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
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: "); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started