Results 1 to 2 of 2
  1. #1
    MrMario is offline Member
    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    Default Alarm Clock Help

    I need to create an alarm clock, which requires a user to enter year, month, day, hour, minute and PM or AM.
    I need to create an calendar object with the time of the alarm and to check to see when the alarm will go off (today, tomorrow?) I also need to report back the time (hour and minutes)

    This is what I have so far:

    Thanks in advance!


    Java Code:
    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, "Sean \nListing 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 Object and to see when the alarm will go off
    			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));
    			
    			
    			
    			
    			// 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("http://3.bp.blogspot.com/-PsxZ4-C4Jss/UOSc0sDFpPI/AAAAAAAABLQ/nZSkY95cL48/s320/goodbye.jpg"));
    		JOptionPane.showMessageDialog(null, "Thanks for using the Alarm Clock Program!", "Good Bye", JOptionPane.INFORMATION_MESSAGE, icon);
    	}
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

Similar Threads

  1. Android alarm set with databse
    By sibuns in forum Android
    Replies: 0
    Last Post: 05-23-2013, 11:49 AM
  2. Alarm Clock
    By paul1024 in forum New To Java
    Replies: 1
    Last Post: 05-31-2011, 01:24 AM
  3. Replies: 2
    Last Post: 10-29-2008, 11:22 PM
  4. Alarm Clock - Simple Question
    By JDCAce in forum Advanced Java
    Replies: 6
    Last Post: 10-19-2008, 10:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •