Question

So I have this method that returns the time when a tv-show ends(e.g.: 21:15),but when the hour or minute is under 10 I need the method to return something like this : 21:05.

I tried like this, but because msg1 and msg2 are type String they can't return my int, if the elses occur.

What can I do? Helpfull Info: Im in my first year of Computer Engineering.

public static final int ZERO = 0;

 public String endsWhen(){
        String msg1="";
        String msg2="";

        if(fhour<10)
            msg1=ZERO + getFHour();
        else
            msg1=getFHour();  //error here

        if(fmin<10)
            msg2=ZERO+getFMin;
        else
            msg2=getFMin;    //error here

        return  msg1 + ":" + msg2;
    }
Was it helpful?

Solution

You cannot assign an int primitive to a string. assuming your getFHour() and getFMin() returns int. try:

            msg1+=getFHour();  

             msg2+=getFMin;    

OR, you can also convert an int to a string with Integer.toString() method.

           msg1=Integer.toString(getFHour());  

             msg2=Integer.toString(getFMin);  

However you should be using SimpledateFormater to format Dates and Time

OTHER TIPS

Try using a date formatter to format the time when the TV show starts.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top