Question
I have this code so far but i cant figure out how to do the last methods. The FInished version must look lik e the
I have this code so far but i cant figure out how to do the last methods.
The FInished version must look lik
e the attached pictures.
Here are the methods I need:
public static void searchStudentsByID (parameters here)Inside this method, you must:
1. Scan from file the ID of the student to search for. 2. Search for this student ID using a binary search. 3. If the student ID is not found, an error message should print (see output) 4. If the student ID is found, the students record should print (see output)
public static void searchStudentsByName(parameters here)Inside this method, you must:
1. Scan from file the first and last name of the student to search for. 2. Search for this student using first and last name (linear search) 3. If the student is not found, an error message should print (see output) 4. If the student is found, the students record should print (see output)
public static void displayClassStatistics(parameters here)Inside this method, you must:
1. Display the statistical results for the class (see output)
public static void displayAllStudents (parameters here)Inside this method, you must:
Display the record of all students, along with their grades.
If there is no student, an error message should print (see output)
Else, all students should be printed.
public static char getLetterGrade(parameters here)Inside this method, you must:
Determine the letter grade of the student from their final, numerical grade. *You will use the standard scale: 90 or greater is an A, 80 or greater is a B, 70 or greater is a C, 60 or greater is a D, and under 60 is an F.
Return the letter grade.
Here is the code I have:
Main code:
package fscgradebook;
import java.io.File; import java.io.PrintWriter; import java.util.Scanner;
/** * * @author john */ public class FSCgradebook {
// // METHODS USED TO PROCESS THE COMMANDS IN THE INPUT FILE. // - All we really do is print a small message for each command // // Method to Proccess ADDRECORD public static int addRecord(Scanner input, PrintWriter output, Student[] students) {
int id = input.nextInt();
String fname = input.next();
String lname = input.next();
int g1 = input.nextInt();
int g2 = input.nextInt();
int g3 = input.nextInt();
int index = -1;
Student s = new Student(fname, lname, id, g1, g2, g3,(((g2 * (0.3)) + (g3 * (0.4)) + (g1 * (0.3)))));
// save new student into array students[0] = s;
output.println("Command: ADDRECORD");
output.println(fname + " " + lname + " (ID# " + id + ")"+ " has been added to the FSC Grade Book");
output.println(" His final grade is " + (((g2 * (0.3)) + (g3 * (0.4)) + (g1 * (0.3)))) + "("+ ")");
for (int i = 0; i
if (Student.getNumStudents() == 0) {
students[0] = s;
Student.increaseStudents();
return 0; // once we insert a, stop looping
}
for (int y = 0; y
index = y;
} }
}
if (index != -1) {
for (int i = Student.getNumStudents() - 1; i > index; i--) {
students[i + 1] = students[i];
}
students[index] = s;
} else {
index = Student.getNumStudents();
if (index
students[index] = s;
Student.increaseStudents();
} else {
System.out.println("Adding student not possible, it reached to max size");
return -1;
}
}
return index;
}
// Method to Proccess SEARCHBYID public static void searchbyID(PrintWriter output) { output.println("Command SEARCHBYID"); //if (Student.ID) == ) {
}
// Method to Proccess SEARCHBYNAME public static void searchbyNAME(PrintWriter output) { output.println("Command: SEARCHBYNAME"); }
// Method to Proccess DISPLAYSTATS public static void displaySTATS(PrintWriter output) { output.println("Command: DISPLAYSTATS"); //output.println("Statistical Results of"+course+"(Instructor: Dr "+instructor_fName+" "+instructor_lName+"):"); output.println(" Total number of student records: "); output.println(" Average Score: "); output.println(" Highest Score: "); output.println(" Lowest Score: "); output.println(" Total 'A' Grades: " + "(" + "% of class)"); output.println(" Total 'B' Grades: " + "(" + "% of class)"); output.println(" Total 'C' Grades: " + "(" + "% of class)"); output.println(" Total 'D' Grades: " + "(" + "% of class)"); output.println(" Total 'F' Grades: " + "(" + "% of class)"); }
// Method to Proccess DISPLAYSTUDENTS public static void displaySTUDENTS(PrintWriter output) { output.println("Command: DISPLAYSTUDENTS"); }
// Method to Proccess quit public static void QUIT(PrintWriter output) { output.println("Thank you for using the FSC Grade Book."); output.println("Goodbye."); }
//*************// // MAIN METHOD // //*************// public static void main(String[] args) throws Exception { // Variables needed for program String command; // used to save the command read from input file
//Student x = new Student(); //x.setFname("yh7yh6t"); //System.out.println(x.getFname()); // OPEN FILES // Input File: File inputFile = new File("FSCgradebook.in"); if (!inputFile.exists()) { System.out.println("Input file, " + inputFile + ", does not exist."); System.exit(0); } // Output File: File outputFile = new File("FSCgradebook.out");
// Make Scanner variable to read from input file, and // make Printwriter variable to print to output Scanner input = new Scanner(inputFile); PrintWriter output = new PrintWriter(outputFile);
String course = input.nextLine(); String instructor_fName = input.next(); String instructor_lName = input.next(); int maxNumberStudents = input.nextInt();
Student[] students = new Student[maxNumberStudents];
output.println("Welcome to the FSC Grade Book."); do { command = input.next();
// ADDRECORD if (command.equals("ADDRECORD") == true) { addRecord(input, output, students); } // *NOTE: // Notice, that we send the "output" variable (the PrintWriter variable) to the // method. This allows us to print to the file from inside the method. // You can also send the "input" variable to the method, which would allow you to // read from the file from inside the method also. // COMMAND2 else if (command.equals("SEARCHBYID") == true) { searchbyID(output); } // COMMAND3 else if (command.equals("SEARCHBYNAME") == true) { searchbyNAME(output); } else if (command.equals("DISPLAYSTATS") == true) { displaySTATS(output); } else if (command.equals("DISPLAYSTUDENTS") == true) { displaySTUDENTS(output); } // Command QUIT: Quit the Program else if (command.equals("QUIT") == true) { output.println("Thank you for using the FSC Grade Book."); output.println("Goodbye."); } // Invalid Command else { System.out.println("Invalid Command: input invalid."); }
} while (command.equals("QUIT") != true);
// Close input and output input.close(); output.close(); } }
Student Class:
package fscgradebook;
/** * * @author john */ public class Student {
private String fname; private String lname; int ID; private int[] examGrades; private double finalGrade; private char letterGrade; private static int numStudents = 0; private int maxNumStudents;
public Student() { } Student[] students = new Student[maxNumStudents];
public Student(String fname, String lname, int ID, int g1, int g2, int g3, double finalGrade) { this.fname = fname; this.lname = lname; this.ID = ID; this.finalGrade = finalGrade; examGrades = new int[3]; examGrades[0] = g1; examGrades[1] = g2; examGrades[2] = g3; }
public String getFname() { return fname; }
public void setFname(String fname) { this.fname = fname; }
public String getLname() { return lname; }
public void setLname(String lname) { this.lname = lname; }
public int getID() { return ID; }
public void setID(int ID) { this.ID = ID; }
public double getFinalGrade() { return finalGrade; }
public void setFinalGrade(double finalGrade) { this.finalGrade = finalGrade; }
public char getLetterGrade() { return letterGrade; }
public void setLetterGrade(char letterGrade) { this.letterGrade = letterGrade; }
public static int getNumStudents() { return numStudents; }
public static void setNumStudents(int numStudents) { Student.numStudents = numStudents; }
public static void increaseStudents(){ numStudents++; } }
Welcome to the FSC Grade Book. Command: DISPLAYSTUDENTS ERROR: there are no students currently in the system. Command DISPLAYSTATS Statistical Results of CSC-3380 Instructor: Dr Jonathan Cazalas): Total number of student records 0 Average Score: 0.00 Highest Score: 0.00 Lowest Score: 0.00 Total 'A' Grades: 0 (0% of class) Total 'B' Grades: 0 (0% of class) Total 'C' Grades: 0 (0% of class) Total 'D' Grades: 0 (0% of class) Total 'F' Grades: 0 (0% of class) Command: SEARCHBYID (no students added yet) Command: SEARCHBYNAME (no students added yet) Command ADDRECORD ERROR: cannot perform search. The gradebook is empty ERROR: cannot perform search. The gradebook is empty Joe Smith (ID# 111) has been added to the FSC Grade Book. His final grade is 90.10 (A). Command: SEARCHBYNAME Student Record for Joe Smith (ID # 111): 90 85 Exam 1: Exam 2: Final Exam: 94 Final Grade: 90.10 Letter Grade: A Command: SEARCHBYID Indices searched: 0, Student Record for Joe Smith (ID # 111): Exam 1: am or 90 Exam 2: Final Exam: 94 Final Grade: 90.1e Letter Grade: A 85 Command: DISPLAYSTATS Statistical Results of CSC-3380 (Instructor: Dr Jonathan Cazalas): Total number of student records 1 Average Score: 90.10 Highest Score: 90.10 Lowest Score: 90.10 Total 'A' Grades: 1 (100.00% of class) Total 'B' Grades: 0 (0.00% of class) Total 'C' Grades: 0 (0.00% of class) Total 'D' Grades: 0 (0.00% of class) Total Grades: 0 (0.00% of class) Command: DISPLAYSTUDENTS *Class Roster and Grade Sheet -Student Record for Joe Smith (ID # 111): 90 85 Exam 1: Exam 2: Final Exam: 94 Final Grade: 90.10 Welcome to the FSC Grade Book. Command: DISPLAYSTUDENTS ERROR: there are no students currently in the system. Command DISPLAYSTATS Statistical Results of CSC-3380 Instructor: Dr Jonathan Cazalas): Total number of student records 0 Average Score: 0.00 Highest Score: 0.00 Lowest Score: 0.00 Total 'A' Grades: 0 (0% of class) Total 'B' Grades: 0 (0% of class) Total 'C' Grades: 0 (0% of class) Total 'D' Grades: 0 (0% of class) Total 'F' Grades: 0 (0% of class) Command: SEARCHBYID (no students added yet) Command: SEARCHBYNAME (no students added yet) Command ADDRECORD ERROR: cannot perform search. The gradebook is empty ERROR: cannot perform search. The gradebook is empty Joe Smith (ID# 111) has been added to the FSC Grade Book. His final grade is 90.10 (A). Command: SEARCHBYNAME Student Record for Joe Smith (ID # 111): 90 85 Exam 1: Exam 2: Final Exam: 94 Final Grade: 90.10 Letter Grade: A Command: SEARCHBYID Indices searched: 0, Student Record for Joe Smith (ID # 111): Exam 1: am or 90 Exam 2: Final Exam: 94 Final Grade: 90.1e Letter Grade: A 85 Command: DISPLAYSTATS Statistical Results of CSC-3380 (Instructor: Dr Jonathan Cazalas): Total number of student records 1 Average Score: 90.10 Highest Score: 90.10 Lowest Score: 90.10 Total 'A' Grades: 1 (100.00% of class) Total 'B' Grades: 0 (0.00% of class) Total 'C' Grades: 0 (0.00% of class) Total 'D' Grades: 0 (0.00% of class) Total Grades: 0 (0.00% of class) Command: DISPLAYSTUDENTS *Class Roster and Grade Sheet -Student Record for Joe Smith (ID # 111): 90 85 Exam 1: Exam 2: Final Exam: 94 Final Grade: 90.10Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started