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
kobusy [5.1K]
3 years ago
8

Modify any of the previous labs which would have crashed when non-numeric data was entered by adding exception handling so that

the non-numeric input no longer crashes the program. The program must handle the invalid input gracefully by informing the user of the bad input and re-querying until the user provides valid input. It must re-query for the specific input which was incorrectly entered.
Engineering
1 answer:
Mashutka [201]3 years ago
7 0

Answer:

see explaination

Explanation:

import java.util.InputMismatchException;

import java.util.Scanner;

public class calculate {

static float a=0,b=0;

double cal()

{

if(a==0||b==0)

{

System.out.println("no values found in a or b");

start();

}

double x=(a*a)+(b*b);

double h=Math.sqrt(x);

a=0;

b=0;

return h;

}

float enter()

{

float val=0;

try

{

System.out.println("Enter side");

Scanner sc1 = new Scanner(System.in);

val = sc1.nextFloat();

return val;

}

catch(InputMismatchException e)

{

System.out.println("Enter correct value");

}

return val;

}

void start()

{

calculate c=new calculate();

while(true)

{

System.out.println("Enter Command");

Scanner sc = new Scanner(System.in);

String input = sc.nextLine();

switch(input)

{

case "A":

a=c.enter();

break;

case "B":

b=c.enter();

break;

case "C":

double res=c.cal();

System.out.println("Hypotenuse is : "+res);

break;

case "Q":

System.exit(0);

default:System.out.println("wrong command");

}

}

}

public static void main(String[] args) {

calculate c=new calculate();

c.start();

}

}

You might be interested in
The volume of 1.5 kg of helium in a frictionless piston-cylinder device is initially 6 m3. Now, helium is compressed to 2 m3 whi
coldgirl [10]

Answer:

The initial temperature will be "385.1°K" as well as final will be "128.3°K".

Explanation:

The given values are:

Helium's initial volume, v₁ = 6 m³

Mass, m = 1.5 kg

Final volume, v₂ = 2 m³

Pressure, P = 200 kPa

As we know,

Work, W=p(v_{2}-v_{1})

On putting the estimated values, we get

⇒            =200000(2-6)

⇒            =200000\times (-4)

⇒            =800,000 \ N.m

Now,

Gas ideal equation will be:

⇒  pv_{1}=mRT_{1}

On putting the values. we get

⇒  200000\times 6=1.5\times 2077\times T_{1}

⇒  T_{1}=\frac{1200000}{3115.5}

⇒       =385.1^{\circ}K (Initial temperature of helium)

and,

⇒  pv_{2}=mRT_{2}

On putting the values, we get

⇒  200000\times 2=1.5\times 2077\times T_{2}

⇒  T_{2}=\frac{400000}{3115.5}

⇒       =128.3^{\circ}K (Final temperature of helium)

3 0
3 years ago
When the third color band is silver it represents
juin [17]
The third band represents the multiplier
4 0
3 years ago
Which is the independent variable and why is it independent?
algol [13]

Answer: An independent variable is exactly what it sounds like. It is a variable that stands alone and isn't changed by the other variables you are trying to measure. For example, someone's age might be an independent variable.

Carry learning!

Stay safe!

6 0
3 years ago
Read 2 more answers
Coefficients of friction always involve how many materials? a. 0 b. 1 c. 2 d. 3
True [87]

Answer:

Answer is c. 2

Explanation:

Since friction is present at the contact  between 2 materials thus coefficient of friction always involve 2 materials

5 0
3 years ago
The device shown below contains 2 kg of water. The cylinder is allowed to fall 800 m during which the temperature of the water i
olganol [36]

Answer:

m_added = 2 kg

Explanation:

From the question, we are told that the cylinder is allowed to fall 800 m in height. Thus, the potential energy will be converted into heat energy which will increase the temperature of water .

Now, let the mass of the falling cylinder be denoted by "m1" and let h be the height of fall.

Thus;

Formula for potential energy = mgh

Thus, as said earlier it's converted to heat generated. So heat generated = m1gh

Now let's calculate the heat absorbed;

heat absorbed = (m2)cΔt

Where;

ΔT is change in temperature

c is specific heat of water .

m2 is mass of water

Heat absorbed = heat generated

Thus;

(m2)cΔt = m1gh

Δt = m1gh/(m2•c)

Now, in both cases of the water and cylinder, m1, g , h and c are constant

Thus, we have;

Δt = (m1gh/m2) × 1/c

Where;

(m1gh/m2) is denoted as a constant k.

Thus;

Δt = K/m

For the first experiment, we have;

m = 2 kg

Δt = 2.4

Thus;

2.4 = K/2

Multiply both sides by 2 to get;

K = 4.8

For the second experiment, we have;

Δt = 1.2

Also,we have seen that K = 4.8

Thus;

Δt = K/m

Thus;

1.2 = 4.8/m

m = 1.2

m = 4 kg

Thus,mass added is;

m_added = 4 - 2

m_added = 2 kg

6 0
3 years ago
Other questions:
  • For metallurgical reasons, it is desirable to melt the weld metal with minimum energy input. Which one of the following heat sou
    10·1 answer
  • A thick steel slab ( 7800 kg/m3, 480 J/kg·K, 50 W/m·K) is initially at 300°C and is cooled by water jets impinging on one of its
    14·2 answers
  • A motorist enters a freeway at 25 mi/h and accelerates uniformly to 65 mi/h. From the odometer in the car, the motorist knows th
    14·1 answer
  • Alcohol consumption tends to cause more ___________ behavior.
    14·1 answer
  • 10. To cut 1/4" (6 mm) thick mild steel at a rate of 40 inches per minute, the current would be set to
    7·1 answer
  • Which timeline shows the correct order of contributions made to the discovery of DNA?
    6·2 answers
  • The price of a single item within a group of items is
    8·1 answer
  • Engineers need to be open-ended when dealing with their designs. Why?
    11·1 answer
  • Dndbgddbdbhfdhdhdhhfhffhfhhddhhdhdhdhdhd​
    11·2 answers
  • 8. Block A shown in the figure below weighs 2000 N. The chord attached to A passes over a
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!