Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Create a class called Date that includes 3 instance variablesa month (type int), a day (type int), and a year (type int). Provide a constructor

Create a class called Date that includes 3 instance variables—a month (type int), a day (type int), and a year (type int). Provide a constructor that initializes the 3 instance variables and assumes the values provided are correct. Provide a set and a get method for each instance variable. Provide a method displayDate that displays the month, day, and year separated by forward slashes(/). Write a test application named DateTest that demonstrates class Date’s capabilities.

I can not figure out what I am doing wrong.... Here is what I have so far

// -- Data Class
//CSIS 212-

public class DateClass
{
int month;

int day;

int year;

public DateClass(int month, int day, int year) {

this.month = month;

this.day = day;

this.year = year;

}

public int getMonth() {

return month;

}

public void setMonth(int month) {

this.month = month;

}

public int getDay() {

return day;

}

public void setDay(int day) {

this.day = day;

}

public int getYear() {

return year;

}

public void setYear(int year) {

this.year = year;

}

public void displayDate() {

System.out.println(month + "/" + day + "/" + year);

}

}

public class DateTest {

public void main(String[] args) {

Date day = new Date(06,22,2020);

day.displayDate();

System.out.println("Month: " + day.getMonth());

System.out.println("Day: " + day.getDay());

System.out.println("Year: " + day.getYear());

day.setMonth(06);

day.setDay(22);

day.setYear(2020);

day.displayDate();
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Managerial Accounting Decision Making and Motivating Performance

Authors: Srikant M. Datar, Madhav V. Rajan

1st edition

132816245, 9780132816243, 978-0137024872

Students also viewed these Programming questions

Question

2. Recognize students who are helpful.

Answered: 1 week ago