Results 1 to 2 of 2
  1. #1
    sjud9227 is offline Member
    Join Date
    Jul 2014
    Rep Power

    Default Help with "Alarm clock" code

    Hello, thanks for any help, I am SUPER new and I'm having a hard time with this. I post the question and then my code. I'm having a hard time trying to figure out how to get the am / pm working. Also, can you tell me what's wrong with my if and else statements.

    Here is the assignment:
    Many people keep time using a 24-hour clock (11 is 11am and 23 is 11pm, 0 is midnight). If it is currently 13 and you set your alarm to go off in 50 hours, then it will go off at 3 PM. Write a Java program to solve the general version of the above problem. Ask the user for the time now (in hours), and then ask for the number of hours to wait for the alarm. Your program should output what the time would be on the clock (in 12- hour AM/PM format) when the alarm goes off.

    Here is my code so far:
    Java Code:
    import java.util.Scanner;
    public class Alarm
        public static void main(String[] args)
        int currentTime;
        int waitingTime;
        int hours;
        int timeOfDay;
        Scanner scan = new Scanner(;
        System.out.print("Please enter the current time (in hours): ");
        currentTime = scan.nextInt();
        System.out.print("Please enter the number of hours to wait for the alarm: ");
        waitingTime = scan.nextInt();
        hours = (currentTime + waitingTime);
        timeOfDay = (hours % 24);
        if (currentTime > 12)
        System.out.println("The alarm would go off at: " + timeOfDay);
    Last edited by JosAH; 07-10-2014 at 08:22 AM. Reason: added [code] ... [/code] tags

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: Help with "Alarm clock" code

    Well, you might need to tell us what the problem is with it...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 0
    Last Post: 12-07-2012, 08:29 AM
  2. Replies: 3
    Last Post: 10-30-2012, 03:06 PM
  3. Replies: 5
    Last Post: 04-29-2012, 07:18 AM
  4. Program skips "If" code and goes straight to "Else"
    By Logik22 in forum New To Java
    Replies: 12
    Last Post: 01-21-2012, 05:40 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

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