Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dateproj;
- public class DateProj
- {
- private static Date d=new Date(28,2,2001);
- private static Date y=new Date(23,9,98);
- public static void main(String[] args)
- {
- System.out.println(d.compareTo(y));
- Date m = d.getTomorrow();
- System.out.println(m.toString());
- int x= 6;
- Date z = new Date(1,9,2014);
- for(int i = 0; i<x; i++){
- z = z.getTomorrow();
- }
- System.out.println(z.toString());
- }
- private boolean isLeapYear(){
- if(d.getYear()%4==0)
- return true;
- return false;
- }
- }
- ------------------------------------------------------------
- package dateproj;
- import java.util.Calendar;
- import java.util.GregorianCalendar;
- /**
- * Document : yoyo Created on : 08/09/2014, 12:49:47 Author : Admin
- */
- public class Date
- {
- private int dd;
- private int mm;
- private int yy;
- public Date(int day, int month, int year)
- {
- dd = day;
- mm = month;
- yy = year;
- }
- public int getYear()
- {
- return yy;
- }
- public int getMonth()
- {
- return mm;
- }
- public int getDay()
- {
- return dd;
- }
- public void setYear(int yearToSet)
- {
- yy = yearToSet;
- }
- public void setMonth(int yearToSet)
- {
- mm = yearToSet;
- }
- public void setDay(int yearToSet)
- {
- dd = yearToSet;
- }
- public int compareTo(Date other)
- {
- if((yy > other.yy) || (mm > other.mm && yy == other.yy) || (dd > other.dd && mm == other.mm && yy >= other.yy))
- {
- return 1;
- }
- if((yy < other.yy) || (mm < other.mm && yy == other.yy) || (dd < other.dd && mm <= other.mm && yy <= other.yy))
- {
- return -1;
- }
- return 0;
- }
- public String toString()
- {
- return ("<" + dd + "><" + mm + "><" + yy + ">");
- }
- public Date getTomorrow()
- {
- int x = dd + 1;
- int y = mm;
- int z = yy;
- if(dd == 31
- || (dd == 30 && mm % 2 == 0)
- || (yy % 4 == 0 && mm == 2 && dd == 29)
- || (mm == 2 && dd == 28 && yy % 4 != 0))
- {
- y++;
- x = 1;
- }
- if(mm == 13)
- {
- z++;
- y = 1;
- }
- Date n = new Date(x, y, z);
- return n;
- }
- public void setCurrent(){
- GregorianCalendar n = new GregorianCalendar();
- dd = n.get(Calendar.DAY_OF_MONTH);
- mm = n.get(Calendar.MONTH);
- yy = n.get(Calendar.YEAR);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement