Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA Using the provided template, complete the program below, which will read in

ID: 3751082 • Letter: J

Question

JAVA

Using the provided template, complete the program below,
which will read in a number of minutes from the user, and convert those minutes to hours and minutes.

(1) Write a method definition to display the following program description:
Program to convert minutes to hours and minutes
There should be one blank line displayed after the program description.

Then call this method from within the main method.

(2) Write a method definition that takes the number of minutes as an input parameter,
and then calculates the whole hours within those minutes, and returns the result.

Then call this method from within the main method and store the result returned into the wholeHours variable.

(3) Write a method definition that takes the number of minutes as an input parameter,
and then calculates minutes remaining beyond the whole hours, and returns the result.

Then call this method from within the main method and store the result returned into the remainingMinutes variable.

(4) Using the values returned from the methods, display the time in the format (2-digits each):
Hours and minutes: HH:MM

.

import java.util.Scanner;

public class MinuteConverter {

   // Fix (1a) - Add code for method definition to display program description

   // Fix (2a) - Add code for method definition determine and return hours

   // Fix (3a) - Add code for method definition determine and return minutes
  
   public static void main(String[] args) {
      int inputMinutes = 0;
      int wholeHours = 0;
  int remainingMinutes = 0;
      Scanner keyboard = new Scanner(System.in);

  // Fix (1b) - Add method call to display program description

  System.out.println("Enter number of minutes to convert:");
      inputMinutes = keyboard.nextInt();
       
  // Fix (2b) - Add method call to determine whole hours and store the result
  // Fix (3b) - Add method call to determine remaining minutes and store the result
  
  System.out.println();
    // Fix (4) - Finish code to display returned hours and minutes in format XX:XX
    System.out.printf("Hours and minutes: ");
   }

}

Explanation / Answer

import java.util.Scanner; public class MinuteConverter { // Fix (1a) - Add code for method definition to display program description public static void printHeader() { System.out.println("Program to convert minutes to hours and minutes "); } // Fix (2a) - Add code for method definition determine and return hours public static int calculateWholeHours(int minutes) { return minutes / 60; } // Fix (3a) - Add code for method definition determine and return minutes public static int calculateRemainingMinutes(int minutes) { return minutes % 60; } public static void main(String[] args) { int inputMinutes = 0; int wholeHours = 0; int remainingMinutes = 0; Scanner keyboard = new Scanner(System.in); // Fix (1b) - Add method call to display program description printHeader(); System.out.println("Enter number of minutes to convert:"); inputMinutes = keyboard.nextInt(); // Fix (2b) - Add method call to determine whole hours and store the result wholeHours = calculateWholeHours(inputMinutes); // Fix (3b) - Add method call to determine remaining minutes and store the result remainingMinutes = calculateRemainingMinutes(inputMinutes); System.out.println(); // Fix (4) - Finish code to display returned hours and minutes in format XX:XX System.out.printf("Hours and minutes: %02d:%02d ", wholeHours, remainingMinutes); } }