Computer Science, asked by rudrakshadutta75, 9 months ago

Design a class Date which can create Date type objects. Instance Variables: int dd : to store the day int mm : to store the month int yy : to store the year Member Methods: i. Date ( ) – default constructor to initialize the instance variables to default values. ii. Date (int d, int m, int y) : parameterized constructor to initialize as d =dd, m =mm, y =yy. iii. boolean isLeap ( ) : to check whether the year is a leap year or not. If leap year returns true otherwise returns false. iv. void print_date ( ) : to display the date as “dd/mm/yyyy” format and also given year is “Leap year” or “Not a Leap year”. Write a main method to create an object and invoke the above methods.

Answers

Answered by ramabisa
10

Answer:

Explanation:

This is the JAVA program for your question:

import java.util.Scanner;

class Date

{

int dd, mm, yy;

Date()

{

dd = 0;

mm = 0;

}

Date(int d, int m, int y)

{

dd = d;

mm = m;

yy = y;

}

boolean isLeap()

{

if(yy%2==0)

System.out.println("True");

else

System.out.println("False");

}

void print_date()

{

System.out.println(dd+"/"+mm+"/"yy)

}

if(yy%2==0)

{

System.out.println("Leap year");

}

else

{

System.out.println("Not a leap year")

public void main()

{

Scanner in = new Scanner(System.in)l

System.out.println("Enter a date of your choice");

dd = in.nextInt();

System.out.println("Enter a month of your choice");

mm = in.nextInt();

System.out.println("Enter a year of your choice");

yy = in.nextInt();

Date d = new Date(dd,mm,yy)

d.isLeap();

d.print_date();

}

}

}

Hope this helps you!!

Answered by prasunbanerjee1997
1

Answer:

import java.util.Scanner;

public class Date

{

int dd, mm, yy;

Date()

{

dd = 0;

mm = 0;

}

Date(int d, int m, int y)

{

dd = d;

mm = m;

yy = y;

}

boolean isLeap()

{

if(yy%2==0)

return true;

else

return false;

}

void print_date()

{

System.out.println(dd+"/"+mm+"/"+yy);

if(yy%2==0)

{

System.out.println("Leap year");

}

else

{

System.out.println("Not a leap year");

}

}

public static void main(String[] args)

{

Scanner in = new Scanner(System.in);

System.out.println("Enter a date of your choice");

int a = in.nextInt();

System.out.println("Enter a month of your choice");

int m = in.nextInt();

System.out.println("Enter a year of your choice");

int y = in.nextInt();

Date d = new Date(a,m,y);

d.isLeap();

d.print_date();

}

}

Explanation:

Similar questions