Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The program will keep track of a cost of names and of phone number. The cost of

ID: 3691151 • Letter: T

Question

The program will keep track of a cost of names and of phone number. The cost of names is "Aee". "Betty", cathy", "Dawn", "Eva", and "Francis". The phone numbers in "555-1111", "555-2345"; "555-3333", "555-4000", "555-5432", and 555-6666". The program will ask the user for the name to search form. The program will read name form user. It will search for the name in the of names.If a moter is found, the subscript of the name will be used to corresponding phone number. It name is not found, the message "Not found" will be printed. The program will then ask if there another name. If reply "yes" then program, will loop back to read next name. It reply then program is finished otherwise, the program ask for "Yes or no" and reads reply again.

Explanation / Answer

Please try below code: if any issues please let me know:

import java.util.Hashtable;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Enumeration;

public class HashtableExample {

public static void main(String[] args) throws IOException {

Enumeration names, values;
String key;
int value;
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));


// Creating a Hashtable
Hashtable<String, Integer> hashtable =
new Hashtable<String, Integer>();

// Adding Key and Value pairs to Hashtable
hashtable.put("Name1",444444);
hashtable.put("Name2",421421);
hashtable.put("Name3",456666);
String input="yes";
while(input.equalsIgnoreCase("Yes")){
   System.out.println("Eneter the name");
   String name= br.readLine();
names = hashtable.keys();
values=(Enumeration) hashtable.values();
while(values.hasMoreElements()) {
value = (int) values.nextElement();
key=(String) names.nextElement();
if(hashtable.get(value).equals(name)){
   System.out.println(hashtable.get(key));
}else{
   System.out.println("Number not found");
}
  
}
System.out.println("Do you want one more search");
String search = br.readLine();
if(search.equalsIgnoreCase("No")){
   input="No";
}
}
}
}