Results 1 to 5 of 5
  1. #1
    bs3ac is offline Member
    Join Date
    Oct 2009
    Posts
    10
    Rep Power
    0

    Default 24 hour clock to 12 hour clock project.

    Hi guys, i am working through a java book and have come across this challenge exercise where we are told to create a 24 hour clock which i have accomplished.

    They now have told us to change the 24 hour clock into a 12 hour clock which i have 90% completed but am having a problem with the am/pm string that is shown at the end of the clock display.

    Currently i have used if statements to do the following,

    public void timeTick()
    {
    minutes.increment();
    if(minutes.getValue() == 0) { // it just rolled over!
    hours = hours + 1;
    }
    if(hours > 12)
    {
    hours = hours -12;
    }
    updateDisplay();
    }


    This gets the value if its 13+ and subtracts 12 to get the 12hour clock result.

    The problem i am having is the following to display the am/pm

    I created the following method,

    private String updateDisplayTwo()
    {
    if(hours > 12)
    {
    amPm = "pm";
    }
    else
    {
    amPm = "am";
    }

    return amPm;
    }


    Now i know where the problem lies as the hours data is never going to be 13+ anymore because if it is then 12 is subtracted from it.

    What i was wondering is there anything within java that will 'show' when a method had been used and been activated. As i belive if i can tell when the 12> function is being used i can use that in another IF statement to show the pm string instead of the constant am (currently).

    Thanks in advance guys.

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Suppose you a boolean variable that can be accessed by both if statements. If this variable starts of with the value false, then you can use the first if to update it. The second if can then have a look at the same variable to see if the first if was used or not.

  3. #3
    gcampton Guest

    Default

    a extreeeeemely long if /else if would solve this.

    if (hours == 0) time is 12am
    else if (hours between 1-11) time is am
    else if (hours == 12) time is pm
    else if (hours between 13-23) time is pm and minus 12.
    else if (hours == 24) time is 12am

    in that order you won't get repeat assignments.
    remember army time both 0hundred hours and 24hundred hours is 12am, usually 0hundred is referred to as past tense, and 24hundred hours pre-tense.
    But most people disregard standard meanings and mix them up anyway... you can have 0:32:14 and 24:32:14 both are 12:32:14 am

    http://en.wikipedia.org/wiki/24-hour_clock

    Time-of-day notations beyond 24:00 (such as 24:01 or 25:59) are neither commonly used nor covered by any relevant standards. However, they have been observed occasionally in some special contexts in Japan and Hong Kong where business hours extend beyond midnight, such as broadcast-television production and with time-validation stamps on some European public transport systems, such as those used in Copenhagen, which may show, for example, 27:45 instead of 03:45.

    Most digital clocks and watches show times between 00:00 to 23:59. As a notable exception, the digital clocks of at least one European manufacturer of kitchen appliances show 24:00 for midnight, rather than the standard 00:00, with an example being Bosch Siemens microwaves.
    if you are doing this for assignment or for other to use then you should inlcude, at least up to 24:00:00 as some people are easily confused.
    Last edited by gcampton; 11-06-2009 at 04:43 PM.

  4. #4
    foram77 is offline Member
    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Default Re: 24 hour clock to 12 hour clock project.

    Hi, i am doing the same assignment for my uni this year please can i ask you for a help if you have done this assignment already can i get the proper code as i am stuck in various places please if you can mail me the actual coding on my email address which is [email address removed] i'll really appreciate that

    my assignment is due tomorrow please try an reply me back ASAP!
    Last edited by DarrylBurke; 01-08-2013 at 11:48 AM. Reason: Removed email address

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default Re: 24 hour clock to 12 hour clock project.

    Don't resurrect a very old thread; start your own thread and don't beg for code; that's cheating.

    kind regards,

    Jos

    ps. I'm closing this threaad.
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. computing hour & Salary
    By arshesander in forum New To Java
    Replies: 4
    Last Post: 08-07-2009, 10:17 PM
  2. HELP!! Assignment due in one hour!
    By murr0508 in forum New To Java
    Replies: 1
    Last Post: 02-26-2009, 09:31 PM
  3. Help needed for a 40 mark homework due in 1 hour .. plz
    By q8ysurgeon in forum New To Java
    Replies: 5
    Last Post: 01-09-2009, 05:07 PM
  4. [SOLVED] Very Simple 2-3 hour project $50
    By arbit3r in forum Jobs Offered
    Replies: 3
    Last Post: 08-05-2008, 03:20 AM
  5. Calculating per hour statistics
    By vipergt89 in forum New To Java
    Replies: 2
    Last Post: 05-01-2008, 06:25 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
  •