Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

My question is 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 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 Dates capabilities.

My code is

public class Date {

int month;

int day;

int year;

public Date(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 static void main(String[] args) {

Date day = new Date(4,16,2012);

day.displayDate();

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

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

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

day.setMonth(12);

day.setDay(25);

day.setYear(2011);

day.displayDate();

}

}

This was given when someone previously answered, however this code does not work. Please help

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

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

6. How would you design your ideal position?

Answered: 1 week ago

Question

2. How do they influence my actions?

Answered: 1 week ago