Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions