Question: JAVA Add three instance attributes (or variables) for the day, the month, and the year. At the top of the file, inside the package but

JAVA

Add three instance attributes (or variables) for the day, the month, and the year. At the top of the file, inside the package but before the class, add a statement to import the module java.util.Scanner. Then add a class attribute (static) called scan of type Scanner and initialize it with new Scanner(System.in). This will be useful for input.

Add a public method called input with no parameters and of type void. In this function, ask the user for the values of the date, then input them in the three attributes. Use scan.nextInt() to input the three values. If the value of the month is larger than 12, make it to 12. If it's less than 1, make it 1. The same way, restrict the date to the range [1, 31]. Add a public method called output with no parameters and of type void. In this function, output the date in the format "mm/dd/yyyy". You don't have to verify if the numbers have the right number of digits.

Add a constructor for the class with parameters for the day, month, and year. You can use other names for the parameters for convenience. Then in the constructor, initialize each of the attributes with the value of the corresponding parameter. Add a second default constructor with no parameters and assign the value 0 to all 3 parameters.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!