public source;
import java.io.ObjectInput;
public class Question2() {
public Object;
public class student {
private static final String System = null;
private int input;
public void menu() {
//print the menu
System.out.println("1. Create Student file");
System.out.println("2. Add New Student file");
System.out.println("3. Delete Student file");
System.out.println("4. Print Grades");
System.out.println("5. Exit");
//get input
input = keyboard.nextInt();
// process the input and invoke the method required
switch (input) {
case 1: //call the method to create student file
break;
case 2: //call the method to add a new student to file
break;
case 3: // call the method to delete a student from file
break;
case 4: // call the method to print grades
break;
case 5: // call the method to exit
}
}
public void createFile() { //creating the file
String filename;
System.out.println("Enter a filename");
filename = new keyboard.next();
FileoutFile = new File(filename);
FileoutputStream outStream = new FileOutputStream(outFile);
outObjectStream.close();
}
public void addToFile() {
String filename;
System.out.println("Enter a filename");
filename = new keyboard.next();
//ensure that file existed otherwise call method createFile
//get input for student and marks
FileWriter fileWriter = new FileWriter(filename,true); //append to the file, false will replace
BufferedWriter bufferWriter = new BufferedWriter(fileWriter);
bufferWriter.write(student);
bufferWriter.close();
}
public void deleteFile() {
String filename;
System.out.println("Enter a filename");
filename = new keyboard.next();
//method to delete a student
//get the filename in which the student record is going to be deleted from file
//get input which student to delete
//read file and in an array
//loop through the array
//search the student in the array
//if not the student to be deleted, write to file
//method to print grade
//get the filename
// read file and calculate the average mark
//use if statements to figure out the letter grade and print to console
public void
File;outfile = new File(filename);
FileInputStream inStream = new FileInputStram(infile);
FileInputStream outStream = new FileOutputStream(outFile);
ObjectInputStream inObjectStream = new ObjectInputStream;