I'm very new to Java, and have no idea on what to do to get the return of how many hours and minutes are left till the alarm sounds from what the user input.
This is the code I have now:
// Sean Kilbane import java.net.MalformedURLException; import java.net.URL; import java.util.Calendar; import javax.swing.ImageIcon; import javax.swing.JOptionPane; public class AlarmClock { public static void main(String[] args) throws MalformedURLException { int retry = JOptionPane.YES_NO_OPTION; JOptionPane.showMessageDialog(null, "Listing 4.14 P. 163\nAlarm Clock", "Information", JOptionPane.INFORMATION_MESSAGE); while (retry == JOptionPane.YES_NO_OPTION) { // Asking user for time int hours = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter the hours \nExample: 8")); int minutes = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter the minutes \nExample: 36")); String prefix = JOptionPane.showInputDialog(null, "Enter AM or PM"); // Asking the user for date int year = Integer.parseInt(JOptionPane.showInputDialog(null, "Pelase enter the year \nExample: 1992")); int month = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter the month \nExample: 02")); int day = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter the date \nExample: 26")); Calendar calendar = Calendar.getInstance(); calendar.set(year, month, day, hours, minutes); //System.out.println(calendar.get(Calendar.DAY_OF_MONTH + Calendar.DAY_OF_YEAR + Calendar.MONTH)); long time = System.currentTimeMillis(); long totalSeconds = time / 1000; long currentSecond = totalSeconds % 60; long totalMinutes = totalSeconds / 60; long currentMinute = totalMinutes % 60; long totalHours = totalMinutes / 60; long currentHour = totalHours % 24; System.out.println(currentHour); // Reporting the time left till the alarm // Asking the user if they like to set up another alarm retry = JOptionPane.showConfirmDialog(null, "Would you like to set another alarm?", "Question", JOptionPane.YES_NO_OPTION); } // Good Bye Message final ImageIcon icon = new ImageIcon(new URL("URL IS HERE")); JOptionPane.showMessageDialog(null, "Thanks for using the Alarm Clock Program!", "Good Bye", JOptionPane.INFORMATION_MESSAGE, icon); } }
This is what the requirements left I need. Any help is grateful!
• Create a Calendar object with the time of the alarm.
• Check to see if the alarm will go off today or tomorrow or another day, or when? Use the Calendar.Field Constants. Calculate how many hours and minutes will elapse until the alarm sounds.
• Report the time to the alarm sounding in hours and minutes.