Вы находитесь на странице: 1из 2

package birthdayreminder;

import java.util.Scanner;
/**
*
* @author Tristan
*/
public class BirthdayReminder {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// Scanner and variables
Scanner input = new Scanner(System.in);
final String STOP = "stop";
final int MAX_NUM_INPUTS = 10;
int y = 0;
int count = 0;
boolean validInput = false;
String stop;
String name;
String birthDate;
String[] names = new String[MAX_NUM_INPUTS];
String[] dates = new String[MAX_NUM_INPUTS];
// Do while statement to fill the arrays. (names and dates)
do{
// Get the name, birthdate, and see if the user wants to enter more names
System.out.print("Enter a friend's name: ");
name = input.nextLine();
System.out.print("Enter that friend's birthdate: ");
birthDate = input.nextLine();
System.out.print("If you wish to stop please enter 'stop'”
+ “ otherwise simply press enter to continue: ");
stop = input.nextLine();
// Set the user's inputted values to their corresponding array and raise
// the subscript value
names[count] = name;
dates[count] = birthDate;
++count;
// If statement to get us out of the loop once the arrays are full
if(count == MAX_NUM_INPUTS){
stop = STOP;
}
// If statement to display the total number of names entered when the
// user is finished entering names
if(stop.equals(STOP)){
System.out.println("\nThe total number of names entered”
+ “ was " + count);
}
// While statement condition set to stop the loop once
// String stop equals final String STOP
}while(!stop.equals(STOP));
// For loop to list the names entered into the array
System.out.print("The names entered in order were ");
for(int x = 0; x < count; ++x){
System.out.print(names[x] + " ");
}
// Reset the String stop value so we can enter the next loop
stop = "";
// While loop to show the user the values they entered and set to stop
// once String stop equals final String STOP
while(!stop.equals(STOP))
{
// Ask the user which birthdate they wish to view
System.out.println("\nEnter the name of the person you wish”
+ “ to see the birthdate for");
name = input.nextLine();
// While loop to find out if the name they want to check is even in the
// array
while(validInput == false) {
// If the name they enter is in the array we set the boolean validInput
// to true to escape the loop. Otherwise, just keep looping until a valid
// name is entered
if(names[y].equals(name))
validInput = true;
else
++y;
while(y == count){
System.out.println("!Error! \nThat name was not”
+ “ previously entered");
System.out.println("Enter the name of the person you”
+ “ wish to see the birthdate for");
name = input.nextLine();
y = 0;
}
}
// Display the name and birthdate of the name the user selected
if(validInput == true){
System.out.println(name + "'s birthdate is " + dates[y]);
}
// Find out if the user wants to stop or continue
System.out.print("If you wish to stop please enter 'stop'”
+ “ otherwise simply press enter to continue: ");
stop = input.nextLine();
// If the user decides to continue the y and validInput values must be
// reset
y = 0;
validInput = false;
}
}
}

Вам также может понравиться