import java.util.*; public class PhoneNumbers { public static void main(String[] args) { String names[] = new String[30]; String phones[] = new String[30]; int count; Scanner scanner = new Scanner(System.in); String input; names[0] = "Marceline"; names[1] "Lukas"; names[2] "John"; names[3] = "Joane"; names[4] = "Sylvia"; names[5] = "Murdock" names[6] = "Woodstock" names[7] = "Snoopy"; names[8] names[9] = "Lilith"; = "Rudy"; phones[0] = "(243)-611-2477"; = phones [1] "(555)-321-8536"; phones [2] phones [3] = "(921)-453-9546". "(586)-544-7780" phones [5] phones [6] phones [7] phones [8] = = phones [4] "(456)-444-2222"; = "(222)-486-7532"; "(344)-676-3333" "(333)-211-8764"; "(263)-555-6576"; phones [9] = "(546)-844-1853"; count = 10; input = ""; while (!input.equalsIgnoreCase("quit")) { System.out.print("Enter a name or 'Quit' to end: \n"); input = scanner.nextLine(); if(!input.equalsIgnoreCase("quit")) { boolean found = false; } boolean found = false; for(int i = 0; i < count; i++) { if (names[i].equalsIgnoreCase(input)) { System.out.println("Found!\n"); System.out.println(input + "'s phone number is: " + phones[i]); found = true; break; } } if(!found) { System.out.println(input + is not in the system. \n"); if(count < 30) { names[count] = input; System.out.print("Enter input = scanner.nextLine(); phones[count] = input; count++; + input + "'s phone number: \n"); System.out.println("Added!"); } else { System.out.println("System is full! Sorry!"); } } } } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Hi! I am having trouble with this problem: A personal phone directory contains room for first names and phone numbers for 30 people. Assign names and phone numbers for the first 10 people. Prompt the user for a name, and if the name is found in the list, display the corresponding phone number. If the name is not found in the list, prompt the user for a phone number, and add the new name and phone number to the list. Continue to prompt the user for names until the user enters quit. After the arrays are full (containing 30 names), do not allow the user to add new entries. Save the file as PhoneNumbers.java. Note: Use parallel String arrays to store the names and numbers.)

My code is on the photos.

I need help converting my strings into parallel arrays, as I overlooked that detail when originally doing this. My previous attempts have not worked. Any help would be greatly appreciated!

import java.util.*;
public class PhoneNumbers {
public static void main(String[] args) {
String names[] = new String[30];
String phones[] = new String[30];
int count;
Scanner scanner = new Scanner(System.in);
String input;
names[0]
=
"Marceline";
names[1] "Lukas";
names[2] "John";
names[3] = "Joane";
names[4]
=
"Sylvia";
names[5]
=
"Murdock"
names[6] = "Woodstock"
names[7]
=
"Snoopy";
names[8]
names[9]
= "Lilith";
=
"Rudy";
phones[0] = "(243)-611-2477";
=
phones [1] "(555)-321-8536";
phones [2]
phones [3]
=
"(921)-453-9546".
"(586)-544-7780"
phones [5]
phones [6]
phones [7]
phones [8]
=
=
phones [4] "(456)-444-2222";
= "(222)-486-7532";
"(344)-676-3333"
"(333)-211-8764";
"(263)-555-6576";
phones [9]
=
"(546)-844-1853";
count = 10;
input = "";
while (!input.equalsIgnoreCase("quit")) {
System.out.print("Enter a name or 'Quit' to end: \n");
input = scanner.nextLine();
if(!input.equalsIgnoreCase("quit")) {
boolean found = false;
Transcribed Image Text:import java.util.*; public class PhoneNumbers { public static void main(String[] args) { String names[] = new String[30]; String phones[] = new String[30]; int count; Scanner scanner = new Scanner(System.in); String input; names[0] = "Marceline"; names[1] "Lukas"; names[2] "John"; names[3] = "Joane"; names[4] = "Sylvia"; names[5] = "Murdock" names[6] = "Woodstock" names[7] = "Snoopy"; names[8] names[9] = "Lilith"; = "Rudy"; phones[0] = "(243)-611-2477"; = phones [1] "(555)-321-8536"; phones [2] phones [3] = "(921)-453-9546". "(586)-544-7780" phones [5] phones [6] phones [7] phones [8] = = phones [4] "(456)-444-2222"; = "(222)-486-7532"; "(344)-676-3333" "(333)-211-8764"; "(263)-555-6576"; phones [9] = "(546)-844-1853"; count = 10; input = ""; while (!input.equalsIgnoreCase("quit")) { System.out.print("Enter a name or 'Quit' to end: \n"); input = scanner.nextLine(); if(!input.equalsIgnoreCase("quit")) { boolean found = false;
}
boolean found = false;
for(int i = 0; i < count; i++) {
if (names[i].equalsIgnoreCase(input)) {
System.out.println("Found!\n");
System.out.println(input + "'s phone number is: " + phones[i]);
found = true;
break;
}
}
if(!found) {
System.out.println(input + is not in the system. \n");
if(count < 30) {
names[count] = input;
System.out.print("Enter
input = scanner.nextLine();
phones[count] = input;
count++;
+ input + "'s phone number: \n");
System.out.println("Added!");
}
else {
System.out.println("System is full! Sorry!");
}
}
}
}
}
Transcribed Image Text:} boolean found = false; for(int i = 0; i < count; i++) { if (names[i].equalsIgnoreCase(input)) { System.out.println("Found!\n"); System.out.println(input + "'s phone number is: " + phones[i]); found = true; break; } } if(!found) { System.out.println(input + is not in the system. \n"); if(count < 30) { names[count] = input; System.out.print("Enter input = scanner.nextLine(); phones[count] = input; count++; + input + "'s phone number: \n"); System.out.println("Added!"); } else { System.out.println("System is full! Sorry!"); } } } } }
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education