I have already made the hashtable class and name class. Write a Java program to
ID: 3775659 • Letter: I
Question
I have already made the hashtable class and name class.
Write a Java program to read in the information in the file, create instances of the class from part 2, and store them in your NewHashTable using the name as the key and the class from part 2 as the value. After reading and storing the first 10 names in the file, display the NewHashTable using the toString method, continue to read in the rest of the data. Also, make sure the rehash method is called at least once.
The program then get names from a user and if a name is found in the NewHashTable, displays the information about that name and removes the key and value from the table (This is just to see if your remove method works). Use both the containsKey and get methods when doing the searching (redundant, but good for testing). Include found names, names not found, and names previously found but now removed in the test cases.
import java io. File import java io. IOException; import java util. Scanner import java util. StringTokenizer public class Main @param args ("resource" @Suppress Warnings public static void main String DJ args) throws IOException String searchName String data @SuppressWarnings ("unused") String input int count @SuppressWarnings ("unused") Scanner kb new Scanner System in NewHashTable Name, String> ht new NewHashTable Name, String> C); Name last Names-new Name [151671 Scanner list new Scanner new File("Macintosh HD/Users/moscj/Documents/list.txt")); while Clist hasNext data list next Line(); StringTokenizer tokens new StringTokenizer(data, String lastName tokens .nextTokenO.trimC); int rank Integer. parselnt tokens next TokenO.trimO); int proportion Integer. parselnt tokens next TokenO.trimO); int cum Proportion Integer parselntCtokens next trimO); lastNames [count] new NameClastName, rank, proportion, cumProportion ht put last Names 10] args [1]); System. out.printlnCht); CountExplanation / Answer
import java.io.File;
import java.io.IOExceptio;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main {
/**
* @param args
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String data;
String input;
int count=0;
Scanner kb=new Scanner(System.in);
NewHashTable<Name,String> ht = new NewHashTable<Name, String>();
Name[] lastNames=new Name[151671];
Scanner list = new Scanner(new File("Macintosh HD/Users/moscj/Documents/list.txt"));
while(list.hasNext()) {
data=list.nextLine();
StringTokenizer tokens=new StringTokenizer(data,",");
String lastName=tokens.nextToken().trim();
int rank=Integer.parseInt(tokens.nextToken().trim());
int proportion=Integer.parseInt(tokens.nextToken().trim());
int cumProportion=Integer.parseInt(tokens.nextToken().trim());
lastNames[count]=new Name(lastName, rank, proportion, cumProportion);
ht.put(lastNames[0], lastName);
count++;
if(count==9) /* Prints the first 10 names after reading and storing them in the NewHashTable */
System.out.println("String form of hash table is: "+ht.toString());
}
for (int i = 0; i < args.length; i++) {
if(ht.containsKey(args[i])) {
System.out.println("/t" ht.get(args[i]));
ht.remove(args[i]);
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.