Java Application – Get Age

Java Application – Get Age

Create a java application to prompt the user for the year, month, and day of birth, and display their age in years.  Here is an example of a typical program run:

The main method and method stubs have already been written for you.  Upload the file GetAge.java from Moodle and use it to complete the assignment.

Do not make any changes to this code other than to add your name to the comments at the top of the file to indicate that you have completed the code; and to complete

the code in the method stubs.

Complete the code in the method stubs as follows:

public static int getYear(Scanner kb, int endYear)

The getYear method should use the Scanner parameter passed to prompt the client for their year of birth.  The year must be between zero and the endYear parameter.

Perform this processing in a loop until the year is valid.  Return the year of birth,

public static int getMonth(Scanner kb)

The getMonth method should use the Scanner parameter passed to prompt the client for their month of birth.  The month must be between 1 and 12.  Perform this

processing in a loop until the month is valid.  Return the month of birth,

public static int getDay(Scanner kb, int dobYear, int dobMonth)

The getDay method should use the Scanner parameter passed to prompt the client for their day of birth.  The day must be between 1 and a maximum day determined by the

month.  For example, the maximum day for January is 31, but for April it is 30.  The maximum day for February is 28 unless it is a leap year, in which case the maximum

day is 29.  Perform this processing in a loop until the day is valid.  Return the day of birth.

public static String getMonthName(int month)

The getMonthName method should return the name of the month that is passed as an argument to the method.

public static String getDaySuffix(int day)

The getDaySuffix method should return the suffix for the day of the month.  For example, the suffix for 1, 21, and 31 is “st”; for 2 and 22 is “nd”; for 3 and 23 is

“rd”; and for the remaining days is “th”.

public static int getAge(int dobYear, int dobMonth, int dobDay)

The getAge method should calculate and return the age based on the year, month, and day of birth.  The current date should be used to determine the age.

public static void displayAge(int dobYear, int dobMonth, int dobDay)

This method should call the getMonthName to get the name of the month.  It should call the getAge method to get the user’s age.  It should then display the formatted

date of birth and the user’s age.  If the user is 21 years of age or more, display that they are eligible to drink, otherwise display that they are not eligible to

drink alcohol.  See the run example on the previous page for an example of how to display this information.

HINT:

•    Provide dummy return values for the method stubs so that the program will compile.
•    Code only one method at a time and test that method until it works properly.
•    Provide appropriate comments for each method
Grading Rubric

GetAge.java

•    Correct File Name (GetAge.java) – case sensitive
•    Correct Class Name (GetAge) – case sensitive
•    Correct Style – comments for each method
•    Correct Style – indentation
•    Correct Style – White Space
•    Free of syntax errors
•    No changes made to the main method in the original code provided
•    getYear method prompt and validate correctly in loop
•    getMonth method prompt and validate correctly in loop
•    getDay method determine maximum day correctly
•    getDay method prompt and validate correctly in loop
•    getMonthName method returns correct month name
•    getAge method calculates and returns correct age
•    displayAge method calls the getMonthName method
•    displayAge method calls the getAge method
•    displayAge method displays formatted date
•    displayAge method displays age

PLACE THIS ORDER OR A SIMILAR ORDER WITH US TODAY AND GET AN AMAZING DISCOUNT 🙂

Get a 20 % discount on an order above $ 100
Use the following coupon code :
A+answer