Question
I need help with this error I'm getting in Line 164 - (case 1) . It's saying no suitable method found for sort(List ) I
I need help with this error I'm getting in Line 164 - (case 1) . It's saying no suitable method found for sort(List
package comparator;
import comparator.Course; import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class CourseDirectory {
/**
* @param args the command line arguments
*/
static List
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
// use scanner keyboard Scanner keyboard = new Scanner(System.in);
do
{ // Use do while loop and ask user for curse name, FLA course, year level, numbers of creds // store into variable
System.out.print("Enter your fiu course name: ");
String FIUCourseName = keyboard.next();
System.out.print("enter FLA course: ");
String FLACourseName = keyboard.next();
System.out.print("enter the year level: ");
int yearLevel = keyboard.nextInt();
System.out.print("enter the number of credits: ");
int numCredits = keyboard.nextInt();
ArrayList
while(true)
{
System.out.print("Enter a pre-requisite for the course!! Press Q to stop !): ");
String preReq = keyboard.next();
if(preReq.equalsIgnoreCase("q")) break;
PreReqs.add(preReq);
}
Course course = new Course(FIUCourseName, FLACourseName, yearLevel, numCredits, PreReqs);
courses.add(course);
System.out.print("Press Q to stop entering courses or any other key to continue entering: ");
String userInput = keyboard.next();
if(userInput.equalsIgnoreCase("q")) break;
}while(true);
}
public void displayMenu()
{
//Create a loop that displays the menu of options:
//1. Sort courses by FIU course name
//2. Sort courses by FLA course name
//3. Sort courses by year level
//4. Exit
//Keep looping until the user enters option 4
//For each of the options 1- 3, call a specific method
Scanner keyboard = new Scanner(System.in);
while(true)
{
System.out.println("1. Sort courses by FIU course name");
System.out.println("2. Sort courses by FLA course name");
System.out.println("3. Sort courses by year level");
System.out.println("4. Exit");
int ForTheUser = keyboard.nextInt();
ComparatorByFLACourse comparatorByFLACourse = new ComparatorByFLACourse();
ComparatorByYearLevel comparatorByYearLevel = new ComparatorByYearLevel();
switch(ForTheUser)
{ case 1: Collections.sort(courses); System.out.println(courses); break ;
case 2: Collections.sort(courses, comparatorByFLACourse); System.out.println(courses); break;
case 3: Collections.sort(courses, comparatorByYearLevel); System.out.println(courses); break;
case 4: return;
}
}
}
X Comparator - NetBeans IDE 8.2 File Edit View Navigate Source Refactor Run Debug Profile Team Tools Window Help 90
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started