Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //In this program i build a type of an object called "Date"
- public class Date {
- private int dd;
- private int mo;
- private int yy;
- //These are the creating actions
- //This is a creating action for the "Date" object that gets parameters (day, month, year)
- public Date(int dd,int mo,int yy)
- {
- this.dd = dd;
- this.mo = mo;
- this.yy = yy;
- }
- //This is a creating action for the "Date" object that doesn't get parameters
- //it automatically declares the year to be 1900, the month January and the day the first
- public Date()
- {
- this.dd = 1;
- this.mo = 1;
- this.yy = 1900;
- }
- //This is a copying building action, that gets another date as a parameter
- //it builds another object from the type of date with the same parameters(day,month,year)
- public Date(Date d1)
- {
- this.dd = d1.getDay();
- this.yy = d1.getYear();
- this.mo = d1.getMonth();
- }
- //These are the setting actions
- //This is a setting operation that determines the day
- public void setDay(int nd)
- {
- this.dd = nd;
- }
- //This is a setting operation that determines the month
- public void setMonth(int nm)
- {
- this.mo =nm;
- }
- //This is a setting operation that determines the year
- public void setYear(int ny)
- {
- this.yy =ny;
- }
- /*
- These are the returning operations
- This is a returning operation that returns the day
- */
- public int getDay()
- {return this.dd;
- }
- //This is a returning operation that returns the month
- public int getMonth()
- {return this.mo;
- }
- //This is a returning operation that returns the year
- public int getYear()
- {return this.yy;
- }
- //This is a command that allows the programmer to print the values of the date object
- public String toString()
- {return("Day: "+this.dd+" Month: "+this.mo+" Year: "+this.yy);
- }
- /*
- This is a calcualting operation that returns the number of days passed from another date that is
- given as a parameter
- */
- public int difference(Date d2)
- {return((d2.getYear()-this.yy)*360+(d2.getMonth()-this.mo)*30+d2.getDay()-this.dd);
- }
- /*
- This is a calcualting operation that returns if a date is the same date
- as the one given as a parameter
- */
- public boolean equal(Date d3)
- {boolean equal=true;
- if(this.dd==d3.getDay()&&this.mo==d3.getMonth()&&this.yy==d3.getYear())
- {return equal;
- }
- else
- {equal = false;
- return equal;
- }
- }
- /*
- This is a calculating operation that returns if a date given as a parameter
- is after an original date
- */
- public boolean isAfter(Date d4)
- {boolean after=false;
- if(this.yy<d4.getYear())
- after = true;
- if(this.yy==d4.getYear())
- {if(d4.getMonth()>this.mo)
- after = true;
- if(d4.getMonth()==this.mo)
- {if(d4.getDay()>this.dd)
- after = true;
- if(d4.getDay()==this.dd)
- after = false;
- }
- }
- return after;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement