Question: how can I finish this code ? public class CreateCourses { public static void main ( String [ ] args ) { Scanner keyboard =

how can I finish this code ? public class CreateCourses {
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
ArrayList courses = new ArrayList<>();
/*
TODO 1: write a while loop that iterates until user enters "N" when asked whether they have a course to enter.
Within the loop, call the method getACourse, and add the course to the arraylist courses.
*/
System.out.println("Do you have a course to enter (Y,N)?");
String answer = keyboard.nextLine();
while (answer.equals("Y")){
// need to call the getACourse method
// add the returned course to the array list course
System.out.println("Do you have a course to enter (Y,N)?");
answer = keyboard.nextLine();
}
if (courses.size()==0){
System.out.println("No courses entered.");
return;
}
printCourses(courses);
System.out.println("Enter a course name to search:");
String name = keyboard.nextLine();
Course c = searchCourse(courses, name);
if (c!= null){
System.out.println("Course found.");
System.out.println(c);
} else {
System.out.println("Course not found.");
}
}
/*
* getACourse method will prompt user to enter the information of a course,
* create the course, and return the course. If the user-entered category is
* incorrect, the method should return null.
*
* @param keyboard the scanner that will be used to extract user inputs
* @return the course created or null if the course category user enters is incorrect.
*/
public static Course getACourse(Scanner keyboard){
//TODO 2: complete the method definition
System.out.println("Enter CRN number:");
System.out.println("Enter course category:");
System.out.println("Enter course name:");
return null;
}
/*
* printCourses will print the courses stored in an array list.
*
* @param list the array list that contains the courses
*/
public static void printCourses(ArrayList list){
//TODO 3: define the method
// need loop
}
/*
* searchCourse will search the array list for a course of a given name
*
* @param list the array list that contains the courses
* @param name a course name
* @return the course with the name. If not found, return null.
*/
public static Course searchCourse(ArrayList list, String name){
//TODO 4: define the method
// need loop
return null;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!