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 does aperture control? A)amount of light the image sensor captures when taking a photo. B)how sensitive the camera is to in
My name is Ann [436]

Answer:

How sensitive the camera is to incoming light.

Explanation:

8 0
3 years ago
Read 2 more answers
Software obtained illegally is called open-source software. true / false
Oxana [17]
False, software obtained illegally is called Pirated Software.
<span>Open source software is software developed by and for the user community, ie. Linux based software is Open Source.</span>
3 0
3 years ago
Which type of computer serves as the heart of the computing systems for many, perhaps most, major corporations and government ag
Nezavi [6.7K]

Answer:

Mainframes

Explanation:

Mainframes are utilized by many major corporations and government agencies. They are also used in banking, accounting, and healthcare to name a few.

4 0
2 years ago
Are all the computer users known as programmer ​
Evgesh-ka [11]

Answer:

Nope

Explanation:

programmers are diff

6 0
2 years ago
Greg works for online games development company. He occasionally visits online literature sites and downloads e-books of his cho
zalisa [80]

(A) Yes, because nobody is supposed to access non-work related sites during office hours.

3 0
3 years ago
Read 2 more answers
Other questions:
  • What microsoft operating systems started the process of authenticating using password and username
    14·1 answer
  • How has science fiction influenced technology
    7·2 answers
  • Integration Management, one of the 10 PMBOK Guide Knowledge Areas, represents the processes and activities to identify, define,
    12·1 answer
  • What do Business Analysis workers do? Check all that apply.
    15·2 answers
  • Your company decided to upgrade the older office Ethernet network and needs the fastest speed possible but has decided against f
    8·1 answer
  • Choose a problem that lends to an implementation that uses dynamic programming. Clearly state the problem and then provide high-
    10·1 answer
  • Additional metadata data is stored alongside the binary colour values for each pixel. Give two examples of metadata?
    9·1 answer
  • Terence creates software requirements specification (SRS) documents for various software development projects. In which phase of
    6·1 answer
  • A web application with an SQL server database is found to be compromised by an attacker. On examination, the email IDs of the da
    5·1 answer
  • How can i find these services
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!