Ask Question

Create a class called Date that includes three pieces of information as instance variables-a month (type int), a day (type int), and a year (type int). Your class should have a constructor that initializes the three instance variables and assumes that 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

+5
Answers (1)
  1. 22 August, 19:01
    0
    public class Date {

    private int month;

    private int day;

    private int year;

    / / Constructor

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

    this. month = month;

    this. day = day;

    this. year = year;

    }

    //Getters and setter

    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;

    }

    void displayDate () {

    System. out. println (getMonth () + "/"+getDay () + "/"+getYear ());

    }

    }

    //Test Class

    class DateTest {

    public static void main (String[] args) {

    Date dateOne = new Date (12, 25, 2019);

    dateOne. displayDate ();

    }

    }

    Explanation:

    Using Java programming Language Create the Date class with the instance variables (Month, day and year) all of type int Create the the constructor to initialize all the instance variables Create getters and setters for all the instance variables Create the displayDate () method which uses string concatenation along with the get () method of all the instance variables Create a test class that initializes an instance of the of the Date class Call the method displayDate on the instance of the class created
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Create a class called Date that includes three pieces of information as instance variables-a month (type int), a day (type int), and a year ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers