x. Solution import java.io.*; public class Scheduler { private int hours, minute
ID: 3609346 • Letter: X
Question
x.Explanation / Answer
import java.io.*; public class Scheduler { private int hours, minutes; public Scheduler() { setTime(0, 0); } public Scheduler(int hour, int min) { setTime(hour, min); } public int getHour() { return hours; } public int getMinute() { return minutes; } private void setTime(int hour, int min) { hours = hour; minutes = min; } private void normalize() { while(minutes >=60) { minutes -= 60; hours++; } while(hours >=24) { hours -= 24; } } public void addTime(Scheduler addThis) { hours +=addThis.getHour(); minutes +=addThis.getMinute(); normalize(); } public void addMinutes(int min) { minutes += min; normalize(); } public void roundTime(int multipleOfFifteen) { addMinutes(multipleOfFifteen*15); normalize(); while(minutes%15 !=0) minutes++; normalize(); } public String toString() { StringBuilder toReturn =new StringBuilder(); toReturn.append(hours); toReturn.append(":"); toReturn.append(minutes); if(minutes == 0) toReturn.append("0"); returntoReturn.toString(); } public static void main(String[] args) throwsIOException { BufferedReader in = newBufferedReader(new InputStreamReader(System.in)); System.out.print("Entergame start in 24-hr format: "); String input =in.readLine(); String[] splitString =input.split(":"); Scheduler gametime = newScheduler(Integer.parseInt(splitString[0]),Integer.parseInt(splitString[1])); System.out.print("Entergame length (in hrs and minutes): "); input =in.readLine(); splitString =input.split(":"); Scheduler gameLength =new Scheduler(Integer.parseInt(splitString[0]),Integer.parseInt(splitString[1])); gametime.addTime(gameLength); System.out.println("Thegame is expected to end at: " + gametime.toString()); System.out.print("Enterhow many minutes the game overran(mins): "); gametime.addMinutes(Integer.parseInt(in.readLine())); System.out.println("Thegame should now stop at: " + gametime.toString()); gametime.roundTime(3); System.out.println("Thenext football match should happen at " + gametime.toString()); } } This works. However, you will need to change the input methods inmain to meet your criterion (I never learned to use Dialogs). Also,I am unsure of what you needed for roundTime(int), so I just madeit get the next game time.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.