Java logic problem

Asked

Viewed 30 times

1

Good evening my dear I’m having a problem with the logic of this program which is a clock:

private void updateDisplay() {

        if(hours.getValue()==0 && (periodo=="am" || periodo =="AM")){
              hours.setValue(hours.getValue()+1);
              periodo = "am";
        }
        else{
            if(hours.getValue()==12 && (periodo=="am" || periodo =="AM")){
                periodo="pm";
            }
            else{

            }
        }
        if(hours.getValue()==0 && (periodo=="pm" || periodo =="PM")){
                hours.setValue(hours.getValue()+1);
                periodo="pm";
        }
        else{

        }


         displayString = hours.getDisplayValue() + ":" + 
                    minutes.getDisplayValue() + " " + periodo; 
    }

}

All functions are perfect really is just the part of logic that’s complicated. And I want to limit between 1-12 so when it reaches the limit that is 11:59 pm it turns 12:00 am and when it arrives 11:59 am it turns 12:00 pm.

  • When that code is called?

  • Every time for clock update

  • here is the method:

  • I edited the post and put the method that is updated every minute when calling the method to jump minute

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.