package time;
public class Time1 {
protected int hour;
protected int second;
protected int minute;
//sazande bedone parametr
Time1() {
hour = minute = second = 0;
}
//sazande ba 3 parametr
//call sethour,setminute,set second
Time1(int hour, int minute, int second) {
setHour(hour);
setMinute(minute);
setSecond(second);
}
//sazande ba yek class
Time1(Time1 t) {
this.hour = t.hour;
this.minute = t.minute;
this.second = t.second;
}
//set hour
//hour 0 to 23
public void setHour(int hour) {
this.hour = (hour >= 0 && hour <= 23) ? hour : 0;
}
//set minute
//minute 0 to 59
public void setMinute(int minute) {
this.minute = (minute >= 0 && minute <= 59) ? minute : 0;
}
//set second
//second 0 to 59
public void setSecond(int second) {
this.second = (second >= 0 && second <= 59) ? second : 0;
}
//get hour
public int getHour(){
return this.hour;
}
//get minute
public int getMinute(){
return this.minute;
}
//get hour
public int getSecond(){
return this.second;
}
//toString overload
public String toString(){
return this.hour+":"+this.minute+":"+this.second;
}
}
//class farzand
package time;
public class Time2 extends Time1 {
//tarife fild
private int mili;
//sazande bedon parametr
Time2() {
mili = 0;
}
//sazande ba 4 parametr
//call super for pedar
//call setMili
Time2(int hour, int minute, int second, int mili) {
super(hour, minute, second);
setMili(mili);
}
//sazande ba yek class
Time2(Time2 t) {
super(t);
this.mili = t.mili;
}
//setMili
//mili 0 to 999
public void setMili(int mili) {
this.mili = (mili >= 0 && mili <= 999) ? mili : 0;
}
//getMili
public int getMili() {
return this.mili;
}
//toString
//super for pedar
public String toString() {
return super.toString() + ":" + this.mili;
}
}
:: موضوعات مرتبط:
برنامه سازی پیشرفته ,
,
:: برچسبها:
برنامه ,
کلاس ,
Time ,
:: بازدید از این مطلب : 351
|
امتیاز مطلب : 0
|
تعداد امتیازدهندگان : 0
|
مجموع امتیاز : 0