The following classes are to complete the 'TODO' to fit the task, output and the overview
package lesson;
import java.util.Collection;
import java.util.Deque;
import java.util.Queue;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
/**
* Allows user to enter filename containing courses to display courses
* in a particular order
*
* @author krodgers
* @author TODO
*/
public class App {
public static void main(String[] args) {
Scanner userScan = new Scanner(System.in);
int userInput = 0;
boolean done = false;
while(!done){
switch(userInput){
case 0:
// Print menu - Get prereqs, list courses, quit
System.out.println("Your choices:");
System.out.println("0. Print Menu");
System.out.println("1. Get prereqs");
System.out.println("2. List courses");
System.out.println("3. Quit");
break;
case 1:
try{
// Get Prerequisite classes
System.out.println("Listing the prerequisites");
System.out.println("Enter the course for which to get prereqs (dept courseNo credits): " );
Scanner lineScan = new Scanner(userScan.nextLine());
CreditCourse target = new CreditCourse(lineScan.next(),
lineScan.nextInt(), lineScan.nextInt());
lineScan.close();
System.out.println("Enter filename (x.txt): ");
String filename = userScan.nextLine();
Scanner fileScan = new Scanner(new File(filename));
Deque<CreditCourse> prereqs = CoursePlanner.organizePrereqs(target, fileScan);
System.out.println("To take " + target + ", you must take the following classes: " );
printStructure(prereqs);
fileScan.close();
} catch(FileNotFoundException e){
System.out.println("Tried to open file, but couldn't find it");
}
break;
case 2:
// TODO
// Ask for the order in which courses should be printed
// Ask for the order in which courses are listed in the file
// Ask for filename
// Print courses by using either chronologicalOrder or
// revChronologicalOrder and printStructure
break;
case 3:
done = true;
break;
default:
System.out.println("Invalid menu option - enter 1, 2, or 3");
}
System.out.print("Enter Option: ");
userInput = Integer.parseInt(userScan.nextLine());
}
}
/**
* Prints the contents of a Queue or Deque by popping items. This
* method will modify the data structure - courses will be empty
* when this method returns
* DO NOT MODIFY THIS METHOD
* @param courses - the data structure to print
*/
public static void printStructure(Queue<CreditCourse> courses){
while(courses.size() > 0){
System.out.println(courses.remove());
}
}
}
package lesson;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Deque;
import java.util.Scanner;
import java.io.File;
/**
* Contains methods to organize courses.
*
* All methods take course information input in the form
* <pre>
* <dept> <courseNo> <credits>
* <dept> <courseNo> <credits>
* ...
* </pre>
*
* @author
*/
public class CoursePlanner{
/**
Returns data structure that will list courses in the order they
must be taken in order to take target course
Classes with the same last digit are in a series and must be.
The following classes are to complete the 'TODO' to fit the task- outp.pdf
1. The following classes are to complete the 'TODO' to fit the task, output and the overview
package lesson;
import java.util.Collection;
import java.util.Deque;
import java.util.Queue;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
/**
* Allows user to enter filename containing courses to display courses
* in a particular order
*
* @author krodgers
* @author TODO
*/
public class App {
public static void main(String[] args) {
Scanner userScan = new Scanner(System.in);
int userInput = 0;
boolean done = false;
2. while(!done){
switch(userInput){
case 0:
// Print menu - Get prereqs, list courses, quit
System.out.println("Your choices:");
System.out.println("0. Print Menu");
System.out.println("1. Get prereqs");
System.out.println("2. List courses");
System.out.println("3. Quit");
break;
case 1:
try{
// Get Prerequisite classes
System.out.println("Listing the prerequisites");
System.out.println("Enter the course for which to get prereqs (dept courseNo credits): " );
Scanner lineScan = new Scanner(userScan.nextLine());
CreditCourse target = new CreditCourse(lineScan.next(),
lineScan.nextInt(), lineScan.nextInt());
lineScan.close();
System.out.println("Enter filename (x.txt): ");
String filename = userScan.nextLine();
Scanner fileScan = new Scanner(new File(filename));
Deque<CreditCourse> prereqs = CoursePlanner.organizePrereqs(target, fileScan);
3. System.out.println("To take " + target + ", you must take the following classes: " );
printStructure(prereqs);
fileScan.close();
} catch(FileNotFoundException e){
System.out.println("Tried to open file, but couldn't find it");
}
break;
case 2:
// TODO
// Ask for the order in which courses should be printed
// Ask for the order in which courses are listed in the file
// Ask for filename
// Print courses by using either chronologicalOrder or
// revChronologicalOrder and printStructure
break;
case 3:
done = true;
break;
default:
System.out.println("Invalid menu option - enter 1, 2, or 3");
}
System.out.print("Enter Option: ");
userInput = Integer.parseInt(userScan.nextLine());
4. }
}
/**
* Prints the contents of a Queue or Deque by popping items. This
* method will modify the data structure - courses will be empty
* when this method returns
* DO NOT MODIFY THIS METHOD
* @param courses - the data structure to print
*/
public static void printStructure(Queue<CreditCourse> courses){
while(courses.size() > 0){
System.out.println(courses.remove());
}
}
}
package lesson;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Deque;
import java.util.Scanner;
import java.io.File;
/**
5. * Contains methods to organize courses.
*
* All methods take course information input in the form
* <pre>
* <dept> <courseNo> <credits>
* <dept> <courseNo> <credits>
* ...
* </pre>
*
* @author
*/
public class CoursePlanner{
/**
Returns data structure that will list courses in the order they
must be taken in order to take target course
Classes with the same last digit are in a series and must be
taken in series order. For example, EDU 101, EDU 221, EDU 251,
EDU 321, EDU 451 form a series.
Hint: Use modulus division to extract the last digit from the course number
@param prereqs - file containing courses from 500 level to 100 level
@param courses - a Scanner object already opened to input containing classes in numerical order
*/
public static Deque<CreditCourse> organizePrereqs(CreditCourse target, Scanner courses){
6. return null;
}
/**
* Returns a Deque that will list courses from earliest taken
* taken to most recently taken
*
* @param transcript - Scanner open to input containing courses ordered
* most recently taken to earliest taken
*/
public static Deque<CreditCourse> chronologicalOrder(Scanner transcript){
return null;
}
/**
* Returns a Queue that will list courses from most
* recently taken to earliest taken
*
* @param transcript - Scanner open to input containing courses ordered
* most recently taken to earliest taken
*/
public static Queue<CreditCourse> revChronologicalOrder(Scanner transcript){
return null;
}
}
7. Second test files
Here is an overview of the total task to do
Task 1 - Read all provided code Read through README.md and all provided source and test
files. Pay particular attention to the datafiles and the description of the datafiles in
README.md. Read the javadoc comments! For this lab, the tests have been provided for you.
Task 2 - Update CreditCourse Copy Creditcourse. j ava from your last lab into app / src / main /
java / lesson with the rest of the source files. Run Creditcoursetest.java and fix any tests that fail.
Take a look through the test file and note the test cases; in general, you want to test for valid
cases, invalid cases, and boundary cases. Task 2 - Implement CoursePlanner Class Use the
javadocs in courseplanner. java to implement the methods. Note all methods are static methods -
you don't have to create an object to call the methods (like the Math class). Each method will
return either a Deque or a queue. Do not create, open, or close any Scanners in this class. Do not
open any files in this class. Just use the Scanner parameter - it should be an initialized Scanner
object. You can use it in the exact same way as any Scanner you created yourself. Refer to Code
Examples for Using Scanners Task 3 - Implement App.java The file App.java contains
comments that outline an algorithm (something you should do when you write your own
algorithms). Complete the TODOs. Example Output User input is in green text Your choices: 0.
Print Menu 1. Get prereqs 2. Iist courses 3. Quit Enter Option: 2 M - most recent to least recent L
- least recent to most recent In what order should courses be displayed? M/L L In what order are
courses listed in the file? M/L M Enter filename (x.txt): yearCourses.txt (1) CS HU 310 (1) CS
HU 271 (1) CS HU 250 (4) ECE 230 (3) CS 253 (3) CS 321 (1) CS HU 153 (3) UF 200 (3)
ENGL 212 (3) CS 221 (4) MATH 189 Enter Option: 2 M - most recent to least recent I - least
recent to most recent In what order should courses be displayed? M/I M In what order are
courses listed in the file? M/L M Enter filename (x.txt) : yearCourses.txt (4) MATH 189 (3) CS
221 (3) ENGL 212 (3) UF 200 (1) CS HU 153 (3) CS 321 (3) CS 253 (4) ECE 230 (1) CS-HU
250 (1) CS-HU 271 (1) CS-HU 310 Enter Option: 1 Listing the prerequisites Enter the course for
which to get prereqs (dept courseno credits): EDU 4943 Enter filename (x.txt): courses.txt To
take (3) EDU 494, you must take the following classes: (6) EDU 184 (4) EDU 194 (4) EDU 364
(5) EDU 384 (6) EDU 464 (1) EDU 484 (3) EDU 494 Enter Option: 3 purseTest.java 9 + X ##
Learning objectives - Use generic methods and classes - Understand generic classes - Understand
how to choose the appropriate linear data structure for a particular application - Use a Stack
(Deque) and Queue ## Overview This project contains the following source files: - App.java -
Driver class; Allows the user to choose options from a menu to search and display courses;
partially implemented, you need to finish the rest. - CoursePlanner.java - Contains methods you
need to implement. The methods process input and returns a data structure of courses in the
correct order. You should not be opening files or creating Scanners in this file - use the
parameter objects to process the input. You may assume the data in the input is in the correct
format. This is a bad assumption, but adequate for the purposes of this lab. the following test
files: - CreditcourseTest.java - contains complete tests for CreditCourse.java; do not modify. Do
look through the tests to see what is being tested, how the tests are structured, etc. -
CoursePlannerTest.java - contains complete tests for CoursePlanner. Do not modify.