我正在为数字时钟创建一堆方法和构造函数,我正在尝试创建一个用户输入所有内容的方法,但程序不允许我请求用户输入。
import java.util.Scanner;
import java.util.Calendar;
public class DigitalClock {
Calendar calendar = Calendar.getInstance();
int hour = 0;
int minute = 0;
boolean am = true;
public DigitalClock() {
hour = 12;
minute = 0;
am = true;
}
public void setTime() {
hour = input.nextInt();
minute = input.nextInt();
}
public void getHour() {
hour = calendar.get(Calendar.HOUR_OF_DAY);
}
public void getMinute() {
minute = calendar.get(Calendar.MINUTE);
}
public void isMorning() {
if(hour > 12){
am = false;
}else{
am = true;
}
}
}
答案 0 :(得分:0)
Scanner object is not used. Main method is missing as well.
Scanner input = new Scanner(System.in); needs to be added. Add a println to ask for inputs.
example:
Scanner input= new Scanner(System.in); // Read from System.in
System.out.println("Enter the Hour: ");
hour = input.nextInt(); // Scans the input as an int.
input.close();