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!"); } } } } }
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!
Step by step
Solved in 2 steps