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

Please write the program in java netbeans This program will keep track of a list

ID: 3691210 • Letter: P

Question

Please write the program in java netbeans

This program will keep track of a list of names and a list of phone numbers. The list of names is “Alice”, “Betty”, “Cathy”, “Dawn”, “Eve”, and “Francis”. The list of phone numbers is “555-1111”, “555-2345”, “555-3333”, “555-4000”, “555-5432”, and “555-6666”. The program will ask the user for the name to search for. The program will read a name from the user. It will search for the name in the list of names. If a match is found, the subscript of that name will be used to print the corresponding phone number. If the name is not found, the message “Not found” will be printed. The program will then ask if there is another name. If the user replies “yes”, then the program will loop back to read the next name. If the user replies “no” then the program is finished. Otherwise, the program asks for “yes or no” and reads the reply again.

Explanation / Answer

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class HelloWorld{
// main function
public static void main(String []args){
// define result
int result;
// call function
result = doSomething();
// check search find and not
if(result == 0){
System.out.println("Not found");
// ask to user want more and not
System.out.println("There is another name :- y/n");
Scanner in = new Scanner(System.in);
String var= in.next();
if(var.equalsIgnoreCase("Y")){// Matches "Y" or "y"
main(null); // if input is Y then call main again.
}else{
System.out.println("Thanks");
}
}
}

public static int doSomething(){
int check = 1;
//define name list
List<String> notSoCoolStringList = new ArrayList<String>();
notSoCoolStringList.add("Alice");
notSoCoolStringList.add("Betty");
notSoCoolStringList.add("Cathy");
notSoCoolStringList.add("Dawn");
notSoCoolStringList.add("Eve");
notSoCoolStringList.add("Francis");
//define number list
List<String> numSoCoolStringList = new ArrayList<String>();
numSoCoolStringList.add("555-1111");
numSoCoolStringList.add("555-2345");
numSoCoolStringList.add("555-3333");
numSoCoolStringList.add("555-4000");
numSoCoolStringList.add("555-5432");
numSoCoolStringList.add("555-6666");
  
  
Scanner in = new Scanner(System.in);
// get user input
System.out.print("Enter your name :- ");
String s = in.nextLine();
//System.out.println("You entered string "+s);
// search in list
int index = notSoCoolStringList.indexOf(s);
if(index == -1){
check = 0;
}else{
// if found then print name and number
System.out.println("Search Name :" + s);
String retval=numSoCoolStringList.get(index);
System.out.println("Phone number = " + retval);
}
//return result
return check;
}
}