0

any one can figure out dis

Define a class: MyDate, including fields: year, month, day; member methods: setYear, getYear, isLeapYear (boolean, determine whether the current is a leap year), print(print year\month\day of the object). (1) In “main”method, through: “MyDate d1=new MyDate(); MyDate d2=new MyDate(2009,4,1);”construct a MyDate object d1(1999.1.1) and a MyDate object d2(2009.4.1), and print the information of d1 and d2, respectively. (2) Make the “year”of d1 have the same value as d2, make the “month”of d2 have the same value as d1, then print the information of d1 and d2.

24th Dec 2016, 8:40 AM
xo101
2 Réponses
0
class MyDate{ private int year; private int month; private int day; public void setYear(int yr){ year=yr; } public int getYear(){ return year; } //Add getMonth/setMonth and day with the same code changing Year for Month/Day public MyDate(int year, int month, int day){ year=year; month=month; day=day; } public boolean isLeapYear() { if(year%4==0&&(year%400==0||year%100!=0){return true;} return false; } }
3rd Mar 2017, 7:16 PM
Qwerty
0
This is the class MyDate. The main is easier, and it looks like homework, I'm I right? xD Well, I hope that helps. In case it is homework, some of the code is...dirty, don't do that.
3rd Mar 2017, 7:18 PM
Qwerty