Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Thanks for reviewing my question. Please answer in java and do not reuse other chegg answers. this is a 9 step question. I have attached

image text in transcribed

Thanks for reviewing my question. Please answer in java and do not reuse other chegg answers. this is a 9 step question.

image text in transcribed

I have attached the code provided

In this exercise, you'll write an application that gets the uue's date of birth calculates the user's age in years, and displays the user's age. When you're done, the console should look something like this: Enter your date of birth (IOE-Y-DD): 1966-02-14 the user's age Welcome to the Age Calculator Your date o birth is Feb 4, 1960 The current date is Apr 11, 2017 Your age is 49 1. Open the project named ch14_ex2_AgeCalculator that's in the ex_starts folder. Then, review the code in the Age Calculator App class 2. Add code to this class that gets the current date and stores it in a LocalDate object. 3. Add code that parses the string entered by the user to create a LocalDate object. 4. Add code to format and print the user's date of birth. 5. Add code to format and print the current date. 6. Add code to calculate and print the user's age in years, 7. Run the application and test it to make sure it works correctly for a date in the correct format. 8. Run the application and test it with a date in an invalid format such as "Feb 4. 1968". This should cause an exception to occur. 9. Run the application again, enter a date of birth that's after the current date. and notice that the age is displayed as a negative number. To fix this, validate the date to be sure it isn't after the current date. If it is, display an error message. Run the application one more time to test this change. Source History IG 7 public class AgeCalculatorApp B 9 public static void main(String[] args) System.out.println("welcome to the Age Calculator "); 10 12 12 13 14 15 Get the current date LocalDate currentDate = LocalDate.now(); W cet input from the the user Scanner sc = new Scanner (System.in); System.out.print("Enter your date of birth (YYYY-MM-DD): "); string dateofBirthstring; da teofbirthstring - sc.nextLine(); System.out.printin(); 16 17 28 19 20 21 1/ Get and validate user's date of birth telut final DateTime Formatter dtf - DateTimeFormatter.ofpattern("YYY-MM-dd": 23 24 LocalDate birthDate = LocalDate.parse(dateoBirthstring, dtt); System.out.println(birthDate): 25 26 27 28 29 30 if (currentDate.is before (birthDate) 31 System.out.println("Please Enter Vaild DOB, Must be before current date"); 1 else 32 33 + dd, YYYY"): 35 DateTime Formatter DateTime Formatter.of Pattern ("MMM 1 catch Exception... ch System.out.println("invaild DOB, Try again."); > 37 38 39 40 41 If user's date of birth is valid Format and print user's date of birth System.out.println("Your date of birth is + birthgate. format formatter) ); I 43 44 1. Format and print the current date System.out.println("The current date is currentDate.format(termatten)): 46 47 W calculate and print the user's age System.out.println("Your age 1 + Chronounit. YEARS.between (Date, current Date!): h 50

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

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions

Question

Define and measure service productivity.

Answered: 1 week ago