Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java - Creating a MyDate Class Setting up your program: You will need to create two classes this time. The first class should be called

Java - Creating a MyDate Class

Setting up your program: You will need to create two classes this time.

The first class should be called DateDemo and include a main method

The second class should be called MyDate and should be a template for a new type of object (and not include a main method).

You start by completing the MyDate class.

Step One: add the following private attributes (all integers)

Month

Day

(4-digit) Year

Step Two: Add two Constructors

MyDate() here you will need to set the attributes to default values (12/31/1999)

MyDate(int m, int d, int y) use input parameters to set the attribute values

You should add error checking to this function to ensure that a user has given you valid input. If their input is invalid, you should print an error message and set that variable to a default value.

The month should be a number between 1 and twelve

The day should be a number between 1 and thirty-one

The year should be a non-negative four-digit number

Step Three: Add the following Accessors to your program.

getMonth()

getDay()

getYear()

Step Four: Additional Methods to add to your class

setDate(int m, int d, int y) should allow the user to modify the attribute values. This function should again include error checking to make sure that the user is giving you reasonable input.

printDate() print the date to the screen

Now it is time to test our class. In the main method of DateDemo

Create a variable date1 that is created using the default constructor

Use the print method in the MyDate class to print date1

Create a variable date2 using the second constructor method (enter the data for your birthday)

Use the accessor method to print just the month attribute of date2

Create a variable date3 and try using the second constructor with an invalid data

Try changing date1 to your birthday using the setDate function

Use the print method in the MyDate class to print date1

Try setting date1 to an invalid date using the setDate function

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

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions

Question

BPR always involves automation. Group of answer choices True False

Answered: 1 week ago