Create a program that repeatedly reads in a name and age from the keyboard

computer science

Description

NETBEANS IDE 8.0.2 - CLEAR INSTRUCTIONS (ATTACHED)

For this assignment, you'll create a program that repeatedly reads in a name and age from the keyboard. It will store that data in Person objects. Each persons will be stored together in an ArrayList.

After each data for a person is entered, ask the user if they want to enter another student. Continue reading and storing persons until the user indicates they're finished.

Create a project

That will be your "main" class (since it's the class that has this

public static void main(String[] args)

From here on, I'll refer to that as the "main" class.

Create a Person class, which will hold the person's name and age.

No need for first/middle/last. Just have a name:( I HAVE DONE THAT PART)

public static void main(String[] args) {

Scanner keyboard = new Scanner(System.in);

System.out.print("Enter your name: ");

String name = keyboard.nextLine();

System.out.print("Enter your age: ");

String lineEntered = keyboard.nextLine();

int age = Integer.parseInt(lineEntered);

The "main" class will

Repeatedly prompt the user to enter the person's name and age

See the sample output for the data validation to do

UPDATE:  You can assume that for the age, the user is only typing numeric values

Create a new Person instance

Store that instance in an ArrayList called people

Ask the user if they want to enter another name (Y or N)

Keep reading in names until the user enters "N"

When the user is finished entering names, output the list of names

This will be done with the help of a method called output, which you will create in the Person class.

That output method will concatenate return a string having the name followed by the age in parentheses (see sample output below)

Sample output (yours must match)
Enter name: John Sam
Enter age: 11
Another (Y/N): Y
Enter name:
ERROR: Please enter a name
Enter name: George Var
Enter age: -1
ERROR: age must be 0 or higher
Enter age: 9
Another (Y/N): x
ERROR: Enter Y or N
Another (Y/N): N
You entered 2 names:
John Sam (11)
George Var (9)

Instruction Files

Related Questions in computer science category


Disclaimer
The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.