hey
i've been creating a hashtable for storing data on student names and exam marks. i'm trying to set up a couple of searches but i'm not sure i'm going along the right lines.
if anyone can give me a heads up on anything i need to change and also a good search technique it would be greatly appreciated.
i know some of the indentation is wrong but i'm more concerned about the understanding.Code:import java.io.*; import java.util.*; class HashTable { private Hashtable record; private BufferedReader input; private String name, mark; public static void main(String[] args)throws IOException { HashTable myHash = new HashTable(); } public HashTable()throws IOException{ input = new BufferedReader( new InputStreamReader(System.in)); record = new Hashtable(); readItems(); displayTable(); } public void readItems() throws IOException{ System.out.println("Enter Student Names and Marks. \n Enter Student Name, to finish type 'end': \n") ; name = input.readLine() ; System.out.println("Enter Student Exam Mark, to finish type 'end': \n") ; mark = input.readLine() ; while ( !name.equals("end")) { record.put(name, name); record.put(name, mark); System.out.println("Enter Student Name, to finish type 'end': \n") ; name = input.readLine() ; System.out.println("Enter Student Exam Mark, to finish type 'end': \n") ; mark = input.readLine() ; } } public void displayTable() throws IOException{ System.out.println("The Names and Marks are : "); Enumeration enumName = record.keys(); Enumeration enumMark = record.elements(); while ( enumName.hasMoreElements() ) System.out.println(enumName.nextElement()+ " " + enumMark.nextElement()); System.out.println(); System.out.println("Enter Student Name to Search for Mark : \n"); name = input.readLine(); System.out.println("The Students Mark is : \n" + record.get(name) + "\n"); } }
thanks in advance.



Reply With Quote
Bookmarks