Im working on the following question:
A 24-hour clock is a 4-digit number, where the leftmost two digits indicate the hour (from 0 to 23, inclusive) and the rightmost two digits indicate the minutes (from 0 to 59, incl.). For example, 2130 expresses half past eight in the evening. Write a class Time for encapsulation time. It must have the following instance methods:
get the time from the keyboard (comes in the form of a four-digit number, for example 2130). You can assume that the number represents the actual time.
My code so far:
import java.util.Scanner; import java.io.*; class Time { private double hour, min; Scanner scanner = new Scanner(System.in); Time() { hour = 00; min = 00; } Time(double h, double m) { hour = h; min = m; } void get() { System.out.println("Please enter a time in 24 hour format: "); double x = scanner.nextDouble(); hour = x / 100; min = x % 100; System.out.println("The time is " + hour + ":" + min); } public String toString() { return "Time: " + hour + min; } }
The problem is how to divide the 4-digit input by hour and minute, all the tips, the tips are appreciated.
Bll27 source share