aj98

Untitled

Aug 16th, 2018
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1.  
  2. public class MyDate {
  3.  
  4.     private int day;
  5.     private int month;
  6.     private int year;
  7.  
  8.     public MyDate(int day, int month, int year) {
  9.         this.day = day;
  10.         this.month = month;
  11.         this.year = year;
  12.     }
  13.  
  14.     public String toString() {
  15.         return this.day + "." + this.month + "." + this.year;
  16.     }
  17.  
  18.     public void advance() {//91.1
  19.         day++;
  20.         if (this.day > 30) {
  21.             this.day = 1;
  22.             this.month++;
  23.             if (this.month > 12) {
  24.                 this.month = 1;
  25.                 this.year++;
  26.             }
  27.         }
  28.  
  29.     }
  30.    
  31.    
  32.      public void advance(int numberOfDays) {//91.2
  33.         for (int i = 1; i <= numberOfDays; i++) {
  34.             this.advance();
  35.  
  36.         }
  37.  
  38.     }
  39.  
  40.     public MyDate afterNumberOfDays(int days) {//91.3
  41.  
  42.         MyDate newMyDate = new MyDate(day, month, year);
  43.  
  44.         for (int i = 1; i <= days; i++) {
  45.             newMyDate.advance(days);
  46.  
  47.         }
  48.         return newMyDate;
  49.  
  50.     }
  51.  
  52.    
  53.  
  54.     public boolean earlier(MyDate compared) {
  55.         if (this.year < compared.year) {
  56.             return true;
  57.         }
  58.  
  59.         if (this.year == compared.year && this.month < compared.month) {
  60.             return true;
  61.         }
  62.  
  63.         if (this.year == compared.year && this.month == compared.month
  64.                 && this.day < compared.day) {
  65.             return true;
  66.         }
  67.  
  68.         return false;
  69.     }
  70.  
  71. }
Add Comment
Please, Sign In to add comment