Write an application that allows a user to enter the names and phone numbers of
ID: 3667492 • Letter: W
Question
Write an application that allows a user to enter the names and phone numbers of up to 20 friends. Continue to prompt the user for names and phone numbers until the user enters “zzz” or has entered 20 names, whichever comes first. When the user is finished entering names, produce a count of how many names were entered, but make certain not to count the application-ending dummy “zzz” entry. Then display the names. Ask the user to type one of the names and display the corresponding phone number. Save the application as PhoneBook.java.
Explanation / Answer
package movie_Rating;
import java.util.Scanner;
public class Phone_numbers_Dummy {
String names;
int phoneNumer;
public static void main(String[] args) {
String userIp;
int count=0;
Phone_numbers_Dummy [] pnd=new Phone_numbers_Dummy[20];
Scanner sc=new Scanner(System.in);
do
{
pnd[count].names=sc.nextLine();
pnd[count].phoneNumer=sc.nextInt();
count++;
userIp=sc.nextLine();
}while(userIp=="zzz"|count<20);
System.out.println("Total names Entered are "+count);
System.out.println("Enter any of the name");
String nameIp=sc.nextLine();
for (int i = 0; i < pnd.length; i++) {
if(nameIp==pnd[i].names)
{
System.out.println("The corresponding phone number is "+pnd[i].phoneNumer);
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.