Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyDate {
- private int day;
- private int month;
- private int year;
- public MyDate(int day, int month, int year) {
- this.day = day;
- this.month = month;
- this.year = year;
- }
- public String toString() {
- return this.day + "." + this.month + "." + this.year;
- }
- public void advance() {//91.1
- day++;
- if (this.day > 30) {
- this.day = 1;
- this.month++;
- if (this.month > 12) {
- this.month = 1;
- this.year++;
- }
- }
- }
- public void advance(int numberOfDays) {//91.2
- for (int i = 1; i <= numberOfDays; i++) {
- this.advance();
- }
- }
- public MyDate afterNumberOfDays(int days) {//91.3
- MyDate newMyDate = new MyDate(day, month, year);
- for (int i = 1; i <= days; i++) {
- newMyDate.advance(days);
- }
- return newMyDate;
- }
- public boolean earlier(MyDate compared) {
- if (this.year < compared.year) {
- return true;
- }
- if (this.year == compared.year && this.month < compared.month) {
- return true;
- }
- if (this.year == compared.year && this.month == compared.month
- && this.day < compared.day) {
- return true;
- }
- return false;
- }
- }
Add Comment
Please, Sign In to add comment