Question: Need Help with Files lab, here doc file first. File I/O (Input/Output) Lab Given a file of student records that initially looks like this (supplied

Need Help with Files lab, here doc file first.

File I/O (Input/Output) Lab

Given a file of student records that initially looks like this (supplied in the zip):

Students.txt

F James Wilson

s Nathan Irwin

J Sebastian Rodriguez

S Tom Jordan

*F means freshman, s means sophomore, J means junior, and S means senior.

Implement the methods to append to that file, delete all records of the file, and print out how many seniors, juniors, sophomores, and freshman there are.

In the main method, you will find a loop that prompts the user with 4 choices:

Please enter a choice

Add a student to the file.

Delete the contents of the file.

Print out how many seniors, juniors, sophomores, and freshman there are.

Exit.

Remember that to append to a file, you cannot just use the PrintWriter constructor that accepts a file name. Instead, you have to use a FileWriter as the argument to the PrintWriter constructor.

Appending to a file example:

FileWriter fw = new FileWriter("names.txt", true);

PrintWriter pw = new PrintWriter(fw);

pw.print(collegeLevel); pw.print(firstName);

pw.println(lastName);

pw.close();

package student.records.lab;

import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner;

public class Driver {

public static void main(String[] args) throws IOException { // Keep asking the user what they want to do here until they chose // the option to stop. Scanner keyboard = new Scanner(System.in); int menuOption = 0; do { displayMenu(); System.out.println("What menu option would you like?"); menuOption = keyboard.nextInt(); switch (menuOption) { case 1: //call appropriate method break; case 2: //call appropriate method break; case 3: //call appropriate method break; case 4: //sout a message that says "bye" and "thanks" break; default: //sout a message that says "invalid menu option. try again." }

} while (menuOption != 4); }

public static void appendToFile(String studentName, String yearLevel) throws IOException { // Add a the data for a new student to the file.

}

public static void deleteAllRecords() throws IOException { // Remember that using the PrintWriter with the file name as the paramater // will overwrite the contents of the file.

}

public static void countStudents() throws FileNotFoundException { // Print out how many seniors, juniors, sophomores, and freshman there are. // Example: 1 Freshman, 2 Sophmore, 1 Junior, and 1 Senior students.

} public static void displayMenu() { System.out.println("Enter a menu choice:" ); System.out.println(" 1. Add a student to the file. "); System.out.println("2. Delete the contents of the file."); System.out.println("3. Print out how many seniors, juniors, sophomores, and freshman there are."); System.out.println("4. Exit."); }

}

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 Databases Questions!