Question

In: Computer Science

Write a program that accepts a number of minutes and converts it to days and hours....

Write a program that accepts a number of minutes and converts it to days and hours. For example, 6000 minutes represents 4 days and 4 hours. Be sure to provide proper exception handling for non-numeric values and for negative values.

Save the file as  MinuteConversionWithExceptionHandling.java

Solutions

Expert Solution

MinuteConversionWithExceptionHandling.java

import java.util.Scanner;
import java.io.IOException;
import java.util.*;

public class Main
{
   public static void main(String[] args) {
       int minutes;
       int days;
       int hours;
       int min;
       Scanner input = new Scanner(System.in);
       try {
       //Read the input
       System.out.print("Enter the minutes to convert:");
minutes =input.nextInt();
//Check for the negative input
if(minutes<0)
throw new Exception("The entered number is negative");
//Convert to days
days=minutes/(24*60);
//convert to hours
hours = (minutes%(24*60))/60;
//convert to minutes
min=(minutes%(24*60))%60;
System.out.println(days+"days"+" "+hours+"hours"+" "+min+"minutes");
  
}
//for non-numeric input
catch(InputMismatchException e) {
System.out.println("Invalid input,Please enter integer");
       } catch(Exception e) {
       System.out.println(e.getMessage());
       }
   }
}

Output

Enter the minutes to convert:hfkesjf                                                                                          

Invalid input,Please enter integer  

Output

Enter the minutes to convert:-89                                                                                              

The entered number is negative

Output

Enter the minutes to convert:6000                                                                                             

4days 4hours 0minutes


Related Solutions

Write a program that accepts a number of minutes and converts it both to hours and...
Write a program that accepts a number of minutes and converts it both to hours and days. For example, 6000 minutes is 100.0 hours or 4.166666666666667 days. (I currently have what is below) import java.util.Scanner; public class MinutesConversion { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int numOfMinutes = sc.nextInt(); double hour = numOfMinutes/60.00; double days = (hour/24); System.out.println(numOfMinutes + " minutes is " + hour + " hours or " + days + " days.");...
3. Write a java method that accepts a binary number and converts it to decimal then...
3. Write a java method that accepts a binary number and converts it to decimal then display the result. For Example: (110)2 = (6)10 (2 2 *1)+ (21 *1) + (20*0) = 6 Additional task: write a method that accepts a decimal and converts it to binary. i need to solve it as soon as and i will upvote you directly
Write a program that converts the user's number into the desired unit of measurement. The user...
Write a program that converts the user's number into the desired unit of measurement. The user will pick the desired unit from a menu shown below. Ask the follow-up question (the number to convert) and do the math ONLY if the user picks a valid choice from the menu. You can see the conversions / multipliers needed for this program in the output section below. Menu/Prompt: Enter the number that corresponds to your desired unit conversion from the choices below:...
2. Write a program that asks for hexadecimal number and converts it to decimal. Then change...
2. Write a program that asks for hexadecimal number and converts it to decimal. Then change it to convert an octal number to decimal in perl language.
Write a program in C++ that converts a positive integer into the Roman number system. The...
Write a program in C++ that converts a positive integer into the Roman number system. The Roman number system has digits I      1 V    5 X    10 L     50 C     100 D    500 M    1,000 Numbers are formed according to the following rules. (1) Only numbers up to 3,999 are represented. (2) As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately. (3) The numbers 1 to 9 are expressed as...
A C program that accepts a single command line argument and converts it in to binary...
A C program that accepts a single command line argument and converts it in to binary with array length of 16 bits. The array should contain the binary of the int argument. the program should also convert negative numbers. Side note the command line arg is a valid signed int.
In a program, write a function that accepts two arguments: a list, and a number n....
In a program, write a function that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all of the numbers in the list that are greater than the number n. The program should ask for a list of numbers from the user as well as a value (a, b, c)--> inputs from user. After that, each number in that list should be compared to that value (a or b or...
Write a C++ program that accepts a positive integer number from the keyboard . The purpose...
Write a C++ program that accepts a positive integer number from the keyboard . The purpose of the program is to find and the display all the square pair numbers between 1 and that number. The user should be able to repeat the process until he/she enters n or N in order to terminate the process and the program. Square numbers are certain pairs of numbers when added together gives a square number and when subtracted also gives a square...
Write a program that converts a given floating point binary number with a 24-bit normalized mantissa...
Write a program that converts a given floating point binary number with a 24-bit normalized mantissa and an 8-bit exponent to its decimal (i.e. base 10) equivalent. For the mantissa, use the representation that has a hidden bit, and for the exponent use a bias of 127 instead of a sign bit. Of course, you need to take care of negative numbers in the mantissa also. Use your program to answer the following questions: (a) Mantissa: 11110010 11000101 01101010, exponent:...
Write a program in C A teacher will assign homework and give the number of days...
Write a program in C A teacher will assign homework and give the number of days for the students to work on. The student is responsible for calculating the due date. The teacher does not collect homework on Friday or weekend. Write a C program that let the user enter today’s day of the week (0 for Sunday, 1 for Monday, etc.) and the number of days to allow the students to do the work, which may be several weeks....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT