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();

}

}

For QUESTION 4, please create a class, name it as "Program". Then

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

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

Output:

Program{ public static void main (String[] args){ Data r = new Data();

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); Test1 [Java Application] C:\Program Files (x86) Vava\jre6\bin\javaw.exe (Nov 19, 2014 11:19:03 AM) current date:2014/10/25 after addition of 5 days: current date: 2014/10/30 after addition of 2 week: current date: 2014/11/13 number of days that this Date must be adjusted to make it equal to the given Date is :-371 Testi [Java Application] C:\Program Files (x86)Vava\jre6\bin\javaw.exe (Nov 19, 2014 11:20:42 AM) current date: 2014/10/25 after addition of 5 days: current date: 2014/10/30 after addition of 2 week: current date: 2014/11/13 number of days that this Date must be adjusted to make it equal to the given Date is :6

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!