I am creating a bunch of methods and constructors for a digital clock, and I am trying to make one where the user inputs everything in but the program is not allowing me to ask for user input.
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;
}
}
}
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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.