FUTURE DATE | ISC COMPUTER 2024 | survnor.blogspot.com
Write a program to input a date in the format dd(day
number), mm(month number), yyyy(year number). Input day(no. of days) and print
the future date after the given days. The output of the program should be in
the format dd/mm/yyyy with suitable message.
Example:- Input:- dd=07, mm=04, yyyy=2022, days=10
Output:- Future date=17/04/2022
ALGORITHM
STEP 1:- Start.
STEP2:- Declare futuredate as a class.
Declare and initialize suitable variables such as DD, MM, YYYY, days and countß0.
STEP 3:- Initialize array of mont[] with
values 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.
STEP 4:- Now declare input method() with
return type void. Input values of DD, MM, YYYY and days. Now close input
method().
STEP 5:- Declare calculate() as a method with
return type void. Check for leap year as if YYYY%4==0 then store 29 in month[2]
otherwise store 28.
STEP 6:- Repeat step 7 to step 12 while
count<days.
STEP 7:- Add 1 to DD and add 1 to count.
STEP 8:- Check if month(MM>month[MM])
i.e., number of days of current month. Then go to step 9 else go to step 10.
STEP 9:- Assign 1 to DD and add 1 to MM.
STEP
10:- Check if mm
greater than 12 then go to step 11.
STEP
11:- Assign to mm and
1 to YYYY.
STEP
12:- Check for a
leap year as if YYYY not 4==, then store 29 in month[2] otherwise store .
STEP
13:- Print the
value of dd, mm, yyyy as the future date. Now close calculate().
STEP
14:- Declare main()
function. Create object ob of class futuredate. Now call the input() and
calculate() through object ob within main function.
STEP
15:- Now close main
function() and close class future date.
STEP
16:- Stop.
SOURCE CODE
import
java.util.*;
class
futuredate
int dd,mm,yyyy,days,count=0;
int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
Scanner sc=new Scanner(System.in);
void input(){
System.out.println("INPUT A
DAY,MONTH,YEAR IN A NUMBER");
dd=sc.nextInt();
mm=sc.nextInt();
yyyy=sc.nextInt();
System.out.println("ENTER NO. OF
DAYS AFTER WHICH NEW DATE IS TO BE FOUND:");
days=sc.nextInt();}
void calculate(){
if(yyyy%4==0)
month[2]=29;
else
month[2]=28;while(count<days){
dd++;
count++;
if(dd>month[mm]){
dd=1;
mm++;}{
if(mm>12)
mm=1;
yyyy++;
if(yyyy%4==0)
month[2]=29;
else
month[2]=28;}}
System.out.println("FUTURE
DATE:"+dd+"/"+mm+"/"+yyyy);}
public static void main(){
futuredate ob=new futuredate();
ob.input();ob.calculate();}}
VARIABLE DESCRIPTION
S.L.No. |
Name |
Data Type |
Description |
1 |
dd |
int |
To input day number . |
2 |
mm |
int |
To input month number. |
3 |
yyyy |
int |
To input year number. |
4 |
days |
int |
To input number of days. |
5 |
count |
int |
To use a counter upto days. |
6 |
Month[] |
Int |
To store the no. of days of each
month. |
INPUT AND
OUTPUT