11.7k views
0 votes
Create an application in Java that asks a user for a number of hours, days, weeks, and years. It then computes the equivalent number of minutes (ignoring leap years)

User Child
by
5.5k points

1 Answer

4 votes

Answer:

The program written in Java is as follows;

The program takes input for hours, days, weeks and months;

Then the inputs are converted to minutes individually and then summed up

For you to better understand the program, made use of comments to explain difficult lines,

The program is as follows

import java.util.*;

public class Assignment{

public static void main(String []args){

//This line declares all variables

int hours, days, weeks, years;

Scanner input = new Scanner(System.in);

//This line prompts user for hours input

System.out.print("Hours: ");

//This line accepts input for hours

hours = input.nextInt();

//This line prompts user for days input

System.out.print("Days: ");

//This line accepts input for days

days = input.nextInt();

//This line prompts user for weeks input

System.out.print("Weeks: ");

//This line accepts input for weeks

weeks = input.nextInt();

//This line prompts user for years input

System.out.print("Years: ");

//This line accepts input for years

years = input.nextInt();

//This line converts hours to minute

int minute = 60 * hours + 1440 * days + 10080 * weeks + 525600 * years;

//This line prints the equivalent minute of user input

System.out.println(minute +" minutes");

}

}

User Michelle Crane
by
5.3k points