Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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."); }

}

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();

Need help completing this on Netbeans and only use the class that it already has. can not use array. only use these:

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

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

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

Students also viewed these Databases questions