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
kolbaska11 [484]
3 years ago
8

If the user enters any operator symbol other than , -, *, or /, then an UnknownOperatorException is thrown and the user is allow

ed to reenter that line of input. Define the class UnknownOperatorException as a subclass of the Exception class. Your program should also handle NumberFormatException if the user enters non-numeric data for the operand.
Computers and Technology
1 answer:
Anna007 [38]3 years ago
7 0

Answer:

Explanation:

The following code is written in Java. It creates the UnknownOperatorException class and catches it if the user enters something other than the valid operators. If so it continues asking the user for a new input. Once a valid operator is entered, it exits the function and prints the operator.

import java.util.Scanner;

class Brainly {

   public static void main(String[] args) {

       char symbol = askForOperand();

       System.out.println("Operand: " + symbol);

   }

   public static char askForOperand() {

       Scanner in = new Scanner(System.in);

       try {

           System.out.println("Enter operator symbol: ");

           char symbol = in.nextLine().charAt(0);

           if ((symbol != '-') && (symbol != '*') && (symbol != '/')) {

               System.out.println(symbol);

               throw new UnknownOperatorException();

           } else {

               return symbol;

           }

       } catch (NumberFormatException | UnknownOperatorException e) {

           System.out.println("Not a valid operand");

           char symbol = askForOperand();

           return symbol;

       }

   }

}

class UnknownOperatorException extends Exception {

   public UnknownOperatorException() {

       System.out.println("Unknown Operator");

   }

}

You might be interested in
Is the answer a,b,c,d
MariettaO [177]
Well I got some numbers mixed up but I think it’s B
4 0
3 years ago
If you wanted to create a line of code that would add ten to the user’s current score, which code should you use?
Korvikt [17]

Answer:

choice c

Explanation:

score = score + 10

because the rest doesn't make since and score == score + 10 has an extra equal sign.

7 0
3 years ago
Read 2 more answers
SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Assume that the classes listed in the Java Quick R
adoni [48]

Answer:

Check the explanation

Explanation:

Player 1 Coin

Player 2 Coin

Player 1

Player 2

Round

Count at

Count at

Player

Player

Coin

Coin

Number

Beginning of

Beginning of

1

2

Outcome

Count at

Count at

Round

Round

Spends

Spends

End of

End of

Round

Round

Off-by-

one,

10 - 1

10

10

2

player 2

10 - 2

+

= 8

1

gains 1

= 10

coin

Same,

10 - 2

2

8

10

2

2

player 2

-

gains 1

6

+

=

1

=

9

coin

Off-by-

two,

6 - 1

+

3

6

9

3

player 1

2

9 - 3

gains 2

=

=

7

6

coins

Same,

4

7

6

2

2

player 2

7 - 2

6 - 2+

gains 1

=

5

=

coin

5

Kindly check the attached image below to see the well arranged table to solve the above question.

4 0
3 years ago
Write a function DrivingCost with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar co
jolli1 [7]

Answer:

the brainly thing is saying that i can't put the answer so i screenshotted it and put it down below

Explanation:

4 0
2 years ago
If you wish to include a header or footer on all pages in a publication, you will need to insert this by navigating to the _____
Marina86 [1]
If you wish to include a header or footer on all pages in a publication, you will need to insert this by navigation to the master page.
7 0
3 years ago
Read 2 more answers
Other questions:
  • To apply the rule of thirds you first? PLZ HURRY AND ANSWER THIS
    5·2 answers
  • How to use javascript libraries in javascript code?
    9·1 answer
  • A friend complains that she is always running out of money even though she “never buys anything expensive.” What advice would yo
    10·1 answer
  • NEED HELP NOW 25 POINTS!!!!!!
    15·2 answers
  • Dylan, an interior designer, has sketched out a layout for a client's living room. He wants the client's approval of the layout
    11·2 answers
  • What are the importance of switches in our electron device
    15·1 answer
  • When you set up a worksheet, you should use cell references in formulas whenever possible, rather than ____ values.
    11·1 answer
  • What does the Python print() function do?
    7·1 answer
  • What is the correct way to write h1 tag
    12·1 answer
  • What role do play in medicine ​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!