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 pv, int kk, int vv) {
- this.day = pv;
- this.month = kk;
- this.year = vv;
- }
- public String toString() {
- return this.day + "." + this.month + "." + this.year;
- }
- 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;
- }
- /*
- * In assignment 92 method differneceInYears was added to MyDate
- * Copy the method here since it eases this assignment considerably.
- */
- public int differenceInYears(MyDate comparedDate) {
- int totalDays = this.day + (this.month * 30) + (this.year * 12 * 30);
- int totalDays2 = comparedDate.getDay() + (comparedDate.getMonth() * 30) + (comparedDate.getYear() * 12 * 30);
- int diffOfDays;
- if (totalDays > totalDays2) {
- diffOfDays = totalDays - totalDays2;
- } else {
- diffOfDays = totalDays2 - totalDays;
- }
- // int diffOfDays = totalDays - totalDays2;
- if (diffOfDays > 360) {
- int years = diffOfDays / 360;
- return years;
- } else if (diffOfDays == 360) {
- return 1;
- } else {
- return 0;
- }
- }
- public int getDay() {
- return day;
- }
- public int getMonth() {
- return month;
- }
- public int getYear() {
- return year;
- }
- }
Add Comment
Please, Sign In to add comment