Question: JAVA When i input 10 names i receive an error and doesnt output correctly import java.util.*; public class BirthdayReminder { public static void main(String[] args)

JAVA

When i input 10 names i receive an error and doesnt output correctly

import java.util.*; public class BirthdayReminder { public static void main(String[] args) { // Write your code here String sentinal = "ZZZ"; final int size = 10; int count = 0; String name = null; String dateOfBirth = null; String[] names = new String[size]; String[] birthdates = new String[size]; Scanner input = new Scanner(System.in); System.out.println("Enter a name or enter ZZZ to quit: "); name = input.nextLine(); while(!name.equals(sentinal) && count < 10) { System.out.println("Enter birtdate: "); dateOfBirth = input.nextLine(); names[count] = name; birthdates[count] = dateOfBirth; System.out.println("Enter a name or enter ZZZ to quit: "); name = input.nextLine(); count++; } System.out.println("Total number of names is: " + count); boolean repeat = true; boolean found = false; while(repeat) { System.out.println("Enter name to get birthday(or ZZZ to quit): "); name = input.nextLine(); if(name.equals(sentinal)) repeat = false; else { for(int i = 0; i < count && !found; i++) { if(names[i].equals(name)) { found = true; dateOfBirth = birthdates[i]; } } if(found) System.out.println("The birthdate of " + name + " is " + dateOfBirth); else System.out.println("Sorry, no entry for " + name); } found = false; } } }

this is the assignment:

Write an application that allows a user to enter the names and birthdates of up to 10 friends. Continue to prompt the user for names and birthdates until the user enters the sentinel value ZZZ for a name or has entered 10 names, whichever comes first. When the user is finished entering names, produce a count of how many names were entered, and then display the names. In a loop, continuously ask the user to type one of the names and display the corresponding birthdate or "Sorry, no entry for name" if the name has not been previously entered. The loop continues until the user enters ZZZ for a name.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!