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
5. Will rotating the tires extend their life?<br><br> O Yes<br> O No
ZanzabumX [31]
Answer is yes.
Tire rotation is undertaken to ensure that the tires wear evenly. This can extend tire life and save you money.
For example, failure to rotate tires on a front-wheel-drive vehicle will eventually result in the front tires having significantly less tread than the rear tires.
5 0
3 years ago
Read 2 more answers
What similarities do wind and solar energy share?
Viefleur [7K]

Answer:

Both come from the sun

Both are reusable sources

and both don't cause pollution

Explanation:

3 0
2 years ago
If the slotted arm rotates counterclockwise with a constant angular velocity of thetadot = 2rad/s, determine the magnitudes of t
astraxan [27]

Answer:

Magnitude of velocity=10.67 m/s

Magnitude of acceleration=24.62 ft/s^{2}

Explanation:

The solution of the problem is given in the attachments

3 0
3 years ago
Please help for our stem project :(
Darina [25.2K]

Answer:

Do you have some a picture

4 0
2 years ago
Truth table for (A+B)(B+C)
serg [7]

Answer:

A truth table is a logical expression of the given inputs specially in boolean algebra and boolean functions in computer science and digital electronics.

Explanation:

Number of variables are 3 i.e A,B and C

so the number of bits are 2^3=8

A      B     C           A+B               B+C         (A+B)(B+C)

0       0     0             0                   0                    0

0       0      1             0                    1                    0

0       1       0             1                    1                    1

0       1       1              1                    1                    1

1        0      0             1                    0                   0  

1        0      1              1                     1                    1

1        1       0             1                     1                    1

1        1        1             1                     1                    1

5 0
4 years ago
Other questions:
  • Millions of years ago, the Sierra Nevada region began to be uplifted along a crack in Earth's crust. The region on the other sid
    14·1 answer
  • A tire-pressure monitoring system warns you with a dashboard alert when one of your car tires is significantly under-inflated.
    6·1 answer
  • The correct statement about the lift and drag on an object is:_______
    7·2 answers
  • What is the average linear (seepage) velocity of water in an aquifer with a hydraulic conductivity of 6.9 x 10-4 m/s and porosit
    13·1 answer
  • An electrochemical cell is composed of pure nickel and pure iron electrodes immersed in solutions of their divalent ions. If the
    13·1 answer
  • Rubber bushings are used on suspensions to
    9·1 answer
  • Question 3. Assign boston_under_10 and manila_under_10 to the percentage of rides that are less than 10 minutes in their respect
    14·1 answer
  • Which term describes a Cloud provider allowing more than one company to share or rent the same server?
    7·1 answer
  • No question but thx<br> reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
    7·2 answers
  • 5. Liam is working on a circuit and notices it's quite hot to the touch. What's causing the heat Liam Is noticing
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!