Enter date of announcement, number of days given to complete the project and find the date of submission of project.
/* Enter date of announcement, number of days given to complete the project and
* find the date of submission of project.
*/
import java.util.*;
class DateOfSubmission
{
public static void main (String args[])throws InputMismatchException
{
Scanner scan = new Scanner(System.in);
int dd, mm, yy, nod,i,tdays=0,m;
System.out.println("Enter the day, month and year of the date of
announcement of the project: ");
dd = scan.nextInt();
mm = scan.nextInt();
yy = scan.nextInt();
System.out.println("Enter the no of days given to complete the project: ");
nod = scan.nextInt();
int dom[] = {31,28,31,30,31,30,31,31,30,31,30,31};
//If it is a leap year, februrary should have 29 days.
if(yy%4 == 0)
dom[1] = 29;
//Add the days of the month
for(i=0; i< mm-1; i++)
tdays+=dom[i];
//Add the days of the current month
tdays+=dd;
//Add the number of days given to complete the project
tdays+=nod;
//Now convert the total calculated days to date
// If the days exceed the total number of days in a year
// Increment the year by one
if(yy%4 == 0){
if(tdays > 366){
tdays-=366;
yy++;
}
}else{
if(tdays > 365){
tdays-=365;
yy++;
}
}
if(yy%4 == 0)
dom[1] = 29;
else
dom[1] = 28;
m=0;
while(tdays>dom[m]){
tdays-=dom[m];
m++;
}
System.out.println("Date of submission: "+tdays+"/"+(m+1)+"/"+yy);
}//end of main
}//end of class
Have something to say? Log in to comment on this post.
0 comments