1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
anzhelika [568]
3 years ago
5

Write a program the prompts the user to enter a length in feet and inches and outputs the equivalent length in centimeters.If th

e user enters a negative number or a nondigit number, throw and handle an appropriate exception and prompt the user to enter another set of numbers.
Computers and Technology
1 answer:
antiseptic1488 [7]3 years ago
8 0

Answer:

The solution is written in Java.

  1. public class Main {
  2.    public static void main(String[] args) {
  3.        double CM_PER_INCH = 2.54;
  4.        double CM_PER_FOOT = 30.48;
  5.        double feet = 0;
  6.        double inches = 0;
  7.        double centimeter;
  8.        Scanner input = new Scanner(System.in);
  9.        try{
  10.            System.out.print("Please enter feet: ");
  11.            String input_feet = input.nextLine();
  12.            feet = Double.parseDouble(input_feet);
  13.            System.out.print("Please enter inch: ");
  14.            String input_inches = input.nextLine();
  15.            inches = Double.parseDouble(input_inches);
  16.            if(feet >= 0 && inches >=0){
  17.                centimeter = feet * CM_PER_FOOT + inches * CM_PER_INCH;
  18.                System.out.println("The total centimeter is " + centimeter);
  19.            }else{
  20.                throw new IllegalArgumentException();
  21.            }
  22.        }
  23.        catch(NumberFormatException ex){
  24.            System.out.println("The input must be digit.");
  25.            System.out.println("Please re-enter input.");
  26.        }
  27.        catch(IllegalArgumentException e){
  28.            System.out.println("The input must be positive number.");
  29.            System.out.println("Please re-enter input.");
  30.        }
  31.    }
  32. }

Explanation:

There are two types of errors required to captured: Negative value error and non-digit error.

Hence, we can define two error handling blocks as in (Line 25-28 and Line 29 - 32) to handle those two errors, respectively.

To check for non-digit error, we can use parseDouble method (Line 13 & 16). If the input is not a digit, the exception, NumberFormatException will be raised. If the input is negative value, IllegalArgumentException will be raised.

If everything goes smooth, the program will calculate the centimeter and display it to terminal (Line 19-20).

You might be interested in
How long does it take rblx to re open deleted acc
dedylja [7]

Answer:

(Probably) unknown

Explanation:

First off, you have to get rblx to agree to re-open a deleted, which I can imagine would take a herculean effort and most likely a stream of emails and phone calls. If they happen to archive deleted accounts, they may be able to recover it, but this is done by humans, so there is no definitive way to find out how long it would take a human to do this. If deleted accounts aren't archived, then you're outta luck because they won't be able to get it back.

4 0
3 years ago
Read 2 more answers
Negative numbers are encoded using the __________ technique. a. two’s complement b. floating point c. ASCII d. Unicode
OLEGan [10]

Negative numbers are encoded using the two’s complement technique. Two's complement is used to encode negative numbers.

Option  A is correct .

<h3>What method does the in data type use to store negative numbers?</h3>

Most implementations you're likely to encounter store negative signed integers in a form known as two's complement. Another important way of storing negative signed numbers is called one's complement. The one's complement of an N-bit number x is basically defined as x with all bits inverted.

<h3>What is encoding method?</h3>

An encoding technique is the application of established industry conventions to a coded character set to create a coded character scheme. Such rules determine the number of bits required to store the numeric representation of a given character and its code position in the encoding.

Learn more about two complement technique encoding :

brainly.com/question/26668609

#SPJ4

5 0
1 year ago
Each device attached to your computer has a special program called a(n ________ that enables the device and operating system to
koban [17]
The answer is Device Driver
8 0
3 years ago
Round 74,361 to the nearest 10​
grandymaker [24]

Answer:

74,400 i think

Explanation:

8 0
3 years ago
The amount of white space or vertical space between the lines of the text in a paragraph is called line spacing.
jekas [21]

Answer:

It is a true statement .

3 0
3 years ago
Other questions:
  • Which of the following is NOT a search engine ( Bing, Yahoo, Ask, Twitter)
    6·2 answers
  • What is returned by datetime(1970, 1, 1).strftime('%Y-%d-%B') in Python?
    10·1 answer
  • Which one of the following may be used as an input as well as an output device? A. Fax machine B. Scanner C. Printer D. Voice re
    9·1 answer
  • Phillip wants to create a new Google Display Ad campaign and base his targeting on an existing remarketing list named Checkout A
    10·1 answer
  • Please check my answer! (Java)
    8·1 answer
  • Why does a print document need a higher raster effect setting ?​
    14·1 answer
  • I need help with this answer, I will give brainliest as long as there is actually an answer!
    11·1 answer
  • How can a user remove or delete a Pivot Table?
    8·1 answer
  • hello fellows i need a help.Ineed to know about computer evolutions and computer generations.please hurry.Its my rankover questi
    10·1 answer
  • What open source format has multiple versions for storing audio and video content?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!