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
Eduardwww [97]
3 years ago
14

The Double.parseDouble() method requires a String argument, but it fails if the String cannot be converted to a floating-point n

umber. Write an application in which you try accepting a double input from a user and catch a NumberFormatException if one is thrown. Te catch block forces the number to 0 and displays an appropriate error message. Following the catch block, display the number. Save the fle as TryToParseDouble.java.
Engineering
1 answer:
LuckyWell [14K]3 years ago
5 0

Answer:

  1. import java.util.Scanner;
  2. public class TryToParseDouble {
  3.    public static void main(String[] args) {
  4.        Scanner input = new Scanner(System.in);
  5.        double num;
  6.        try{
  7.            System.out.print("Input a number: ");
  8.            num = Double.parseDouble(input.nextLine());
  9.        }catch(NumberFormatException e){
  10.            num = 0;
  11.            System.out.println("Invalid input! It should be a number in double type");
  12.        }
  13.        System.out.println(num);
  14.    }
  15. }

Explanation:

Firstly, create a Scanner object to get user input (Line 5).

Next, create a try block and prompt user to input a number and use Double.parseDouble() method to convert the input to double type in the block (Line 8-10).

Next, create a catch block to catch a NumberFormatException. In the Catch block, set the num to zero and then print out a message to inform user about the invalid input (Line 12-14).

Lastly, display the number (Line 16).

You might be interested in
In Lab 7, we worked through a program that displayed the homeless shelter occupancy over time. The same approach can be used for
Bezzdna [24]

Answer:

Explanation:

The python code to generate this is quite simple to run.

i hope you understand everything written here, you can as well try out other problems to understand better.

First to begin, we import the package;

Code:

import pandas as pd

import matplotlib.pyplot as plt

name = input('Enter name of the file: ')

op = input('Enter name of output file: ')

df = pd.read_csv(name)

df['Date'] = pd.to_datetime(df["Date"].apply(str))

plt.plot(df['Date'],df['Absent']/(df['Present']+df['Absent']+df['Released']),label="% Absent")

plt.legend(loc="upper right")

plt.xticks(rotation=20)

plt.savefig(op)

plt.show()

This should generate the data(plot) as seen in the uploaded screenshot.

thanks i hope this helps!!!

6 0
3 years ago
What is this spray pattern defect most likely caused by:
DiKsa [7]

Answer:

fluid nozzle that is too large

6 0
2 years ago
An_______<br> employee is always prompt and on time.
Paha777 [63]
Do u won’t to go out
5 0
4 years ago
A ship tows a submerged cylinder, 1.5 m in diameter and 22 m long, at U = 5 m/s in fresh water at 20°C. Estimate the towing powe
shusha [124]

Answer:

(a) 120 kW

(b) 800 kW

Explanation:

Given:

diameter: 1.5 m

length = 22 m

U = 5 m/s

temperature = 20°C

For water at 20°C, take ρ = 998 kg/m³  and µ = 0.001 kg/m⋅s

To find:

power in kW

(a) if the cylinder is parallel

Length / Diameter = L / D = 22 / 1.5 = 14.6 = 15

Re(L) = ρ*U*L / µ = 998 * 5 * 22 / 0.001 = 109780000 = 1.1E8

C(D.Frontal) ≈ 1.1

  Force = F = 1.1 * ρ/2 * U² * π / 4 * D

            =  1.1 (998 / 2) (5)²(π / 4)(1.5)²  

            = 1.1 * 499 * 25 * 0.785 * 2.25

            = 24000 N

Power = Force * Displacement / time

           = F * U

           = 24000 * 5

           = 120000

Power = 120 kW

b) if the cylinder is normal to the tow direction.

Re(L) = ρ*U*D / µ = 998 * 5 * 1.5 / 0.001 = 7485000 = 7.5E6

C(D.Frontal) ≈ 0.4

Force = F = 0.4 * ρ/2 * U² * D * L

            =  0.4 (998 / 2) (5)²(1.5)(22)  

            = 164670 ≈ 165000

Power = Force * Displacement / time

           = F * U

           = 165000 * 5 = 825000

           ≈ 800 kW

Power = 800 kW

7 0
4 years ago
A 10.2 mm diameter steel circular rod is subjected to a tensile load that reduces its cross- sectional area to 52.7 mm^2. Determ
VMariaS [17]

Answer:

The percentage ductility is 35.5%.

Explanation:

Ductility is the ability of being deform under applied load. Ductility can measure by percentage elongation and percentage reduction in area. Here, percentage reduction in area method is taken to measure the ductility.

Step1

Given:

Diameter of shaft is 10.2 mm.

Final area of the shaft is 52.7 mm².

Calculation:

Step2

Initial area is calculated as follows:

A=\frac{\pi d^{2}}{4}

A=\frac{\pi\times(10.2)^{2}}{4}

A = 81.713 mm².

Step3

Percentage ductility is calculated as follows:

D=\frac{A_{i}-A_{f}}{A_{i}}\times100

D=\frac{81.713-52.7}{81.713}\times100

D = 35.5%.

Thus, the percentage ductility is 35.5%.

5 0
3 years ago
Other questions:
  • The motor draws in the cord at B with an acceleration of aB = 2 m/s2 . When sA = 1.5 m , vB = 6.2 m/s .
    9·1 answer
  • One positive side-effect of bipolar encoding is that a bipolar violation (two consecutive pulses or two consecutive - pulses sep
    11·1 answer
  • How much heat (Btu) is prod uced by a 150-W light bulb that is on for 20-hours?
    14·1 answer
  • How do I cancel Trial subscription
    15·1 answer
  • Write a SELECT statement that returns these column names and data from the Products table: product_name The product_name column
    9·1 answer
  • A three-phase, 318.75kVA, 2300-Volt, alternator has an armature resistance of 0.35/phase and a synchronous reactance of 1.2/phas
    10·1 answer
  • Witch part of the testing and evaluation stage of designing a PDA
    9·1 answer
  • Suppose there is a mobile application that can run in two modes: Lazy or Eager. In Lazy Mode, the execution time is 3.333 second
    11·1 answer
  • In one study the critical stress intensity factor for human bone was calculated to be 4.05 MN/m3/2. If the value of Y in Eq. (2.
    6·1 answer
  • 2. The moist weight of 0.1 ft3 of soil is 12.2 lb. If the moisture content is 12% and the specific gravity of soil solids is 2.7
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!