Need comments please public class ThisDate { boolean B1, B2, B3; private int Dy,
ID: 3665865 • Letter: N
Question
Need comments please
public class ThisDate
{
boolean B1, B2, B3;
private int Dy, Mnth, Yr;
public ThisDate(int Dy, int Mnth, int Yr)
{
super();
SetMnth(Mnth);
SetDy(Dy);
SetYr(Yr);
ValidChk();
}
public void ValidChk()
{
if(B1 == true && B2 == true && B3 == true)
{
System.out.println(" date is valid");
}
}
public int GetYr()
{
return Yr;
}
public void SetYr(int Yr)
{
if(Yr >= 0)
{
this.Yr = Yr;
B1 = true;
}
else
{
System.out.println(" year is not valid");
}
}
public int GetDy()
{
return Dy;
}
public void SetDy(int Dy)
{
if(GetMnth() == 2)
{
if(Dy >= 0 && Dy <= 29)
{
B2 = true;
}
else
{
System.out.println("date is not valid");
}
}
else if((Dy >= 1) && (Dy <= 31))
{
this.Dy = Dy;
B2 = true;
}
else
{
System.out.println(" you enterd day is not valid");
}
}
public int GetMnth()
{
return Mnth;
}
public void SetMnth(int Mnth)
{
if(Mnth<=12)
{
this.Mnth = Mnth;
B3 = true;
}
else
{
System.out.println(" your enterd month is not valid");
}
}
public boolean LeapYr(int Yr)
{
boolean LeapCk = false;
if(Yr % 400 == 0)
{
LeapCk = true;
}
else if (Yr % 100 == 0)
{
LeapCk = false;
}
else if(Yr % 4 == 0)
{
LeapCk = true;
}
else
{
LeapCk = false;
}
return LeapCk;
}
}
Explanation / Answer
/**
* @author Your Name
*
*/
public class ThisDate {
// true if the date, month and year is valid
boolean B1, B2, B3;
// to store date, month and year
private int Dy, Mnth, Yr;
/**
* construct the object with date, month and year
*
* @param Dy
* @param Mnth
* @param Yr
*/
public ThisDate(int Dy, int Mnth, int Yr) {
super();
SetMnth(Mnth);
SetDy(Dy);
SetYr(Yr);
ValidChk();
}
/**
* method to check weather the date, month and year is valid or not
*
*/
public void ValidChk() {
if (B1 == true && B2 == true && B3 == true) {
System.out.println(" date is valid");
}
}
/**
* method to return the year
*
* @return
*/
public int GetYr() {
return Yr;
}
/**
* method to set the year and also check weather it is valid or not
*
* @param Yr
*/
public void SetYr(int Yr) {
if (Yr >= 0) {
this.Yr = Yr;
B1 = true;
} else {
System.out.println(" year is not valid");
}
}
/**
*
* method to return the day
*
* @return
*/
public int GetDy() {
return Dy;
}
/**
* method to set the day and also check weather it is valid or not
*
* @param Dy
*/
public void SetDy(int Dy) {
if (GetMnth() == 2) {
if (Dy >= 0 && Dy <= 29) {
B2 = true;
} else {
System.out.println("date is not valid");
}
}
else if ((Dy >= 1) && (Dy <= 31)) {
this.Dy = Dy;
B2 = true;
}
else {
System.out.println(" you enterd day is not valid");
}
}
/**
* method to return the month
*
* @return
*/
public int GetMnth() {
return Mnth;
}
/**
* method to set the month and also check weather it is valid or not
*
* @param Mnth
*/
public void SetMnth(int Mnth) {
if (Mnth <= 12) {
this.Mnth = Mnth;
B3 = true;
} else {
System.out.println(" your enterd month is not valid");
}
}
/**
* method to check weather the given year is leap year or not
*
* @param Yr
* @return
*/
public boolean LeapYr(int Yr) {
boolean LeapCk = false;
if (Yr % 400 == 0) {
LeapCk = true;
} else if (Yr % 100 == 0) {
LeapCk = false;
} else if (Yr % 4 == 0) {
LeapCk = true;
} else {
LeapCk = false;
}
return LeapCk;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.