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
BaLLatris [955]
3 years ago
13

Code example 5-1 import java.util.Scanner; import java.text.NumberFormat; public class WeightConverter { public static void main

(String[] args) { Scanner sc = new Scanner(System.in); String prompt = "Enter weight in lbs: "; boolean isValid = false; double weightInPounds = 0.0; while (!isValid) { weightInPounds = getDouble(sc, prompt); if (weightInPounds > 0) { isValid = true; } else { System.out.println("Weight must be greater than 0."); } } double weightInKilos = weightInPounds / 2.2; NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2); String message = weightInPounds + " lbs\nequals\n" + nf.format(weightInKilos) + " kgs\n"; System.out.print(message); } public static double getDouble(Scanner sc, String prompt) { double d = 0.0; boolean isValid = false; while (!isValid) { System.out.print(prompt); if (sc.hasNextDouble()) { d = sc.nextDouble(); isValid = true; } else { System.out.println ("Error! Invalid decimal value. Try again."); } sc.nextLine(); } return d; } } (Refer to code example 5-1.) If the user enters "two hundred" at the console prompt, what does the code do? a. displays an error message from the main() method b. displays an error message from the getDouble() method c. figures the weight in kilograms d. throws an InputMismatchException
Computers and Technology
1 answer:
Trava [24]3 years ago
4 0

Answer:

It displays an error message from the getDouble() method

Explanation:

The above would be the result because of the following

1. Variable d is declared as a double variable and should be used as such.

2. The getDouble() method is also defined to handle double variables only.

When the program tries to accept at

weightInPounds = getDouble(sc, prompt);

The getDouble method is called immediately and since the value

"two hundred" entered in string, it can't handle this data type and it (the getDouble method) will display an error message

You might be interested in
What best describes "broadband access"? a. broadband access is a specific term used to describe the delivery of one-way televisi
Alex_Xolod [135]

Answer:

c. broadband access describes several technical methods that enable users to connect to high speed networks

Explanation:

Broadband is a simply term used for a high speed connection to the internet. This kind of internet access allow users to do everything they want using the internet, such as downloading video or audio clips, listen to online radio, sending emails, and others, at a very fast rate. Broadband services transmit information 40 times faster than dial-up modem connection. There are several  different broadband access techniques such as ISDN , DSL , Cable , Satellite , and Wireless.

5 0
3 years ago
Which of these might be an example of an advertiser's target group?
d1i1m1o1n [39]

Answer:

I would assume C. because it's the answer that makes the most sense.

Explanation:

D. would be the other choice however, just because they live in the same region doesn't mean they watch TV or have any access to media.

5 0
3 years ago
Read 2 more answers
Which option is the easiest way to configure macros in Access 2016?
zhuklara [117]
Number 2
Have a nice day
6 0
3 years ago
If you are writing an article on your favorite cuisine, which form of illustration would best fit the article?
andrezito [222]
The best article to use for this is a website that describes the food.
6 0
3 years ago
Read 2 more answers
List the six external parts or "peripherals" of a computer system and identify which are output and which are input devices/ Lis
vitfil [10]
Keyboard-Input
Mouse-Input
<u></u>Monitor-Output
Speakers-Output
Printer-Output
Hard Drive<span>-Output</span>
3 0
3 years ago
Other questions:
  • What is the use of word art?
    10·1 answer
  • Double clicking a word selects the entire word?
    10·1 answer
  • Suppose arraylist list1 is [1, 2, 5] and arraylist list2 is [2, 3, 6]. after list1.addall(list2), list1 is __________.
    8·1 answer
  • Consider the following classes: public class Vehicle {...} public class Car extends Vehicle {...} public class SUV extends Car {
    8·1 answer
  • Devon would like to install a new hard drive on his computer. Because he does not have a SATA port available on his motherboard,
    7·1 answer
  • Could u give me brief summary of New Years
    14·2 answers
  • Of the following field which would be the most appropriate for the primary key in a customer information table?
    5·1 answer
  • Electronic evidence on computer storage media that is not visible to the average user is called​ ________.
    14·1 answer
  • Do you trust machine learning application?
    10·1 answer
  • processing C. have only one function, e.g. control traffic lights in a town, games machines 7 To create a formula, you first: A.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!