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

This program will keep track of a list of names and a list of phone numbers. The

ID: 3691275 • Letter: T

Question

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-1 111", "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 prmt 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

// create a file name Menu.java then copy this code and execute in your net beans

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package menu; // package creation
import java.util.Scanner; // importing scanner class for reading input from user
/**
*
* @author Shivakumar
*/
public class Menu { // class declaration
static String[] names={"Alice","Betty","Cathy","Dawn","Eve","Francis"}; // String array to store names
static String[] phone={"555-1111","555-2345","555-3333","555-4000","555-5432","555-6666"}; // string array to //store phone numbers

/**
* @param args the command line arguments
*/
public static void main(String[] args) { // main method starts here
String s; // string to read user name
String c=null; // String object to read yes or no from user
Scanner sc=new Scanner(System.in); // scanner object creation
// TODO code application logic here
  
while(!"no".equals(c)) // loop continues until user enters no
{
System.out.println("Enter user name:"); // prompting user to enter user name
s=sc.next(); // reading from user input next() method in string reads string
for(int i=0;i<names.length;i++) // for loop to search name
{
if(s.equals(names[i])) // checking the existance of name
{
System.out.println("The corresponding phone number of "+s+" is "+phone[i]); // printing the //corresponding phone number
}
else if(i==6)
System.out.println("Not Found"); // printing if name is not found
}
System.out.println("Do you want to enter another name:yes/no"); // asking user for continuation
c=sc.next(); // reading to c object
}
  
  
}
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote