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
You are considering purchasing a compact washing machine, and you have the following information: The Energy Guide claims an est
RSB [31]

Answer: $15.34

Explanation: see image below

8 0
2 years ago
Given the inherent costs of regulation it is safe to say that there is always a negative economic impact associated with regulat
Alexus [3.1K]

the answer is true.                                     <u>                    </u>                                                              

6 0
2 years ago
What steps might one take to make a decision or solve a problem
marusya05 [52]

you must think and plan out what you want to do

8 0
3 years ago
Read 2 more answers
A commercial refrigerator with refrigerant -134a as the working fluid is used to keep the refrigerated space at -30C by rejectin
Mariana [72]

Answer:

a) 0.487

b) refrigeration load = 5.46w

c) cop = 2.24

d)ref load max = 12.43kw

Explanation:

6 0
3 years ago
Read 3 more answers
Which is a better hydraulic cross section for an open channel: one with a small or a large hydraulic radius?
Cerrena [4.2K]
Hydraulic radius is caused by pressurized hydrogen air so that should mean the answer is hydraulic radius
6 0
2 years ago
Other questions:
  • You read a research study that concludes that the higher a student's self-esteem, the better he performs in school. This sort of
    5·1 answer
  • An n- channel enhancement- mode MOSFET with 50 nm thick HfO2 high- k gate dielectric (Pr = 25) has a flat band voltage of 0.5 V,
    5·1 answer
  • A power of 100 kW (105 W) is delivered to the other side of a city by a pair of power lines, between which the voltage is 12,000
    9·1 answer
  • A logic chip used in a computer dissipates 3 W of power in an environment at 120°F, and has a heat transfer surface area of 0.08
    11·1 answer
  • Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print
    10·1 answer
  • A 2.5 m wide rough continuous foundation is placed in the ground at 1 m depth. There is bedrock present at 1 m depth below the b
    12·1 answer
  • A hurdler is 0.535 m from a hurdle when he jumps at 6.82 m/s at a 6.79 degree angle. What is his height when he clears the hurdl
    13·1 answer
  • For RTK to work, what do we need besides two or more receivers collecting data from a sufficient number of satellites simultaneo
    11·1 answer
  • Technician A says that fuel filler caps with pressure and vacuum vents are used with EVAP system fuel tanks. Technician B says t
    5·1 answer
  • A company intends to market a new product and it estimates that there is a 20% chance that it will be first in the market
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!