This is a Java Programming question: This assignment will use the following desc
ID: 3682702 • Letter: T
Question
This is a Java Programming question:
This assignment will use the following description to implement a Dialog class for the Leap Year Problem. You need to decompose this problem into 2 classes:
1.The Date.java class: Implements a public class Date that represents a date composed of a month , day, and a year.
You need to:
Declare three instance variables: month, day, and year as integers(5 points).
Date constructor which has three paramaters: month, day and year in order(10 points)
4 methods:
"daysIs()" which returns a day (5 points)
"monthIs()" which returns a month (5 points)
"yearIs()" which returns a year (5 points)
"isLeapYear()" is needed in the class Date. It has no parameter and returns a boolean. Write the method isLeapYear() knowing that a year is defined to be a leapyear it is a multiple of 4, and if it is is a multiple of 100, it must also be a multiple of 400. isLeapYear() thus decides when a year is a leap year. (see the discussion on "Hints for Assign5" to discover specific examples of a LeapYear)(20 points).
2.The DateJDialog.java class: which implements the GUI. Please use the Dialog boxes developed in the book in chapter2 in pages 99-100 in the code-listing 2-32 (NamesDialog.java) for input and output.
Remember that you will prompt the user using input dialog boxes to input (10 points):
a day;
a month;
a year.
Once the 3 variables are read, you will be able to create a date object of the class Date which has three parameters.(15 points)
Then you will use the dialog box to tell the user
Whether the year entered was a leapyear or not a leapyear.(25 points).The purpose of the Date.java that you will implement is to decide whether a year is a leap year. Here is a definition of when a year is considered a leap year :
year y1 is a leap year if it is multiple of 4.
year y1 is a leap year if it is a multiple of 100, it must be a multiple of 400.
Otherwise y1 is not a leap year.
Do not forget to compile the 2 java files. To verify that the DateJDialog.java works, in TextPad after you compile DateJDialog.java, Click on Tools, Click on "Run Java Application".
Explanation / Answer
1.
2.
import java.io.*;
import java.io.*;
class LeapYear
{
public static void main(String args[]) throws IOException
{
String n;
System.out.println(" Enter the Year: ");
BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));
n = ob.readLine();
int leap_year = Integer.parseInt(n);
if(leap_year % 4 == 0)
{
System.out.println(" This Year is Leap");
}
else
{
System.out.println(" This Year is not Leap");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.