Home » Java » java – Exception Handling task-Exceptionshub

java – Exception Handling task-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

Exercises :

Write a program that converts dates from numerical month/day/year format to normal
“month day, year” format (for example, 12/25/2000 corresponds to December 25, 2000).
You will define three exception classes, one called MonthException, another called
DayException, and a third called YearException. If the user enters anything other than a
legal month number (integers from 1 to 12), your program will throw and catch a
MonthException. Similarly, if the user enters anything other than a valid day number
(integers from 1 to either 28, 29, 30, or 31, depending on the month and year), then your
program will throw and catch a DayException. If the user enters a year that is not in the
range 1000 to 3000 (inclusive), then your program will throw and catch a YearException.

edit: my proplem is the throws exeption, i made super calss Exception with 3 sup calss dayexception,month exception,yearexception but when i make a throws exception in the exception constructor it does not work

edit : sorry for the post its my fisrt post and i did not know how the site work

public class Exception {
protected int day;
protected int month;
protected int year;
protected int date = year+month +day;

public Exception(int date) throws DayException {
    if (day>0) {
    }
    else {
     this.day = day;
     this.month = month;
     this.year = year;
    }
}
public int getmonth() {
    return month;
}
public int geatyear() {
    return year;
}
public void setmonth() {
    this.month = month;
}
public void setyear() {
    this.year = year;
}

}

How to&Answers: