Sunday, 9 November 2014

To find the completion date of a scheduled project given starting date and number of working days

// To find the completion date of a scheduled project given starting date and
// number of working days
import java.util.* ;
class DateQ1_1995 {
static int isLeap(int y){
if((y%4==0 && y%100!=0)|| y%400==0) return 1;
return 0;
}
public static void main(String args []) throws Exception {
Scanner sc=new Scanner(System.in);
int daysOfMonth[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int i,dd,mm,yy,ww;
System.out.println("Project Start Date");
System.out.print("DAY:\t");
dd=sc.nextInt();
System.out.print("MONTH:\t");
mm=sc.nextInt();
System.out.print("YEAR:\t");
yy=sc.nextInt();
System.out.print("WORKING DAYS: ");
ww=sc.nextInt();
dd+=ww; // add working days to the day number
daysOfMonth[2]+=isLeap(yy); // check for days in February
while(dd>31){
dd-=daysOfMonth[mm]; // finds the day of the year
++mm; // update the month
if(mm>12){
yy++; // update year
mm=1; // start from the first month of new year
daysOfMonth[2]+=isLeap(yy);
}
}
System.out.println("\nOUTPUT :");
System.out.println("Project Completion Date");
System.out.println("DAY:\t"+dd);
System.out.println("MONTH:\t"+mm);
System.out.println("YEAR:\t"+yy);
} // end of main
} // end of class 

No comments:

Post a Comment