Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BusinessDate {
- public BusinessDate(int pDay, int pMonth, int pYear) {
- setMonth(pMonth);
- setYear(pYear);
- setDay(pDay);
- }
- private int day = 0;
- private int month = 0;
- private int year = 0;
- public int getDay() {
- return day;
- }
- public int getMonth() {
- return month;
- }
- public int getYear() {
- return year;
- }
- public void setMonth(int month) {
- if(month < 1){
- this.month = 1;
- }
- if(month > 12){
- this.month = 12;
- }
- else
- this.month = month;
- }
- public void setYear(int year) {
- if(year < 0){
- this.year = 0;
- }
- if(year > 3000){
- this.year = 3000;
- }
- else
- this.year = year;
- }
- public void setDay(int day) {
- if(day < 1)
- this.day = 1;
- else {
- switch(month){
- case 1:
- if(day > 31)
- this.day = 31;
- else
- this.day = day;
- break;
- case 2:
- if(isLeapYear(day) == true)
- this.day = 29;
- else if (day > 30 && isLeapYear(day) == true)
- this.day = 29;
- else if (day > 29 && isLeapYear(day) == false)
- this.day = 28;
- break;
- case 3:
- if(day >31)
- this.day = 31;
- else
- this.day = day;
- break;
- case 4:
- if (day < 30)
- this.day = 30;
- else
- this.day = day;
- break;
- case 5:
- if (day > 31)
- this.day = 31;
- else
- this.day = day;
- break;
- case 6:
- if(day > 30)
- this.day = 30;
- else
- this.day = day;
- break;
- case 7:
- if (day > 31)
- this.day = 31;
- else
- this.day = day;
- break;
- case 8:
- if (day > 31)
- this.day = 31;
- else
- this.day = day;
- break;
- case 9:
- if (day > 30)
- this.day = 30;
- else
- this.day = day;
- break;
- case 10:
- if (day > 31)
- this.day = 31;
- else
- this.day = day;
- break;
- case 11:
- if(day > 30)
- this.day = 30;
- else
- this.day = day;
- break;
- case 12:
- if(day > 31)
- this.day = 31;
- else
- this.day = day;
- default:
- this.day = day;
- }
- }
- }
- public boolean isLeapYear(int year) {
- if (year % 4 != 0) {
- return false;
- } else if (year % 400 == 0) {
- return true;
- } else if (year % 100 == 0) {
- return false;
- } else {
- return true;
- }
- }
- public void print() {
- System.out.println(day + "." + month + "." + year);
- }
- }
Add Comment
Please, Sign In to add comment