You will create a class to keep student’s information: name, student ID, and grade. The program will have the following functionality:
– The record is persistent, that is, the whole registry should be saved on file upon exiting the program, and after any major change.
– The program should provide the option to create a new entry with a student’s name, ID, and grade.
– There should be an option to lookup a student from his student ID (this will be the key in the hash table).
– There should be an option to remove a particular entry by providing the student ID.
– There should be an option to display the whole registry, sorted by student ID.
– Remember that the registry must be persistent, so you will have to save all this information to the file system. You may use any of the versions of hash tables implemented in the previous exercise.
Here is my code for it so far, it might not be correct.
public class Student<String, V> extends HashTable<String, V> {
private V name;
private String id;
private int grade;
public V lookup() {
HashTable<String, V> registry = new HashTable<String, V>();
Scanner input = new Scanner(System.in);
System.out.print(“Please Enter the Student ID: “);
id = (String) input.next();
registry.lookup(id);
java.lang.String out = “The Student’s Name is ” + name;
return (V) out;
}
public V remove() {
HashTable<String, V> registry = new HashTable<String, V>();
Scanner input = new Scanner(System.in);
System.out.print(“Please Enter the Student ID: “);
id = (String) input.next();
super.remove(id);
java.lang.String out = “The Student That Has Been Removed is ” + name;
return (V) out;
}
public java.lang.String display() {
HashTable<String, V> registry = new HashTable<String, V>();
super.getSortedList(null);
System.out.println(something);
}
public static void main(java.lang.String[] args) {
HashTable<String, V> registry = new HashTable<String, V>();
Scanner input = new Scanner(System.in);
java.lang.String choice;
System.out.print(“nWhat Would You Like to Do? Enter a Number:”
+ “n1. Lookup Student by ID”
+ “n2. Remove an entry with Student ID”
+ “n3. Display Registryn”);
switch (choice) {
case “1”:
registry.lookupName();
case “2”:
registry.removeEntry();
case “3”:
registry.display();
}
}
}
The ‘key’ is the student id, and the ‘value’ is to call the object Student to get the name and letter grade.
I don’t understand how to make the registry “persistent’.
Expert Answer
//Student.java import java.util.*; import java.io.*; public class Student { private String name,grade; int id; //constructer public Student(String name,int id,String grade){ public int getId(){ break; for (Integer str : v) { return new Student(name,id,grade); File file = new File(“register.txt”); // creates the file // creates a FileWriter Object // Writes the content to the file |