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]
4 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]4 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
Ask the user to type in an integer greater than 50 and assign it to a variable called x. Write a program to calculate the sum of
Zinaida [17]

Answer:

The solution in Python is as follows:

<em>num = int(input("Number: "))</em>

<em>if num>50:</em>

<em>     sum = 0</em>

<em>     count = 0</em>

<em>     for i in range(1,num):</em>

<em>          count = count + 1</em>

<em>          sum = sum + i**2</em>

<em>          if sum > num:</em>

<em>               sum = sum - i**2</em>

<em>               count = count - 1</em>

<em>               break;</em>

<em>    </em>

<em>     print("Sum: "+str(sum))</em>

<em>     print("Numbers: "+str(count))</em>

<em>else:</em>

<em>     print("Number must be greater than 50")</em>

<em />

Explanation:

The condition stated in the question do not conform with the example. The question says, the loop should stop when sum > x.

But:

When x = 100 and sum = 91, the program loop should not stop because 91 is not greater than 100.

However, I'll answer based on the example given in the question.

This prompts user for number

num = int(input("Number: "))

The following if condition is executed if number is greater than 50

if num>50:

This initializes sum to 0

    sum = 0

This initializes count to 0

    count = 0

The iterates through the inputted number (e.g. 100)

    for i in range(1,num):

This increases the count

         count = count + 1

This calculates the sum of square of the positive integer

         sum = sum + i**2

The following removes excess number from the sum

<em>          if sum > num:</em>

<em>               sum = sum - i**2</em>

<em>               count = count - 1</em>

<em>               break;</em>

This prints the calculated sum    

    print("Sum: "+str(sum))

This prints the count of number used

    print("Numbers: "+str(count))

The following is executed if user input is less than 50

<em>else:</em>

<em>     print("Number must be greater than 50")</em>

<em />

<em></em>

3 0
3 years ago
Which of the following features of a network connection between a switch and server is not improved by link aggregation?
Elza [17]

Answer:

The correct answer to the following answer will be Speed.

Explanation:

  • As we all know that computer works at a remarkable speed, no one can match the speed of the computer system.
  • No one having the capacity of solving the computations (complex) fastest than any computer.
  • Its can be the feature by which connection of the network between a server and a switch can't be improved by the collection of link.

The other three options A, C and D can't be the features of network connection as they are not related to the given statement.

7 0
3 years ago
The exception classes are in packages in the ________.
kakasveta [241]

Answer: Compiler

Explanation:

 The exception classes are basically occur during the compilation of the program in the system. The exception is the event which disrupt the flow of the instruction.

It basically provide a way to transfer the control in the one part of the program to another program. The exception class is also known as run-time exception that basically indicate the condition in the class application.

All the other options are not in the form of packages in the exception class. Therefore, compiler is the correct option.

8 0
4 years ago
6
Lisa [10]

Answer C in the paragraph group on the home tab

8 0
3 years ago
When methods have ____, other programs and methods may use the methods to get access to the private data.
Nostrana [21]

When methods have public access, other programs and methods may use the methods to get access to the private data.

<h3>What do you mean by public access?</h3>

The Definition of the term public access is known to be a kind of a television channel where anybody can be able to broadcast a program

An example is the city council meeting can be able to broadcast on public access.

Hence, When methods have public access, other programs and methods may use the methods to get access to the private data.

See full question below

When methods have ____, other programs and methods may use the methods to get access to the private data.

a. private access

b. public access

c. complete access

d. all access

Learn more about public access from

brainly.com/question/2736088

#SPJ1

5 0
2 years ago
Other questions:
  • Elvis has asked Bonnie out on a date to a baseball game. Elvis is a friend of Bonnie's classmate Ginger and she has met him a fe
    5·2 answers
  • You have a subnetwork, 192.168.48.0/24. it is divided into subnet a and subnet
    8·1 answer
  • Why is drafting important in every industry
    6·1 answer
  • Right click on a spot of your desktop that is not covered by an icon, window, or menu. when the menu comes up, play with the opt
    7·1 answer
  • Ben sends a few emails over the weekend to his relatives. Where should Ben place his laptop so that he can avoid slouching while
    11·1 answer
  • ______ norms are usually unstated rules that regulate members' interaction.
    12·1 answer
  • Which group allows you to add notes to your presentation?
    8·2 answers
  • What is the first law of thermodynamics?
    5·2 answers
  • Write a python program to print numbers from 100 to 50 using for loop.<br> I NEED THIS URGENT PLEASE
    9·1 answer
  • Just help :(((((((((((((((((((((((((((((((((((
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!