1 Create a new class called Course with attributes such as F
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, using the compareTo() method 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 2 more 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 which the order in which to print the Course arrayList :
 by FIUCourseName
 by FloridaCourseName
 by yearLevel
 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
 b.) using a Comparator object to sort by yearLevel
 c.) using a Comparator object to sort by FloridaCourseName.***
***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 while loop)
Solution
import java.util.Comparator;
 import java.util.List;
 public class Course implements Comparable<Course>,Comparator<Course>{
   protected String FIUCourseName;
    protected int credits;
 protected String floridaCourseName;
    protected List<String> prequisites;
    protected int yearlevel;
   
   
   
   
   
    public Course(String fIUCourseName, int credits, String floridaCourseName,
            List<String> prequisites, int yearlevel) {
        FIUCourseName = fIUCourseName;
        this.credits = credits;
        this.floridaCourseName = floridaCourseName;
        this.prequisites = prequisites;
        this.yearlevel = yearlevel;
    }
   public int compareTo(Course course) {
       
       
        return this.FIUCourseName.compareTo(course.FIUCourseName);
    }
   
    public int compare1(Course course,Course next)
    {
        return course.floridaCourseName.compareTo(next.floridaCourseName);
       
    }
   public int compare(Course course, Course next) {
        return Integer.compare(course.yearlevel, course.yearlevel);
    }
   
   @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + ((FIUCourseName == null) ? 0 : FIUCourseName.hashCode());
        result = prime * result + credits;
        result = prime
                * result
                + ((floridaCourseName == null) ? 0 : floridaCourseName
                        .hashCode());
        result = prime * result
                + ((prequisites == null) ? 0 : prequisites.hashCode());
        result = prime * result + yearlevel;
        return result;
    }
   @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Course other = (Course) obj;
        if (FIUCourseName == null) {
            if (other.FIUCourseName != null)
                return false;
        } else if (!FIUCourseName.equals(other.FIUCourseName))
            return false;
        if (credits != other.credits)
            return false;
        if (floridaCourseName == null) {
            if (other.floridaCourseName != null)
                return false;
        } else if (!floridaCourseName.equals(other.floridaCourseName))
            return false;
        if (prequisites == null) {
            if (other.prequisites != null)
                return false;
        } else if (!prequisites.equals(other.prequisites))
            return false;
        if (yearlevel != other.yearlevel)
            return false;
        return true;
    }
   @Override
    public String toString() {
        return \"Course [FIUCourseName=\" + FIUCourseName + \", credits=\"
                + credits + \", floridaCourseName=\" + floridaCourseName
                + \", prequisites=\" + prequisites + \", yearlevel=\" + yearlevel
                + \"]\";
    }
   
   
   
   
   
 }
import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Scanner;
public class mainDemo {
public List<Course> courses = new ArrayList<Course>();
   public static void main(String[] args) {
        mainDemo demo = new mainDemo();
        int no = 0;
        Scanner scanner = new Scanner(System.in);
       int i = 1;
        while (i == 1) {
            System.out.println(\"1.add the courses\");
            System.out.println(\"2.fiucoursename\");
            System.out.println(\"3 florida course name\");
            System.out.println(\"4.year level\");
            System.out.println(\"5 exit\");
           System.out.println(\"enter your choice\");
            int choice = scanner.nextInt();
           switch (choice) {
            case 1:
                System.out.println(\"enter how many courses you want to add\");
                no = scanner.nextInt();
                for (int j = 0; j < no; j++) {
                   System.out.println(\"enter fiucourse name\");
                    String FIUCourseName = scanner.next();
                    System.out.println(\"enter florida course name\");
                    String FloidaCourseName = scanner.next();
                    System.out.println(\"enter the credits\");
                    int credits = scanner.nextInt();
                    System.out.println(\"enter the year level\");
                    int level = scanner.nextInt();
                   System.out.println(\"enter the prequisites\");
                    List<String> prerequisites = new ArrayList<String>();
                    System.out.println(\"enter no of prerequisites \");
                    int num = scanner.nextInt();
                    for (int k = 0; k < num; k++) {
                        System.out.println(\"enter the prerequisite\");
                        String word = scanner.next();
                        prerequisites.add(word);
                    }
                   Course course = new Course(FIUCourseName, credits,
                            FloidaCourseName, prerequisites, level);
demo.courses.add(course);
break;
}// for
           case 2:
                System.out.println(\"the sort for level\");
                Collections.sort(demo.courses);
               for (Course course : demo.courses) {
                    System.out.println(course);
                }
                break;
            case 3:
                System.out.println(\"the sort for course name\");
               for (Course course : demo.courses) {
                    System.out.println(\"course\");
                }
                break;
            case 4:
                System.out.println(\"the sort for florida course name\");
                for (Course course : demo.courses) {
                    System.out.println(\"course\");
                }
                break;
            case 5:
                System.out.println(\" exit\");
                System.exit(0);
               break;
            default:
                System.out.println(\"please choose correct option\");
                break;
            }// switch
        }// while
   }// main
 }// class




