第1个回答 推荐于2017-11-26
public class MyTime {
private int hour; //时
private int minute; //分
private int second; //秒
public MyTime(){
}
public MyTime(int hour,int minute,int second){
this.hour = hour;
this.minute = minute;
this.second = second;
}
public void diaplay(MyTime time){
System.out.println(time.getHour()+":"+time.getMinute()+":"+time.getSecond());
}
public int getHour() {
return hour;
}
public void setHour(int hour) {
this.hour = hour;
}
public int getMinute() {
return minute;
}
public void setMinute(int minute) {
this.minute = minute;
}
public int getSecond() {
return second;
}
public void setSecond(int second) {
this.second = second;
}
public void addSecond(int sec){
this.second = second + sec;
}
public void addMinute(int min){
this.minute = minute + min;
}
public void addHour(int hou){
this.hour = hour + hou;
}
public void subSecond(int sec){
this.second = second - sec;
}
public void subMinute(int min){
this.minute = minute - min;
}
public void subHour(int hou){
this.hour = hour - hou;
}
/**
* main:(这里用一句话描述这个方法的作用).
*
* @param args
*/
public static void main(String[] args) {
MyTime time = new MyTime(12,14,15);
time.diaplay(time);
time.addHour(1);
time.addMinute(1);
time.addSecond(1);
time.subHour(1);
time.subMinute(1);
time.subSecond(1);
time.diaplay(time);
}
}
记得采纳哦!本回答被提问者采纳