Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class SchoolCourseManagement { //Keyboard read object private static Scanner sc = new Scanner(System.in); public static void main(String[] args) { //Create a course arraaylist ArrayList

public class SchoolCourseManagement { //Keyboard read object private static Scanner sc = new Scanner(System.in);

public static void main(String[] args) { //Create a course arraaylist ArrayList courses = new ArrayList(); //Call method to get course details from file readCourses(courses); //Get user menu int option = getMenu(); //Execute each options until exit while (option != 6) { if (option == 1) { listCourses(courses); } else if (option == 2) { addCourse(courses); } else if (option == 3) { deleteCourse(courses); } else if (option == 4) { searchCourseByName(courses); } else if (option == 5) { searchCourseByCRN(courses); } option = getMenu(); } writeFile(courses); //Terminate System.out.println(" Thank you for using School application!!!"); }

//Method to read course details from a file to course list public static void readCourses(ArrayList courses) { try { Scanner fileIn = new Scanner(new File("course.txt")); while (fileIn.hasNextLine()) { String[] temp = fileIn.nextLine().split(","); if (temp[2].equalsIgnoreCase("Math")) { if (temp[3].equalsIgnoreCase("STEM")) { courses.add(new Math(temp[0], temp[1], temp[2], true, temp[4])); } else { courses.add(new Math(temp[0], temp[1], temp[2], false, temp[4])); } } else if (temp[2].equalsIgnoreCase("History")) { if (temp[3].equalsIgnoreCase("Eligible")) { courses.add(new History(temp[0], temp[1], temp[2], true, temp[4])); } else { courses.add(new History(temp[0], temp[1], temp[2], false, temp[4])); } } else if (temp[2].equalsIgnoreCase("English")) { courses.add(new English(temp[0], temp[1], temp[2], temp[3], temp[4])); } } fileIn.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }

//Method to display menu public static int getMenu() { System.out.println(" WELCOME TO SCHOOL COURSE DETAILS "); System.out.println( "1. List all available courses 2. Add a new course 3. Delete a course 4. Search a course by course name 5. search a course by CRn 6. Exit"); System.out.print(" Enter your choice:"); int opt = sc.nextInt(); while (opt 6) { System.out.println("Incorrect option!!Try again"); System.out.print(" Enter your choice:"); opt = sc.nextInt(); } sc.nextLine(); System.out.println(); return opt; }

public static void listCourses(ArrayList courses) { System.out.println("CourseName CRN Category"); for (int i = 0; i

//Method to add a course into school list public static void addCourse(ArrayList courses) { System.out.print("Enter course name: "); String courseName = sc.nextLine(); System.out.print("Enter course CRN: "); String crn = sc.nextLine(); System.out.print("Enter category of course(Math/English/History): "); String category = sc.nextLine(); if (category.equalsIgnoreCase("Math")) { System.out.print("Is it Stem or not?(y): "); char ch = sc.nextLine().charAt(0); System.out.print("Enter mode of class room(Online/in-Person/Hybrid): "); String mode = sc.nextLine(); if (ch == 'y') { courses.add(new Math(courseName, crn, category, true, mode)); } else { courses.add(new Math(courseName, crn, category, false, mode)); } } else if (category.equalsIgnoreCase("History")) { System.out.print("Is it Eligible area or not?(y): "); char ch = sc.nextLine().charAt(0); System.out.print("Enter mode of class room(Online/in-Person/Recorded): "); String mode = sc.nextLine(); if (ch == 'y') { courses.add(new Math(courseName, crn, category, true, mode)); } else { courses.add(new Math(courseName, crn, category, false, mode)); } } else if (category.equalsIgnoreCase("English")) { System.out.print("Enter course level(freshman, sophomore, junior, senior): "); String level = sc.nextLine(); System.out.print("Enter type of course(reading/writing/both): "); String type = sc.nextLine(); courses.add(new English(courseName, crn, category, level, type)); } System.out.println(); }

//Method to delete a course from list public static void deleteCourse(ArrayList courses) { System.out.println("Enter CRN of course to delete: "); String crn = sc.nextLine(); for (int i = 0; i

//Method to search a course by name public static void searchCourseByName(ArrayList courses) { System.out.println("Enter course name to search: "); String name = sc.nextLine(); for (int i = 0; i

//Method to search a course by CRN public static void searchCourseByCRN(ArrayList courses) { System.out.println("Enter course CRN to search: "); String crn = sc.nextLine(); for (int i = 0; i

//Write into file public static void writeFile(ArrayList courses) { try { BufferedWriter bw = new BufferedWriter(new FileWriter("course.txt")); for (int i = 0; i

image text in transcribed

Part I: Write a program ConvertTextToBinary.java that reads in your text file from Homework 1. The program will then write the Course objects using ObjectOutputStream (writeObject) to a new binary file. Hint: You can copy your Homework 1 solution. In the main method, delete the while loop for displaying a menu and change it to a for loop to go through the arraylist of courses and write each course to the binary file. Part II: Write the second program ConvertBinaryToText.java that reads the binary file generated by the program you wrote in Part I and convert it to a new text file. Open this new text file and compare it with your original text file for Homework 1. They should be the same. Part I: Write a program ConvertTextToBinary.java that reads in your text file from Homework 1. The program will then write the Course objects using ObjectOutputStream (writeObject) to a new binary file. Hint: You can copy your Homework 1 solution. In the main method, delete the while loop for displaying a menu and change it to a for loop to go through the arraylist of courses and write each course to the binary file. Part II: Write the second program ConvertBinaryToText.java that reads the binary file generated by the program you wrote in Part I and convert it to a new text file. Open this new text file and compare it with your original text file for Homework 1. They should be the same

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

int tab[5]; for(int i = 4;i>=0; i--) tab[i] = 4 - 1; cout

Answered: 1 week ago

Question

1. What might have led to the misinformation?

Answered: 1 week ago

Question

2. How will you handle the situation?

Answered: 1 week ago