Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a java program that allows the user to enter as many names and birthdays as they like. Each of these should be stored in

Create a java program that allows the user to enter as many names and birthdays as they like. Each of these should be stored in an object of the supplied Birthday class. You must create an InvalidBirthdayException that will be used by Birthday. Your drivers should handle the exceptions thrown. Once the names are entered, you should print the list using the Birthday toString() method. Finally, create an iterator to traverse the list and return the oldest person in the list.

Additional instructions/hints.

The birthday class contains two instance variables, a String name and an int bday. Defaults will be Fred with a birthday of 20160714.

Birthdays should be entered in the format yyyymmdd.

You should structure your program with methods, recommend one to enter the values for the list, one to print the list, and one to find the oldest.

findOldest must use an iterator to traverse the list, you are not allowed to sort on the birthday to find the oldest. printList can use an enhanced for to print the contents of the list.

You need to modify Birthday to implement Comparable. This should be used to find the oldest person. Think about who would be the oldest

Example output

Enter the person's name. Enter -1 to exit

Name cannot be empty.

Enter the person's name. Enter -1 to exit

Sally

Enter the birthday (yyyymmdd)

0

Enter the person's name. Enter -1 to exit

Fred

Enter the birthday (yyyymmdd)

-19961212

Birthday of -19961212 is not valid. Must be between 0 and 20160714

Enter the birthday (yyyymmdd)

19961212

Enter the person's name. Enter -1 to exit

Sue

Enter the birthday (yyyymmdd)

20160715

Birthday of 20160715 is not valid. Must be between 0 and 20160714

Enter the birthday (yyyymmdd)

2016071$

Invalid characters found in the entered birthday

Enter the birthday (yyyymmdd)

20160714

Enter the person's name. Enter -1 to exit

-1

Sally 0

Fred 19961212

Sue 20160714

The oldest person in the list is Sally 0

Submit and .

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

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions

Question

1. Explain how technology has changed the learning environment.

Answered: 1 week ago