• Register
0 votes
2.2k 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

Please log in or register to answer this question.

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)));
   }
38.6k 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("");
   }
}

 

31.7k points

Related questions

0 votes
1 answer 447 views
447 views
Convert seconds to hours, minutes and seconds #include <cstdio> #include <iostream> using namespace std; int main() {      int seconds, hours, minutes;      cin >> seconds;      hours = seconds/3600;      cout << seconds << "seconds is equivalent to" << ... know how to fix this? Whenever I do a number less than 3600, a message appears on the screen stating that the program has stopped working.
asked Aug 27, 2020 sasha 16.2k points
0 votes
1 answer 31 views
31 views
Problem: complete the method definition to output the hours given minutes. output for sample program:
asked Feb 23 Muneeb Saadii 130k points
0 votes
1 answer 44 views
44 views
Problem: Someone assist me please : Complete the function definition to output the hours given minutes. output for sample program:
asked Jun 11 Chi Omega 166k points
0 votes
1 answer 13 views
13 views
Problem: I need to convert minutes to hours and minutes in java. For example 260 should be 4:20. can anyone help me how to do convert it.
asked Apr 25 Yeamin 23.5k points
0 votes
1 answer 16 views
16 views
Problem: Where should I look for help with this issue : Complete the function definition to output the hours given minutes?
asked Jun 19 Florina Gulnar 103k points
0 votes
1 answer 16 views
16 views
Problem: How do I complete this recursive function at output_string += ? Output should be: 5! = 5 * 4 * 3 * 2 * 1 = 120 def print_factorial(fact_counter, fact_value): output_string = '' if fact_counter == 0: # Base case: 0! = 1 output_string ... next_counter * fact_value output_string += return output_string user_val = 5 print('%d! = ' % user_val, end="") print(print_factorial(user_val, user_val))
asked Apr 25 sumaiya simi 43.9k points
0 votes
1 answer 214 views
214 views
Problem: write code to complete printfactorial()'s recursive case. sample output if userval is 5:
asked Feb 23 Muneeb Saadii 130k points
0 votes
1 answer 105 views
105 views
Problem: How can I handle the base case of this recursive function? My base case is causing an output of zero
asked Mar 6 ummesalma 29.1k points
0 votes
1 answer 10 views
10 views
Problem: Any solution to this iisue > Overload the + operator as indicated. sample output for the given program:
asked May 2 ummeshani 10.8k points
0 votes
1 answer 36 views
36 views
Problem: Is it legitimate to delete items from a dictionary in Python while iterating over it? : Delete prussia from country_capital. sample output for the given program:
asked May 1 ochena 23.3k points