Hej stworzyłam klasę w której definiuję day month i year oraz zakres. W pliku MyDateMain.java mam za pomocą displayDate wyświetlić pola z uwzględnieniem zer nieznaczących oddzielone znakiem "/", np 21/03/2051.
MyDate.java
package src;
public class MyDate {
private int month;
private int day;
private int year;
public MyDate() {
this.month = month;
this.day = day;
this.year = year;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
if(Checkmonth(month))
this.month = month;
}
public int getDay() {
return day;
}
public void setDay(int day) {
if(Checkday(day))
this.day = day;
}
public int getYear() {
return year;
}
public void setYear(int year) {
if(Checkyear(year))
this.year = year;
}
private boolean Checkmonth(int month){
return(0 <= month) && (month <= 12);
}
private boolean Checkday(int day){
return(0 <= day) && (day <= 31);
}
private boolean Checkyear(int year){
return(1990 <= year) && (year <= 2050);
}
}
MyDateMain.java
package src;
public class MyDateMain {
public static void main(String[] args) {
MyDate today = new MyDate();
System.out.println(today.getDay() + "/" + today.getMonth() + "/" + today.getYear());
}
}
w tej chwili po uruchomieniu wyświetla: 0/0/0