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]
4 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]4 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
Another pitfall cited in Section 1.10 is expecting to improve the overall performance of a computer by improving only one aspect
Alexandra [31]

Answer:

<u>note:</u>

<em><u>solution is attached in word form due to error in mathematical equation. furthermore i also attach Screenshot of solution in word due to different version of MS Office please find the attachment</u></em>

Download docx
8 0
4 years ago
The price elasticity of demand for mobile phones a. will be higher if there is an improvement in the production technology. b. w
rodikova [14]

Answer:

b. will be lower if consumers perceive mobile phones to be a necessity.

Explanation:

The price elasticity of demand is described as the percentage variation in the demanded quantity of service or goods divided by the change in the percentage of the price. And henceforth it describes the responsiveness of the demanded quantity to a price change. And now if the mobile phones are thought of as being the necessity then the price will increase as demand will increase, and hence the price elasticity of demand will be lower. And if there is an improvement in the production technology then the price will be lowered, and hence price elasticity of demand will be less as the change in the percentage of the price will be negative. And the exact definition of it as we have described above. Hence, b is correct options.

3 0
3 years ago
Who are griefers?
S_A_V [24]

D) People who try to irritate you and harass you in online games

7 0
3 years ago
You can use a minus sign to make a negative numberlike -2. What happens to each of the following 2++2
Nostrana [21]
2 - -2 = 4
2 + -2 = 0
2 - +2 = 0
:)
6 0
3 years ago
Describe an unethical situation you might encounter at school. Discuss how you would handle the situation and explain why you wo
natali 33 [55]
If someone is threatening to shoot up the school, you would report it to the principal. You would handle it that way so the child can get arrested and nobody will be harmed.
5 0
3 years ago
Read 2 more answers
Other questions:
  • The logical view Select one: a. shows how data are organized and structured on the storage media. b. presents an entry screen to
    7·1 answer
  • What does Pentium means?:/
    7·2 answers
  • Name the part of windows<br> explore window​
    7·2 answers
  • You have been hired as a Systems Analyst in a famous Burger chain. Due to its popularity, the demands from customers also increa
    7·1 answer
  • Which of the following demonstrates the proper way to specify a variable-length argument list?
    7·1 answer
  • Which of the following operating systems includes a virtual assistant?<br> Group of answer choices
    8·1 answer
  • Lập trình web truy vấn csdl và hienr thị ra màn hình danh sách các bản ghi
    15·1 answer
  • 4. What are the things that a computer literate understands?name them
    5·2 answers
  • Does anyone know how to unblock websites on a school chromebook?
    6·2 answers
  • 5 efectos del desarrollo tecnológico en el medio ambiente
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!