Question: (JAVA PROGRAMMING) This assignment does NOT involve a hierarchy of classes. It only involves 1 domain class, 1 driver/tester class, and 2 comparator classes. Interfaces
(JAVA PROGRAMMING)
This assignment does NOT involve a hierarchy of classes.
It only involves 1 domain class, 1 driver/tester class, and 2 comparator classes. Interfaces do NOT need to be created. Only the Comparable and the Comparator interfaces in the Java API are implemented. I provided the 2 given classes(domain and driver with instructions in the comments) and I have to make 2 more comparator classes. The instructions are below also. Please use Scanner Keyboard
INSTRUCTIONS
1.) Create a new class called Course, with attributes such as FIUCourseName, credits, FloridaCourseName, arrayList of preRequisites, and yearLevel.
The Course class must implement the Comparable interface to compare by FIUCourseName. The Course class' toString() method should include printing all the pre-requisites too, which are part of the course object.
You will need comparator objects, to allow the comparison by FloridaCourseName, or by yearLevel.
2.) Create a new driver class whose main method will call at least 2 methods, one to create an arrayList of Course objects, and another to display a menu of options for the user.
The first method called from main will create an arrayList of Course objects by prompting the user to enter the core courses required for the IT major, and asking for all the information required to populate all the attributes of the Course object. Once done, the method will ask the user if he/she wants to enter another course. This will continue until the user replies that he/she is done entering the course information.
The second method called from main will continuously display a menu to the user, to select the order in which to print the Course arrayList : by FIUCourseName (implements Comparable) by FloridaCourseName (use a Comparator object) by yearLevel (use a Comparator object) or exit the menu
Once a menu option is selected, the appropriate Collections.sort method will be called, and the arrayList will be printed in that order: a.) using either the Comparable interface to sort by FIUCourseName Collections.sort(myArrayList); b.) using a Comparator object to sort by yearLevel Collections.sort(myArrayList, new ComparatorByYear); c.) using a Comparator object to sort by FloridaCourseName.*** Collections.sort(myArrayList, new ComparatorByFLACourse);
***Remember: Allow the user to sort in multiple ways without having to re-start the whole program, and re-enter all the data. (Hint: use a ? loop)
Domain Class ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package coursedirectory; import java.util.ArrayList; /** * * @author mtsguest */ public class Course { //what interface should be implemented to compare by FIU Course Name? private String FIUCourseName; private String FLACourseName; private int yearLevel; private int numCredits; private ArrayList
public String getFIUCourseName() { return FIUCourseName; }
public void setFIUCourseName(String FIUCourseName) { this.FIUCourseName = FIUCourseName; }
public String getFLACourseName() { return FLACourseName; }
public void setFLACourseName(String FLACourseName) { this.FLACourseName = FLACourseName; }
public int getYearLevel() { return yearLevel; }
public void setYearLevel(int yearLevel) { this.yearLevel = yearLevel; }
public int getNumCredits() { return numCredits; }
public void setNumCredits(int numCredits) { this.numCredits = numCredits; }
public ArrayList
public void setPrerequisites(ArrayList
@Override public String toString() { return "Course{" + "FIUCourseName=" + FIUCourseName + ", FLACourseName=" + FLACourseName + ", yearLevel=" + yearLevel + ", numCredits=" + numCredits + ", prerequisites=" + prerequisites + '}'; } //What comparison method should be coded, required by the interface, to compare FIU Course Name ?
DRIVER CLASS--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package coursedirectory;
/** * * @author mtsguest */ public class CourseDirectory {
/** * @param args the command line arguments */ public static void main(String[] args) { CourseDirectory myDirectory = new CourseDirectory(); myDirectory.createFIUCourses(); myDirectory.displayMenu(); } public void createFIUCourses() { //Create a loop that will ask user if he/she wants to create another course - do while //Inside loop, ask for all the information for a course //Create another loop inside the outer loop (nested loop) for prerequisites (while) //After the nested loop, create a Course object //Add Course object to arrayList of courses } public void displayMenu() { //Create a loop that displays the menu of options: //1. Sort courses by FIU course name, using main sorting method //2. Sort courses by FLA course name, using alternate sorting method //3. Sort courses by year level, using another alternate sorting method //4. Exit //Keep looping until the user enters option 4 //For each of the options 1- 3, call a specific method } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
