// B39HV2 Software Engineering II // Unit 2 Exercise 2 // Conversion to Java import java.io.*; public class Alarm_clock { public Alarm_clock(int h, int m, int s) { hour = h; minute = m; second = s; normalise(); } public void tick() { second += 1; normalise(); if ( on==true && hour==alarm_h && minute==alarm_m) System.out.println("GET UP!!!"); } public void normalise() { minute += second / 60; hour += minute / 60; minute = minute%60; hour = hour %24; second = second%60; } public void show_time() { System.out.println(hour+":"+minute+":"+second); } public void set_alarm() { InputStreamReader istream = new InputStreamReader(System.in); BufferedReader keyboard = new BufferedReader(istream); System.out.println("Enter Alarm Time (24h)"); try{ alarm_h = Integer.parseInt(keyboard.readLine()); alarm_m = Integer.parseInt(keyboard.readLine()); on = true; } catch(Exception e) { System.err.println("you must enter an integer"); System.exit(0); } } private int hour, minute, second; private int alarm_h, alarm_m; private boolean on; };