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
What are the three main components of a for loop?
insens350 [35]

Answer:

Similar to a While loop, a For loop consists of three parts: the keyword For that starts the loop, the condition being tested, and the EndFor keyword that terminates the loop.

Explanation:

Loop statements usually have four components: initialization (usually of a loop control variable), continuation test on whether to do another iteration, an update step, and a loop body.

8 0
3 years ago
Which step in the software development life cycle involves making improvements based on user feedback?
AnnZ [28]

Answer:

Maintenance is the answer

5 0
3 years ago
When was the phone Built
quester [9]
The first phone was made in 1854 by <span>Antonio Meucci.

Other inventors like </span>Johann Philipp Reis, <span>Alexander Graham Bell, Elisha Gray, and Thomas Edison reinvented the telephone or enhanced it.</span>
3 0
3 years ago
Read 2 more answers
How many numbers can be represented with 2,3,4,8 bits?
MrRa [10]
Image that a bit is the smallest measure in programming, such as an elementary particle in physics. So, a bit can only fit one number.
5 0
3 years ago
Which sql server 2012 edition is targeted at hosted, internet-facing deployment?
Mice21 [21]
<span>The Web version will work for this type of need. This version runs at a slightly lesser capability than the full version, but will still perform many of the advanced functions of SQL Server. The processor and RAM utilizations are a bit less than the maximum provided in other versions.</span>
7 0
3 years ago
Other questions:
  • ________ is digital textual information that can be stored, manipulated, and transmitted by electronic devices.
    7·1 answer
  • The material chosen for your study group
    11·1 answer
  • Gunther is filling in his own input mask. He wants to format the Social Security numbers of his clients. The field must contain
    5·1 answer
  • Write a program that asks the user for two file names. The first file will be opened for input and the second file will be opene
    8·1 answer
  • Cash cows are always in
    7·1 answer
  • There are ___ Federal Reserve Banks. Each bank is also in charge of its assigned District Banks.
    10·1 answer
  • Which of these trade-offs occur in a memory hierarchy?
    15·1 answer
  • Calvin needs to design a simple yet professional interface for his users. Which option should he implement?
    9·2 answers
  • Discuss two business information systems that are used in two different sectors in a modern economy.
    11·1 answer
  • ________(fill in the blank)in online education is intrinsically related to equity.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!