java程序设计 定义一个时钟类,要求如下1,创建新对象时默认0时0分0秒。 2,设置时钟为指定的时间。3,编写
发布网友
发布时间:2022-04-29 04:24
我来回答
共1个回答
热心网友
时间:2023-10-11 08:04
import java.util.Calendar;
public class Clock {
private int hour, mintue, second;
public Clock(){
this(0, 0, 0);
}
public Clock(int hour, int minute, int second){
this.hour = hour;
this.mintue = minute;
this.second = second;
}
public void incsecond(){
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR, hour);
cal.set(Calendar.MINUTE, mintue);
cal.set(Calendar.SECOND, second);
cal.add(Calendar.SECOND, 1);
this.hour = cal.get(Calendar.HOUR);
this.mintue = cal.get(Calendar.MINUTE);
this.second = cal.get(Calendar.SECOND);
}
public String toString(){
return hour + ":" +mintue + ":" + second;
}
public void setHour(int hour) {
this.hour = hour;
}
public void setMintue(int mintue) {
this.mintue = mintue;
}
public void setSecond(int second) {
this.second = second;
}
public static void main(String[] args) {
}
}
热心网友
时间:2023-10-11 08:04
import java.util.Calendar;
public class Clock {
private int hour, mintue, second;
public Clock(){
this(0, 0, 0);
}
public Clock(int hour, int minute, int second){
this.hour = hour;
this.mintue = minute;
this.second = second;
}
public void incsecond(){
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR, hour);
cal.set(Calendar.MINUTE, mintue);
cal.set(Calendar.SECOND, second);
cal.add(Calendar.SECOND, 1);
this.hour = cal.get(Calendar.HOUR);
this.mintue = cal.get(Calendar.MINUTE);
this.second = cal.get(Calendar.SECOND);
}
public String toString(){
return hour + ":" +mintue + ":" + second;
}
public void setHour(int hour) {
this.hour = hour;
}
public void setMintue(int mintue) {
this.mintue = mintue;
}
public void setSecond(int second) {
this.second = second;
}
public static void main(String[] args) {
}
}