Question: For QUESTION 4, please create a class, name it as Program. Then add a main method to this class. Finally, create an object of class
For QUESTION 4, please create a class, name it as "Program". Then add a main method to this class. Finally, create an object of class Date which is defined in QUESTION 3 in the main method, and call its methods.
As an example, see the following code:
class Program{
public static void main (String[] args){
Data r = new Data();
r.addDays();
}
}

Below the QUESTION 4. Here is a code for question 3 and want is prints out



Output:
![Program{ public static void main (String[] args){ Data r = new Data();](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3ba5662846_98166f3ba55df969.jpg)
Below the block box are certain requirements for the code:
-And the coding language for this code must be in java and not in python, C code, etc
-Also In the code, use comments to explain the purpose of the declared variables and the lines in the code.
3. Implement a Date class for the concept of date. Each date object contains year, month and day. Further, each date object must have the following methods: a. print, that prints the value of the date in the output. b. addDays, which takes a parameter n of type int and adds n days to the date. c. compare, which takes a parameter of type Date and calculates the number of days between the date of the current object and the input object. public class MyDatei private int day,month.year; public MyDate1(int day, int month, int year) { superO; this.day = day: this.month = month; this year = year; ) public void addDays(int days) day=day+days: ) public void addWeeks(int weeks) day=day+7*weeks; if(day>31) int daydiff=day-31; month++; day=daydiff: } ) public int getDayO return day: ) public void setDay(int day) { this.day = day: > public int getMonth() { return month; ) public void setMonth(int month) { this month = month; ) public int getYear() { return year; ) public void setYear(int year) { this.year = year; > public boolean isLeapYear(int year) boolean isLeap = false; iflyear % 400 == 0) { isLeap = true; ) else if (year % 100 == 0) isLeap = false; } else if(year % 4 == 0) { isLeap = true; } else { isLeap= false; ) return isLeap: ) public int daysTo(MyDate other) int year1, month1,dayl: dayi=other.getDayo: monthl=other.getMonth(): yearl=other.getYear(); int yeardiff,monthdiff, daydiff; if(yearl>year) yeardiff=(yearl-year): if(monthl>month) { monthdiff=(month1-month); } else { monthdiff=month-monthi; } if(dayl>day) { daydiff=(day1-day): else { daydiff=(day-day1): } retum daydiff+30*monthdiff+365"yeardiff; } else { yeardiff=(year-yeari); if(monthl>month) { monthdiff=(month1-month); } else { monthdiff-month-monthi; } if(day1>day) { daydiff=(dayi-day): } else { daydiff=(day-day); retum -(daydiff+30*month diff+365"yeardiff): } ) public String toStringo return "+year+"/*+month+"/"+day: =a Test1.java package com.charan; public class Testi public static void main(String[] args) { MyDatei date=new MyDate1(25,10,2014); System.out.println("current date:"+ date.toString(): System.out.println("after addition of 5 days:"); date.addDays(5); System.out.println(" current date:"+ date.toString(): System.out.println(" after addition of 2 week:"); date.addWeeks(2); System.out.println(" current date:"+ date.toString(): MyDatei datel=new MyDate1(19,11,2014); System.out.println(" number of days that this Date must be adjusted to make it equal to the given Date is :" +date.daysTo(datel);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
