Write a Java application that allows a user to enter the names and phone numbers
ID: 3761516 • Letter: W
Question
Write a Java application that allows a user to enter the names and phone numbers of up to 10 friends. Use two arrays - one for the names and another for the phone numbers. Recall this is known as a "parallel array". Continue to prompt the user for names and phone numbers until the user enters "zzz" or has entered 10 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 and phone numbers. Ask the user to enter one of the names in their "phone book" and display the corresponding phone number. FIRST, write the pseudocode for your application. Write down step by step what your program should do. You may use either flow charting or pseudocode.
Explanation / Answer
import java.util.*;
class phonebook1
{
public static void main(String args[])
{
int p[]=new int[10];
String n[]=new String[10];
int i;
Scanner o=new Scanner(System.in);
for(i=0;i<10;i++)
{
System.out.println("Enter
name");
n[i]=o.nextLine();
if(n[i].equals("zzz"))
break;
System.out.println("Enter
Phone Number");
p[i]=o.nextInt();
}
System.out.println("Enter name to
search");
String s=o.nextLine();
for(i=0;i<10;i++)
{
if(s.equals(n[i]))
System.out.println(n[i]+"'s Phone Number is ="+p[i]);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.