• Register
0 votes
87 views

Problem :

I have following question 
complete the method definition to output the hours given minutes. output for sample program: 3.5
6.9k points

2 Answers

0 votes

Solution :

One can also use the TimeUnit class

One could define as following

private static final String FORMAT = "%02d:%02d:%02d";
Also can have a method like following:

public static String parseDateTime(long milliseconds) {
      return String.format(FORMAT,
              TimeUnit.MILLISECONDS.toHours(milliseconds),
              TimeUnit.MILLISECONDS.toMinutes(milliseconds) - TimeUnit.HOURS.toMinutes(
              TimeUnit.MILLISECONDS.toHours(milliseconds)),
              TimeUnit.MILLISECONDS.toSeconds(milliseconds) - TimeUnit.MINUTES.toSeconds(
              TimeUnit.MILLISECONDS.toMinutes(milliseconds)));
   }
36.1k points
0 votes

Solution:

Follow the below program i hope you will slove this problem

Code:

/*
Challenge 3.2.2: Basic method call.

Complete the method definition to output the hours given minutes. Output for sample program: 
3.5
*/
public class HourToMinConv {
    public void outputMinutesAsHours(double origMinutes) {

    double minutesInHour = 60.0;
        System.out.print(origMinutes / minutesInHour);
    }

    public static void main (String [] args) {
        HourToMinConv timeConv = new HourToMinConv();
        // test by running with 210.0, 3600.0, and 0.0.
        timeConv.outputMinutesAsHours(210.0);
        System.out.println("");
   }
}

 

15.3k points

Related questions

1 vote
1 answer 87 views
87 views
Problem : I am trying to find solution for following error replace any space ' ' by '_' in 2-character string passcode. sample output for the given program:
asked Nov 11, 2019 peterlaw 6.9k points
0 votes
1 answer 70 views
70 views
Problem : I am unable to understand what am I missing here: Sort my_short_names in reverse alphabetic order. The sample output from the given program as below : ['Tody', 'Samy', 'Joey', 'Jany', 'Anny'] Below is my code for your reference : my_short_names = ['Jany', 'Samy', 'Anny', 'Joey', 'Tody'] my_short_names.sort() print(my_short_names)
asked Jan 8 alecxe 7.5k points
0 votes
1 answer 394 views
394 views
Problem : I learning Python with the help of free online Python tutorial which wants me to write following Program: Create a temperature converter which will convert Fahrenheit values to Celsius and vice-versa using the following two formulas which relate the temperature f in Fahrenheit to ... ,sep ='') if inputString[-1] == 'F': farenheit = inputDigit print(celsiusConvert(farenheit),'C', sep='')
asked Nov 21, 2019 peterlaw 6.9k points
0 votes
1 answer 25 views
25 views
Problem : I am very new to Java Programming and currently I am stuck with the following doubt related to Strings. How to determine if two strings are permutations of each other? Any solution on my above doubt will be appreciated.
asked Dec 25, 2019 alecxe 7.5k points
1 vote
1 answer 181 views
181 views
Problem : I am very new to programming. I need to write a program called swapAdj that must accept the array of integers and after that swap those elements at the adjacent indexes. For example consider the elements 0 and 1 are swapped by the program and after ... note if your array has the odd length then the program must keep final element unmodified. Please help me in writing above program.
asked Apr 7 morrisBson 3.2k points