SlideShare a Scribd company logo
publicclass Date {
privatestatic String DATE_SEPARATOR = "/";
privatestaticintDAYS_PER_WEEK = 7;
//Attributes
privateint day;
privateint month;
privateint year;
/**
* Default Constructor
* Instantiates an object of type Date to 1/1/2000
*/
public Date() {
this.day = 1;
this.month = 1;
this.year = 2000;
}
/**
* Constructs a new date object to represent the given date.
* @param day
* @param month
* @param year
*/
public Date(int day, int month, int year) {
if(isValid(day, month, year)) {
this.day = day;
this.month = month;
this.year = year;
} else
System.out.println("Invalid Date.");
}
/**
* Returns the day value of this date for example, for the date 2006/07/22, returns 22.
* @return
*/
publicint getDay() {
return day;
}
/**
* Returns the month value of this date ,for example, for the date 2006/07/22, returns 7.
* @return
*/
publicint getMonth() {
return month;
}
/**
* Returns the year value of this date, for example , the date 2006/07/22, returns 2006.
* @return
*/
publicint getYear() {
return year;
}
/**
* @param day the day to set
*/
publicvoid setDay(int day) {
this.day = day;
}
/**
* @param month the month to set
*/
publicvoid setMonth(int month) {
this.month = month;
}
/**
* @param year the year to set
*/
publicvoid setYear(int year) {
this.year = year;
}
/**
* Returns true if the year of this date is a leap year.
* A leap year occurs every 4 years , except for multiples of 100 that are not multiples of 400.
* For example, 1956,1844,1600,and 2000 are leap years, but 1983,2002,1700,and 1900 are not.
* @return
*/
publicboolean isLeapYear(){
if(((this.year % 400) == 0) || (((this.year % 4) == 0) && ((this.year % 100) != 0)))
returntrue;
else
returnfalse;
}
/**
* Checks if the date is valid
* @param day
* @param month
* @param year
* @return
*/
publicboolean isValid(int day, int month, int year) {
if((month < 1) || (12 < month))
returnfalse;
else {
if(((month == 1) || (month == 3) || (month == 5) || (month == 7) ||
(month == 8) || (month == 10) || (month == 12)) && ((day < 1) || (31 < day)))
returnfalse;
elseif(((month == 4) || (month == 6) || (month == 9) || (month == 11)) && ((day < 1) || (30 <
day)))
returnfalse;
elseif(month == 2) {
if(isLeapYear() && ((day < 1) || (29 < day)))
returnfalse;
elseif((day < 1) || (28 < day))
returnfalse;
}
}
returntrue;
}
/**
* Returns the maximum number of days in a month
* @return
*/
publicint maxMonthDays() {
if(this.month == 2) {
if(isLeapYear())
return 29;
else
return 28;
} elseif((this.month == 1) || (this.month == 3) || (this.month == 5) || (this.month == 7) ||
(this.month == 8) || (this.month == 10) || (this.month == 12))
return 31;
else
return 30;
}
/**
* Checks if this dat is same as other date
* @param other
* @return
*/
publicboolean isEqual(Date other) {
if((this.day == other.day) && (this.month == other.month) && (this.year == other.year))
returntrue;
else
returnfalse;
}
/**
* Moves this Date object forward in time by the given number of days .
* @param days
*/
publicvoid addDays(int days) {
while(days != 0){
int maxDays = maxMonthDays();
if((maxDays - this.day) >= days) {
this.day += days;
days = 0;
}
else{
days -= (maxDays - this.day);
this.day = 0;
if(month == 12) {
this.month = 1;
this.year += 1;
} else
this.month += 1;
}
}
}
/**
* Moves this date object forward in time by the given amount of seven day weeks
* @param weeks
*/
publicvoid addWeeks(int weeks) {
addDays(weeks * DAYS_PER_WEEK);
}
/**
* Returns the number of days that this Date must be adjusted to make it equal to the given other
Date.
* @param other
* @return
*/
publicint daysTo(Date other) {
Date temp = new Date(this.day, this.month, this.year);
if(temp.isEqual(other))
return 0;
else{
int noOfDays = 0;
do {
if((temp.year == other.year) && (temp.month == other.month)) {
noOfDays += (other.day - temp.day);
temp.day = other.day;
}
else{
int maxDays = temp.maxMonthDays();
noOfDays += (maxDays - temp.day);
temp.day = 0;
if(temp.month == 12) {
temp.month = 1;
temp.year += 1;
}
else
temp.month += 1;
}
} while(!temp.isEqual(other));
return noOfDays;
}
}
/**
* Returns a String representation of this date in year/month/day order, such as "2006/07/22"
*/
@Override
public String toString() {
returnthis.day + DATE_SEPARATOR + this.month + DATE_SEPARATOR + this.year;
}
}
publicclass Driver {
publicstaticvoid main(String[] args) {
Date d1 = new Date(29, 1, 2016);
Date d2 = new Date(29, 12, 2015);
//Add 5 days to d1
System.out.println(" Add 5 days to " + d1 + " : ");
d1.addDays(5);
System.out.println(d1);
//Add 5 days to d2
System.out.println(" Add 5 days to " + d2 + " : ");
d2.addDays(5);
System.out.println(d2);
Date d3 = new Date(28, 8, 2016);
//Add 1 week to d3
System.out.println(" Add 1 week to " + d3 + " : ");
d3.addWeeks(1);
System.out.println(d3);
Date d4 = new Date(31, 8, 2016);
Date d5 = new Date(1, 10, 2016);
System.out.println(" The number of days that " + d4 + " must be adjusted to make it equal to
" + d5 + " : " + d4.daysTo(d5) + " days.");
}
}
SAMPLE OUTPUT :
Add 5 days to 29/1/2016 :
3/2/2016
Add 5 days to 29/12/2015 :
3/1/2016
Add 1 week to 28/8/2016 :
4/9/2016
The number of days that 31/8/2016 must be adjusted to make it equal to 1/10/2016 : 31 days.
Solution
publicclass Date {
privatestatic String DATE_SEPARATOR = "/";
privatestaticintDAYS_PER_WEEK = 7;
//Attributes
privateint day;
privateint month;
privateint year;
/**
* Default Constructor
* Instantiates an object of type Date to 1/1/2000
*/
public Date() {
this.day = 1;
this.month = 1;
this.year = 2000;
}
/**
* Constructs a new date object to represent the given date.
* @param day
* @param month
* @param year
*/
public Date(int day, int month, int year) {
if(isValid(day, month, year)) {
this.day = day;
this.month = month;
this.year = year;
} else
System.out.println("Invalid Date.");
}
/**
* Returns the day value of this date for example, for the date 2006/07/22, returns 22.
* @return
*/
publicint getDay() {
return day;
}
/**
* Returns the month value of this date ,for example, for the date 2006/07/22, returns 7.
* @return
*/
publicint getMonth() {
return month;
}
/**
* Returns the year value of this date, for example , the date 2006/07/22, returns 2006.
* @return
*/
publicint getYear() {
return year;
}
/**
* @param day the day to set
*/
publicvoid setDay(int day) {
this.day = day;
}
/**
* @param month the month to set
*/
publicvoid setMonth(int month) {
this.month = month;
}
/**
* @param year the year to set
*/
publicvoid setYear(int year) {
this.year = year;
}
/**
* Returns true if the year of this date is a leap year.
* A leap year occurs every 4 years , except for multiples of 100 that are not multiples of 400.
* For example, 1956,1844,1600,and 2000 are leap years, but 1983,2002,1700,and 1900 are not.
* @return
*/
publicboolean isLeapYear(){
if(((this.year % 400) == 0) || (((this.year % 4) == 0) && ((this.year % 100) != 0)))
returntrue;
else
returnfalse;
}
/**
* Checks if the date is valid
* @param day
* @param month
* @param year
* @return
*/
publicboolean isValid(int day, int month, int year) {
if((month < 1) || (12 < month))
returnfalse;
else {
if(((month == 1) || (month == 3) || (month == 5) || (month == 7) ||
(month == 8) || (month == 10) || (month == 12)) && ((day < 1) || (31 < day)))
returnfalse;
elseif(((month == 4) || (month == 6) || (month == 9) || (month == 11)) && ((day < 1) || (30 <
day)))
returnfalse;
elseif(month == 2) {
if(isLeapYear() && ((day < 1) || (29 < day)))
returnfalse;
elseif((day < 1) || (28 < day))
returnfalse;
}
}
returntrue;
}
/**
* Returns the maximum number of days in a month
* @return
*/
publicint maxMonthDays() {
if(this.month == 2) {
if(isLeapYear())
return 29;
else
return 28;
} elseif((this.month == 1) || (this.month == 3) || (this.month == 5) || (this.month == 7) ||
(this.month == 8) || (this.month == 10) || (this.month == 12))
return 31;
else
return 30;
}
/**
* Checks if this dat is same as other date
* @param other
* @return
*/
publicboolean isEqual(Date other) {
if((this.day == other.day) && (this.month == other.month) && (this.year == other.year))
returntrue;
else
returnfalse;
}
/**
* Moves this Date object forward in time by the given number of days .
* @param days
*/
publicvoid addDays(int days) {
while(days != 0){
int maxDays = maxMonthDays();
if((maxDays - this.day) >= days) {
this.day += days;
days = 0;
}
else{
days -= (maxDays - this.day);
this.day = 0;
if(month == 12) {
this.month = 1;
this.year += 1;
} else
this.month += 1;
}
}
}
/**
* Moves this date object forward in time by the given amount of seven day weeks
* @param weeks
*/
publicvoid addWeeks(int weeks) {
addDays(weeks * DAYS_PER_WEEK);
}
/**
* Returns the number of days that this Date must be adjusted to make it equal to the given other
Date.
* @param other
* @return
*/
publicint daysTo(Date other) {
Date temp = new Date(this.day, this.month, this.year);
if(temp.isEqual(other))
return 0;
else{
int noOfDays = 0;
do {
if((temp.year == other.year) && (temp.month == other.month)) {
noOfDays += (other.day - temp.day);
temp.day = other.day;
}
else{
int maxDays = temp.maxMonthDays();
noOfDays += (maxDays - temp.day);
temp.day = 0;
if(temp.month == 12) {
temp.month = 1;
temp.year += 1;
}
else
temp.month += 1;
}
} while(!temp.isEqual(other));
return noOfDays;
}
}
/**
* Returns a String representation of this date in year/month/day order, such as "2006/07/22"
*/
@Override
public String toString() {
returnthis.day + DATE_SEPARATOR + this.month + DATE_SEPARATOR + this.year;
}
}
publicclass Driver {
publicstaticvoid main(String[] args) {
Date d1 = new Date(29, 1, 2016);
Date d2 = new Date(29, 12, 2015);
//Add 5 days to d1
System.out.println(" Add 5 days to " + d1 + " : ");
d1.addDays(5);
System.out.println(d1);
//Add 5 days to d2
System.out.println(" Add 5 days to " + d2 + " : ");
d2.addDays(5);
System.out.println(d2);
Date d3 = new Date(28, 8, 2016);
//Add 1 week to d3
System.out.println(" Add 1 week to " + d3 + " : ");
d3.addWeeks(1);
System.out.println(d3);
Date d4 = new Date(31, 8, 2016);
Date d5 = new Date(1, 10, 2016);
System.out.println(" The number of days that " + d4 + " must be adjusted to make it equal to
" + d5 + " : " + d4.daysTo(d5) + " days.");
}
}
SAMPLE OUTPUT :
Add 5 days to 29/1/2016 :
3/2/2016
Add 5 days to 29/12/2015 :
3/1/2016
Add 1 week to 28/8/2016 :
4/9/2016
The number of days that 31/8/2016 must be adjusted to make it equal to 1/10/2016 : 31 days.

More Related Content

Similar to publicclass Date {privatestatic String DATE_SEPARATOR = ;pr.pdf

Write a program to generate the entire calendar for one year. The pr.pdf
Write a program to generate the entire calendar for one year. The pr.pdfWrite a program to generate the entire calendar for one year. The pr.pdf
Write a program to generate the entire calendar for one year. The pr.pdf
arihantmobileselepun
 
ThreeTen
ThreeTenThreeTen
ThreeTen
彥彬 洪
 
@author Haolin Jin To generate weather for locatio.pdf
 @author Haolin Jin To generate weather for locatio.pdf @author Haolin Jin To generate weather for locatio.pdf
@author Haolin Jin To generate weather for locatio.pdf
chennaiallfoodwear
 
Assignment Details There is a .h file on Moodle that provides a defi.pdf
Assignment Details There is a .h file on Moodle that provides a defi.pdfAssignment Details There is a .h file on Moodle that provides a defi.pdf
Assignment Details There is a .h file on Moodle that provides a defi.pdf
jyothimuppasani1
 
Date time function in Database
Date time function in DatabaseDate time function in Database
Date time function in Database
Sarfaraz Ghanta
 
datetimefuction-170413055211.pptx
datetimefuction-170413055211.pptxdatetimefuction-170413055211.pptx
datetimefuction-170413055211.pptx
YashaswiniSrinivasan1
 
Please I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdfPlease I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdf
ankit11134
 
Q2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docx
Q2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docxQ2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docx
Q2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docx
amrit47
 
C++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfC++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdf
jaipur2
 
Synapse india dotnet development overloading operater part 4
Synapse india dotnet development overloading operater part 4Synapse india dotnet development overloading operater part 4
Synapse india dotnet development overloading operater part 4
Synapseindiappsdevelopment
 
Need to make a Java program which calculates the number of days betw.pdf
Need to make a Java program which calculates the number of days betw.pdfNeed to make a Java program which calculates the number of days betw.pdf
Need to make a Java program which calculates the number of days betw.pdf
anjandavid
 
Date and Timestamp Types In Snowflake (By Faysal Shaarani)
Date and Timestamp Types In Snowflake (By Faysal Shaarani)Date and Timestamp Types In Snowflake (By Faysal Shaarani)
Date and Timestamp Types In Snowflake (By Faysal Shaarani)Faysal Shaarani (MBA)
 
Dynamically Evolving Systems: Cluster Analysis Using Time
Dynamically Evolving Systems: Cluster Analysis Using TimeDynamically Evolving Systems: Cluster Analysis Using Time
Dynamically Evolving Systems: Cluster Analysis Using Time
Magnify Analytic Solutions
 
In this assignment, you will continue working on your application..docx
In this assignment, you will continue working on your application..docxIn this assignment, you will continue working on your application..docx
In this assignment, you will continue working on your application..docx
jaggernaoma
 
Functional C++
Functional C++Functional C++
Functional C++
Kevlin Henney
 
DO NOT use System.exit().DO NOT add the project or package stateme.pdf
DO NOT use System.exit().DO NOT add the project or package stateme.pdfDO NOT use System.exit().DO NOT add the project or package stateme.pdf
DO NOT use System.exit().DO NOT add the project or package stateme.pdf
info48697
 
Jsr310
Jsr310Jsr310
Jsr310
彥彬 洪
 
Data20161007
Data20161007Data20161007
Data20161007
capegmail
 
Date object.pptx date and object v
Date object.pptx date and object        vDate object.pptx date and object        v
Date object.pptx date and object v
22x026
 

Similar to publicclass Date {privatestatic String DATE_SEPARATOR = ;pr.pdf (20)

Write a program to generate the entire calendar for one year. The pr.pdf
Write a program to generate the entire calendar for one year. The pr.pdfWrite a program to generate the entire calendar for one year. The pr.pdf
Write a program to generate the entire calendar for one year. The pr.pdf
 
ThreeTen
ThreeTenThreeTen
ThreeTen
 
@author Haolin Jin To generate weather for locatio.pdf
 @author Haolin Jin To generate weather for locatio.pdf @author Haolin Jin To generate weather for locatio.pdf
@author Haolin Jin To generate weather for locatio.pdf
 
Assignment Details There is a .h file on Moodle that provides a defi.pdf
Assignment Details There is a .h file on Moodle that provides a defi.pdfAssignment Details There is a .h file on Moodle that provides a defi.pdf
Assignment Details There is a .h file on Moodle that provides a defi.pdf
 
Script Files
Script FilesScript Files
Script Files
 
Date time function in Database
Date time function in DatabaseDate time function in Database
Date time function in Database
 
datetimefuction-170413055211.pptx
datetimefuction-170413055211.pptxdatetimefuction-170413055211.pptx
datetimefuction-170413055211.pptx
 
Please I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdfPlease I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdf
 
Q2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docx
Q2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docxQ2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docx
Q2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docx
 
C++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfC++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdf
 
Synapse india dotnet development overloading operater part 4
Synapse india dotnet development overloading operater part 4Synapse india dotnet development overloading operater part 4
Synapse india dotnet development overloading operater part 4
 
Need to make a Java program which calculates the number of days betw.pdf
Need to make a Java program which calculates the number of days betw.pdfNeed to make a Java program which calculates the number of days betw.pdf
Need to make a Java program which calculates the number of days betw.pdf
 
Date and Timestamp Types In Snowflake (By Faysal Shaarani)
Date and Timestamp Types In Snowflake (By Faysal Shaarani)Date and Timestamp Types In Snowflake (By Faysal Shaarani)
Date and Timestamp Types In Snowflake (By Faysal Shaarani)
 
Dynamically Evolving Systems: Cluster Analysis Using Time
Dynamically Evolving Systems: Cluster Analysis Using TimeDynamically Evolving Systems: Cluster Analysis Using Time
Dynamically Evolving Systems: Cluster Analysis Using Time
 
In this assignment, you will continue working on your application..docx
In this assignment, you will continue working on your application..docxIn this assignment, you will continue working on your application..docx
In this assignment, you will continue working on your application..docx
 
Functional C++
Functional C++Functional C++
Functional C++
 
DO NOT use System.exit().DO NOT add the project or package stateme.pdf
DO NOT use System.exit().DO NOT add the project or package stateme.pdfDO NOT use System.exit().DO NOT add the project or package stateme.pdf
DO NOT use System.exit().DO NOT add the project or package stateme.pdf
 
Jsr310
Jsr310Jsr310
Jsr310
 
Data20161007
Data20161007Data20161007
Data20161007
 
Date object.pptx date and object v
Date object.pptx date and object        vDate object.pptx date and object        v
Date object.pptx date and object v
 

More from mukhtaransarcloth

S monoclinic is most stable since entropy is the .pdf
                     S monoclinic is most stable since entropy is the .pdf                     S monoclinic is most stable since entropy is the .pdf
S monoclinic is most stable since entropy is the .pdf
mukhtaransarcloth
 
Option D is correct. B is limiting reagent .pdf
                     Option D is correct.  B is limiting reagent      .pdf                     Option D is correct.  B is limiting reagent      .pdf
Option D is correct. B is limiting reagent .pdf
mukhtaransarcloth
 
Let us assume the conc of Ba(OH)2 is known to us .pdf
                     Let us assume the conc of Ba(OH)2 is known to us .pdf                     Let us assume the conc of Ba(OH)2 is known to us .pdf
Let us assume the conc of Ba(OH)2 is known to us .pdf
mukhtaransarcloth
 
london dispersion forces .pdf
                     london dispersion forces                         .pdf                     london dispersion forces                         .pdf
london dispersion forces .pdf
mukhtaransarcloth
 
Methods a, b, c, and e are formal additions of H2.pdf
                     Methods a, b, c, and e are formal additions of H2.pdf                     Methods a, b, c, and e are formal additions of H2.pdf
Methods a, b, c, and e are formal additions of H2.pdf
mukhtaransarcloth
 
h2s4 structure is H-S-S-S-S-H there for two middl.pdf
                     h2s4 structure is H-S-S-S-S-H there for two middl.pdf                     h2s4 structure is H-S-S-S-S-H there for two middl.pdf
h2s4 structure is H-S-S-S-S-H there for two middl.pdf
mukhtaransarcloth
 
freezing point decreases with increase in imp.pdf
                     freezing point decreases   with  increase  in imp.pdf                     freezing point decreases   with  increase  in imp.pdf
freezing point decreases with increase in imp.pdf
mukhtaransarcloth
 
We are currently living in the so-called information age which can b.pdf
We are currently living in the so-called information age which can b.pdfWe are currently living in the so-called information age which can b.pdf
We are currently living in the so-called information age which can b.pdf
mukhtaransarcloth
 
The balanced equation is2 H2O2 = 2 H2O + O2SolutionThe bal.pdf
The balanced equation is2 H2O2 = 2 H2O + O2SolutionThe bal.pdfThe balanced equation is2 H2O2 = 2 H2O + O2SolutionThe bal.pdf
The balanced equation is2 H2O2 = 2 H2O + O2SolutionThe bal.pdf
mukhtaransarcloth
 
Tay-Sachs disease is caused by a mutation (abnormal change) in the g.pdf
Tay-Sachs disease is caused by a mutation (abnormal change) in the g.pdfTay-Sachs disease is caused by a mutation (abnormal change) in the g.pdf
Tay-Sachs disease is caused by a mutation (abnormal change) in the g.pdf
mukhtaransarcloth
 
E.) is less acidic in other A ,B triple bond an.pdf
                     E.) is less acidic   in other A ,B triple bond an.pdf                     E.) is less acidic   in other A ,B triple bond an.pdf
E.) is less acidic in other A ,B triple bond an.pdf
mukhtaransarcloth
 
Solution when user sending the email, then user should select eithe.pdf
Solution when user sending the email, then user should select eithe.pdfSolution when user sending the email, then user should select eithe.pdf
Solution when user sending the email, then user should select eithe.pdf
mukhtaransarcloth
 
please give me points as nobody ecen noticed the qusetion as it is u.pdf
please give me points as nobody ecen noticed the qusetion as it is u.pdfplease give me points as nobody ecen noticed the qusetion as it is u.pdf
please give me points as nobody ecen noticed the qusetion as it is u.pdf
mukhtaransarcloth
 
covalent bond .pdf
                     covalent bond                                    .pdf                     covalent bond                                    .pdf
covalent bond .pdf
mukhtaransarcloth
 
Part-IQuestion 1. What is Dr. Warren’s hypothesis regarding the ba.pdf
Part-IQuestion 1. What is Dr. Warren’s hypothesis regarding the ba.pdfPart-IQuestion 1. What is Dr. Warren’s hypothesis regarding the ba.pdf
Part-IQuestion 1. What is Dr. Warren’s hypothesis regarding the ba.pdf
mukhtaransarcloth
 
Peru is not a part of the Southern South America.SolutionPeru .pdf
Peru is not a part of the Southern South America.SolutionPeru .pdfPeru is not a part of the Southern South America.SolutionPeru .pdf
Peru is not a part of the Southern South America.SolutionPeru .pdf
mukhtaransarcloth
 
Combustion of glucose is respiration. The equatio.pdf
                     Combustion of glucose is respiration. The equatio.pdf                     Combustion of glucose is respiration. The equatio.pdf
Combustion of glucose is respiration. The equatio.pdf
mukhtaransarcloth
 
in truss one...the forces in the member BC and DE have zero.in tru.pdf
in truss one...the forces in the member BC and DE have zero.in tru.pdfin truss one...the forces in the member BC and DE have zero.in tru.pdf
in truss one...the forces in the member BC and DE have zero.in tru.pdf
mukhtaransarcloth
 
iam giving you entire process of  forensc duplication;the response.pdf
iam giving you entire process of  forensc duplication;the response.pdfiam giving you entire process of  forensc duplication;the response.pdf
iam giving you entire process of  forensc duplication;the response.pdf
mukhtaransarcloth
 
How does traffic analysis work Internet data packets have two parts.pdf
How does traffic analysis work Internet data packets have two parts.pdfHow does traffic analysis work Internet data packets have two parts.pdf
How does traffic analysis work Internet data packets have two parts.pdf
mukhtaransarcloth
 

More from mukhtaransarcloth (20)

S monoclinic is most stable since entropy is the .pdf
                     S monoclinic is most stable since entropy is the .pdf                     S monoclinic is most stable since entropy is the .pdf
S monoclinic is most stable since entropy is the .pdf
 
Option D is correct. B is limiting reagent .pdf
                     Option D is correct.  B is limiting reagent      .pdf                     Option D is correct.  B is limiting reagent      .pdf
Option D is correct. B is limiting reagent .pdf
 
Let us assume the conc of Ba(OH)2 is known to us .pdf
                     Let us assume the conc of Ba(OH)2 is known to us .pdf                     Let us assume the conc of Ba(OH)2 is known to us .pdf
Let us assume the conc of Ba(OH)2 is known to us .pdf
 
london dispersion forces .pdf
                     london dispersion forces                         .pdf                     london dispersion forces                         .pdf
london dispersion forces .pdf
 
Methods a, b, c, and e are formal additions of H2.pdf
                     Methods a, b, c, and e are formal additions of H2.pdf                     Methods a, b, c, and e are formal additions of H2.pdf
Methods a, b, c, and e are formal additions of H2.pdf
 
h2s4 structure is H-S-S-S-S-H there for two middl.pdf
                     h2s4 structure is H-S-S-S-S-H there for two middl.pdf                     h2s4 structure is H-S-S-S-S-H there for two middl.pdf
h2s4 structure is H-S-S-S-S-H there for two middl.pdf
 
freezing point decreases with increase in imp.pdf
                     freezing point decreases   with  increase  in imp.pdf                     freezing point decreases   with  increase  in imp.pdf
freezing point decreases with increase in imp.pdf
 
We are currently living in the so-called information age which can b.pdf
We are currently living in the so-called information age which can b.pdfWe are currently living in the so-called information age which can b.pdf
We are currently living in the so-called information age which can b.pdf
 
The balanced equation is2 H2O2 = 2 H2O + O2SolutionThe bal.pdf
The balanced equation is2 H2O2 = 2 H2O + O2SolutionThe bal.pdfThe balanced equation is2 H2O2 = 2 H2O + O2SolutionThe bal.pdf
The balanced equation is2 H2O2 = 2 H2O + O2SolutionThe bal.pdf
 
Tay-Sachs disease is caused by a mutation (abnormal change) in the g.pdf
Tay-Sachs disease is caused by a mutation (abnormal change) in the g.pdfTay-Sachs disease is caused by a mutation (abnormal change) in the g.pdf
Tay-Sachs disease is caused by a mutation (abnormal change) in the g.pdf
 
E.) is less acidic in other A ,B triple bond an.pdf
                     E.) is less acidic   in other A ,B triple bond an.pdf                     E.) is less acidic   in other A ,B triple bond an.pdf
E.) is less acidic in other A ,B triple bond an.pdf
 
Solution when user sending the email, then user should select eithe.pdf
Solution when user sending the email, then user should select eithe.pdfSolution when user sending the email, then user should select eithe.pdf
Solution when user sending the email, then user should select eithe.pdf
 
please give me points as nobody ecen noticed the qusetion as it is u.pdf
please give me points as nobody ecen noticed the qusetion as it is u.pdfplease give me points as nobody ecen noticed the qusetion as it is u.pdf
please give me points as nobody ecen noticed the qusetion as it is u.pdf
 
covalent bond .pdf
                     covalent bond                                    .pdf                     covalent bond                                    .pdf
covalent bond .pdf
 
Part-IQuestion 1. What is Dr. Warren’s hypothesis regarding the ba.pdf
Part-IQuestion 1. What is Dr. Warren’s hypothesis regarding the ba.pdfPart-IQuestion 1. What is Dr. Warren’s hypothesis regarding the ba.pdf
Part-IQuestion 1. What is Dr. Warren’s hypothesis regarding the ba.pdf
 
Peru is not a part of the Southern South America.SolutionPeru .pdf
Peru is not a part of the Southern South America.SolutionPeru .pdfPeru is not a part of the Southern South America.SolutionPeru .pdf
Peru is not a part of the Southern South America.SolutionPeru .pdf
 
Combustion of glucose is respiration. The equatio.pdf
                     Combustion of glucose is respiration. The equatio.pdf                     Combustion of glucose is respiration. The equatio.pdf
Combustion of glucose is respiration. The equatio.pdf
 
in truss one...the forces in the member BC and DE have zero.in tru.pdf
in truss one...the forces in the member BC and DE have zero.in tru.pdfin truss one...the forces in the member BC and DE have zero.in tru.pdf
in truss one...the forces in the member BC and DE have zero.in tru.pdf
 
iam giving you entire process of  forensc duplication;the response.pdf
iam giving you entire process of  forensc duplication;the response.pdfiam giving you entire process of  forensc duplication;the response.pdf
iam giving you entire process of  forensc duplication;the response.pdf
 
How does traffic analysis work Internet data packets have two parts.pdf
How does traffic analysis work Internet data packets have two parts.pdfHow does traffic analysis work Internet data packets have two parts.pdf
How does traffic analysis work Internet data packets have two parts.pdf
 

Recently uploaded

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 

Recently uploaded (20)

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 

publicclass Date {privatestatic String DATE_SEPARATOR = ;pr.pdf

  • 1. publicclass Date { privatestatic String DATE_SEPARATOR = "/"; privatestaticintDAYS_PER_WEEK = 7; //Attributes privateint day; privateint month; privateint year; /** * Default Constructor * Instantiates an object of type Date to 1/1/2000 */ public Date() { this.day = 1; this.month = 1; this.year = 2000; } /** * Constructs a new date object to represent the given date. * @param day * @param month * @param year */ public Date(int day, int month, int year) { if(isValid(day, month, year)) { this.day = day; this.month = month; this.year = year; } else System.out.println("Invalid Date."); } /** * Returns the day value of this date for example, for the date 2006/07/22, returns 22. * @return */ publicint getDay() {
  • 2. return day; } /** * Returns the month value of this date ,for example, for the date 2006/07/22, returns 7. * @return */ publicint getMonth() { return month; } /** * Returns the year value of this date, for example , the date 2006/07/22, returns 2006. * @return */ publicint getYear() { return year; } /** * @param day the day to set */ publicvoid setDay(int day) { this.day = day; } /** * @param month the month to set */ publicvoid setMonth(int month) { this.month = month; } /** * @param year the year to set */ publicvoid setYear(int year) { this.year = year; } /** * Returns true if the year of this date is a leap year.
  • 3. * A leap year occurs every 4 years , except for multiples of 100 that are not multiples of 400. * For example, 1956,1844,1600,and 2000 are leap years, but 1983,2002,1700,and 1900 are not. * @return */ publicboolean isLeapYear(){ if(((this.year % 400) == 0) || (((this.year % 4) == 0) && ((this.year % 100) != 0))) returntrue; else returnfalse; } /** * Checks if the date is valid * @param day * @param month * @param year * @return */ publicboolean isValid(int day, int month, int year) { if((month < 1) || (12 < month)) returnfalse; else { if(((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12)) && ((day < 1) || (31 < day))) returnfalse; elseif(((month == 4) || (month == 6) || (month == 9) || (month == 11)) && ((day < 1) || (30 < day))) returnfalse; elseif(month == 2) { if(isLeapYear() && ((day < 1) || (29 < day))) returnfalse; elseif((day < 1) || (28 < day)) returnfalse; } } returntrue; }
  • 4. /** * Returns the maximum number of days in a month * @return */ publicint maxMonthDays() { if(this.month == 2) { if(isLeapYear()) return 29; else return 28; } elseif((this.month == 1) || (this.month == 3) || (this.month == 5) || (this.month == 7) || (this.month == 8) || (this.month == 10) || (this.month == 12)) return 31; else return 30; } /** * Checks if this dat is same as other date * @param other * @return */ publicboolean isEqual(Date other) { if((this.day == other.day) && (this.month == other.month) && (this.year == other.year)) returntrue; else returnfalse; } /** * Moves this Date object forward in time by the given number of days . * @param days */ publicvoid addDays(int days) { while(days != 0){ int maxDays = maxMonthDays(); if((maxDays - this.day) >= days) { this.day += days;
  • 5. days = 0; } else{ days -= (maxDays - this.day); this.day = 0; if(month == 12) { this.month = 1; this.year += 1; } else this.month += 1; } } } /** * Moves this date object forward in time by the given amount of seven day weeks * @param weeks */ publicvoid addWeeks(int weeks) { addDays(weeks * DAYS_PER_WEEK); } /** * Returns the number of days that this Date must be adjusted to make it equal to the given other Date. * @param other * @return */ publicint daysTo(Date other) { Date temp = new Date(this.day, this.month, this.year); if(temp.isEqual(other)) return 0; else{ int noOfDays = 0; do { if((temp.year == other.year) && (temp.month == other.month)) { noOfDays += (other.day - temp.day); temp.day = other.day;
  • 6. } else{ int maxDays = temp.maxMonthDays(); noOfDays += (maxDays - temp.day); temp.day = 0; if(temp.month == 12) { temp.month = 1; temp.year += 1; } else temp.month += 1; } } while(!temp.isEqual(other)); return noOfDays; } } /** * Returns a String representation of this date in year/month/day order, such as "2006/07/22" */ @Override public String toString() { returnthis.day + DATE_SEPARATOR + this.month + DATE_SEPARATOR + this.year; } } publicclass Driver { publicstaticvoid main(String[] args) { Date d1 = new Date(29, 1, 2016); Date d2 = new Date(29, 12, 2015); //Add 5 days to d1 System.out.println(" Add 5 days to " + d1 + " : "); d1.addDays(5); System.out.println(d1); //Add 5 days to d2 System.out.println(" Add 5 days to " + d2 + " : "); d2.addDays(5); System.out.println(d2);
  • 7. Date d3 = new Date(28, 8, 2016); //Add 1 week to d3 System.out.println(" Add 1 week to " + d3 + " : "); d3.addWeeks(1); System.out.println(d3); Date d4 = new Date(31, 8, 2016); Date d5 = new Date(1, 10, 2016); System.out.println(" The number of days that " + d4 + " must be adjusted to make it equal to " + d5 + " : " + d4.daysTo(d5) + " days."); } } SAMPLE OUTPUT : Add 5 days to 29/1/2016 : 3/2/2016 Add 5 days to 29/12/2015 : 3/1/2016 Add 1 week to 28/8/2016 : 4/9/2016 The number of days that 31/8/2016 must be adjusted to make it equal to 1/10/2016 : 31 days. Solution publicclass Date { privatestatic String DATE_SEPARATOR = "/"; privatestaticintDAYS_PER_WEEK = 7; //Attributes privateint day; privateint month; privateint year; /** * Default Constructor * Instantiates an object of type Date to 1/1/2000 */ public Date() { this.day = 1; this.month = 1;
  • 8. this.year = 2000; } /** * Constructs a new date object to represent the given date. * @param day * @param month * @param year */ public Date(int day, int month, int year) { if(isValid(day, month, year)) { this.day = day; this.month = month; this.year = year; } else System.out.println("Invalid Date."); } /** * Returns the day value of this date for example, for the date 2006/07/22, returns 22. * @return */ publicint getDay() { return day; } /** * Returns the month value of this date ,for example, for the date 2006/07/22, returns 7. * @return */ publicint getMonth() { return month; } /** * Returns the year value of this date, for example , the date 2006/07/22, returns 2006. * @return */ publicint getYear() { return year;
  • 9. } /** * @param day the day to set */ publicvoid setDay(int day) { this.day = day; } /** * @param month the month to set */ publicvoid setMonth(int month) { this.month = month; } /** * @param year the year to set */ publicvoid setYear(int year) { this.year = year; } /** * Returns true if the year of this date is a leap year. * A leap year occurs every 4 years , except for multiples of 100 that are not multiples of 400. * For example, 1956,1844,1600,and 2000 are leap years, but 1983,2002,1700,and 1900 are not. * @return */ publicboolean isLeapYear(){ if(((this.year % 400) == 0) || (((this.year % 4) == 0) && ((this.year % 100) != 0))) returntrue; else returnfalse; } /** * Checks if the date is valid * @param day * @param month * @param year
  • 10. * @return */ publicboolean isValid(int day, int month, int year) { if((month < 1) || (12 < month)) returnfalse; else { if(((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12)) && ((day < 1) || (31 < day))) returnfalse; elseif(((month == 4) || (month == 6) || (month == 9) || (month == 11)) && ((day < 1) || (30 < day))) returnfalse; elseif(month == 2) { if(isLeapYear() && ((day < 1) || (29 < day))) returnfalse; elseif((day < 1) || (28 < day)) returnfalse; } } returntrue; } /** * Returns the maximum number of days in a month * @return */ publicint maxMonthDays() { if(this.month == 2) { if(isLeapYear()) return 29; else return 28; } elseif((this.month == 1) || (this.month == 3) || (this.month == 5) || (this.month == 7) || (this.month == 8) || (this.month == 10) || (this.month == 12)) return 31; else return 30;
  • 11. } /** * Checks if this dat is same as other date * @param other * @return */ publicboolean isEqual(Date other) { if((this.day == other.day) && (this.month == other.month) && (this.year == other.year)) returntrue; else returnfalse; } /** * Moves this Date object forward in time by the given number of days . * @param days */ publicvoid addDays(int days) { while(days != 0){ int maxDays = maxMonthDays(); if((maxDays - this.day) >= days) { this.day += days; days = 0; } else{ days -= (maxDays - this.day); this.day = 0; if(month == 12) { this.month = 1; this.year += 1; } else this.month += 1; } } } /** * Moves this date object forward in time by the given amount of seven day weeks
  • 12. * @param weeks */ publicvoid addWeeks(int weeks) { addDays(weeks * DAYS_PER_WEEK); } /** * Returns the number of days that this Date must be adjusted to make it equal to the given other Date. * @param other * @return */ publicint daysTo(Date other) { Date temp = new Date(this.day, this.month, this.year); if(temp.isEqual(other)) return 0; else{ int noOfDays = 0; do { if((temp.year == other.year) && (temp.month == other.month)) { noOfDays += (other.day - temp.day); temp.day = other.day; } else{ int maxDays = temp.maxMonthDays(); noOfDays += (maxDays - temp.day); temp.day = 0; if(temp.month == 12) { temp.month = 1; temp.year += 1; } else temp.month += 1; } } while(!temp.isEqual(other)); return noOfDays; }
  • 13. } /** * Returns a String representation of this date in year/month/day order, such as "2006/07/22" */ @Override public String toString() { returnthis.day + DATE_SEPARATOR + this.month + DATE_SEPARATOR + this.year; } } publicclass Driver { publicstaticvoid main(String[] args) { Date d1 = new Date(29, 1, 2016); Date d2 = new Date(29, 12, 2015); //Add 5 days to d1 System.out.println(" Add 5 days to " + d1 + " : "); d1.addDays(5); System.out.println(d1); //Add 5 days to d2 System.out.println(" Add 5 days to " + d2 + " : "); d2.addDays(5); System.out.println(d2); Date d3 = new Date(28, 8, 2016); //Add 1 week to d3 System.out.println(" Add 1 week to " + d3 + " : "); d3.addWeeks(1); System.out.println(d3); Date d4 = new Date(31, 8, 2016); Date d5 = new Date(1, 10, 2016); System.out.println(" The number of days that " + d4 + " must be adjusted to make it equal to " + d5 + " : " + d4.daysTo(d5) + " days."); } } SAMPLE OUTPUT : Add 5 days to 29/1/2016 : 3/2/2016 Add 5 days to 29/12/2015 :
  • 14. 3/1/2016 Add 1 week to 28/8/2016 : 4/9/2016 The number of days that 31/8/2016 must be adjusted to make it equal to 1/10/2016 : 31 days.