How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask Scott Your Own Question
Scott
Scott, MIT Graduate
Category: Homework
Satisfied Customers: 3040
Experience:  MIT Graduate (Math, Programming, Science, and Music)
3546829
Type Your Homework Question Here...
Scott is online now
A new question is answered every 9 seconds

Create a class that can be used to test data structure -

Customer Question

Create a class that can be used to test data structure - similar to the StudentA.java example foundshown below:StudentA.javaimport java.util.Scanner;import java.util.ArrayList;class StudentA implements Comparable {static java.util.Random rn = new java.util.Random ();static ArrayList firstNames = new ArrayList <>();static ArrayList lastNames = new ArrayList <>();static SORTBY sortBy = SORTBY.LAST;static int nextUID = 1;String first, last;double gpa = 0;int credits = 0;int uid = 0;static {try {java.util.Scanner scFirst = new java.util.Scanner (newjava.io.File("firstNames.txt"));java.util.Scanner scLast = new java.util.Scanner (newjava.io.File("lastNames.txt"));while (scFirst.hasNext()) firstNames.add (scFirst.next());while ( scLast.hasNext()) lastNames.add ( scLast.next());}catch (java.io.FileNotFoundException e) {System.out.println (e);} // end try catch} // end static intializerenum SORTBY {LAST, FIRST, CREDITS, GPA}public StudentA (String st) {this (new Scanner (st)) }public StudentA (Scanner sc) {uid = nextUID++;first = sc.next();last = sc.next();credits = sc.nextInt();gpa = sc.nextDouble();} // end Scanner constructorpublic StudentA () {uid = nextUID++;} // no parameter constructorpublic int compareTo (StudentA x) {switch (sortBy) {case LAST : return last.compareTo (x.last);case FIRST : return first.compareTo (x.first);case CREDITS: return credits - x.credits;case GPA : return (gpa > x.gpa)? 1 : -1;} // end switchreturn 0;} // end compareTo for Comparable interfacepublic String toString () {return String.format ("%5d %15s, %15s: %5d %10.2f", uid, last, first,credits, gpa);} // end method toStringpublic static StudentA [] makeRandom (int m) {StudentA [] sa = new StudentA [m];for (int i = 0; i < sa.length; i++) {sa[i] = new StudentA ();sa[i].first = firstNames.get (rn.nextInt (firstNames.size()));sa[i].last = lastNames.get (rn.nextInt ( lastNames.size()));sa[i].credits = rn.nextInt (120);sa[i].gpa = rn.nextDouble () * 4.0;} // end for each student to instantiatereturn sa;} // end method makeRanompublic static void main (String args []) {System.out.println (new StudentA ("***** ***** 35 3.98"));StudentA [] x = makeRandom (10);for (StudentA m: x)System.out.println (m);java.util.Arrays.sort (x);System.out.println ("---- SORTED Last -----");for (StudentA m: x)System.out.println (m);System.out.println ("---- SORTED First -----");StudentA.sortBy = SORTBY.FIRST;java.util.Arrays.sort (x);for (StudentA m: x)System.out.println (m);System.out.println ("---- SORTED Credits -----");StudentA.sortBy = SORTBY.CREDITS;java.util.Arrays.sort (x);for (StudentA m: x)System.out.println (m);System.out.println ("---- SORTED GPA -----");StudentA.sortBy = SORTBY.GPA;java.util.Arrays.sort (x);for (StudentA m: x)System.out.println (m);} // end main} // end class StudentANote that this class will be used in the projects in the rest of this course to test various datastructures and algorithmsThe following are requirements for this homework: Unique index integer fields Use at least 5 other fields of various, including at least one of each of String, int anddouble types. Write a method that will create an array of N random instances of this class, where N isan integer parameter to this method Provide a toString method that will format an instance of this class nicely Provide appropriate constructors Write methods that will write and read text files of this classo assume that the String's have no spaces within them Provide a good GUI interface to control and test this class, at a minimum:o to make this easy, assume that the first line of the file is the number of elements inthe fileo make the file one line per entryo use spaces as field delimiters in the fileso use the toString method of the class to write to the fileo use buttons to control the functions availableo use JFileChoose for selecting input and output fileso use a JTextArea and JScrollPane to create a scrolling text area for outputo the window should resize nicely - use BorderLayout with the text area in thecenterSubmit your java file(s) along with your test plan and demonstration of successfulcompilation and running for all test cases to the homework 1 submission area.
Submitted: 1 year ago.
Category: Homework
Expert:  ATLProg replied 1 year ago.

Hello by when you need this done

Customer: replied 1 year ago.
Hi, I need this done by midnight tonight.
Expert:  ATLProg replied 1 year ago.

Ok can do it by then

Expert:  ATLProg replied 1 year ago.

sorry but i am out of ideas on this one. i will opt out for others. Best wishes

Customer: replied 1 year ago.
You are JUST NOW figuring that out!!! Are you f**king kidding me????
Expert:  LogicPro replied 1 year ago.

Hi,

Welcome

Hope you are doing well.

You should be using "For LogicPro only" at the start of your questions to ensure question comes to me or I may not be able to help

Do you still need it?

What is the deadline in hours?

Expert:  LogicPro replied 1 year ago.

Seems you did not get my previous reply.

Expert:  LogicPro replied 1 year ago.

Welcome

Hope you are doing well.

You should be using "For LogicPro only" at the start of your questions to ensure question comes to me or I may not be able to help

Do you still need it?

What is the deadline in hours?

Related Homework Questions