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
Que se encarga de notar lo que pasa alrededor
Angelina_Jolie [31]

Answer: Es nuestro cerebro. Los ojos son las estructuras capaces de transformar las señales luminosas en impulsos eléctricos, los cuales viajan al cerebro y, una vez ahí, él se encarga de transformar estas señales eléctricas en lo que vemos realmente. Y lo mismo pasa con todos los otros sentidos.

Explanation:

7 0
3 years ago
What characteristics need to be exhibited by an organisation to improve its software process?
aalyn [17]

Answer:  Defined , Controllable ,  Measured , Effective ,  Institutionalized are some of the characteristics needed to be exhibited by an organisation to improve its software process

Explanation:

Software process improvement(SPI)  helps in achieving goals of software products for an organization. Some of its characteristics are Defined , Controllable ,  Measured , Effective ,  Institutionalized.

It goals must be defined, and must also be controlled and it performance must be measured at regular intervals and any reforms carried out to achieve goals must be effective. Lastly it should implement all goals in an institutional framework to be followed by every one in the organization.

6 0
3 years ago
Differences between analog computer and hybrid computer​
aleksandrvk [35]

Answer:

Analog computers only work with continuous numerical data in analog quantities, digital computers can process both non-numerical and numerical data and a hybrid computer is a combination of both analog and digital. A hybrid computer has the accuracy of a digital computer paired with speed of an analog one.

5 0
2 years ago
Read 2 more answers
What type of device can be used to block unwanted traffic initiated from the internet and can also restrict internet access from
statuscvo [17]
It is the firewall exactly.
4 0
2 years ago
The spreadsheet below shows how much money each store raised for charity during the months of January, February, and March. A1:
Elenna [48]

Answer:

B2:B4

Explanation:

6 0
2 years ago
Read 2 more answers
Other questions:
  • Write a for loop that iterates from 1 to numbersamples to double any element's value in datasamples that is less than minvalue.
    15·1 answer
  • According to the partnership for 21st-century learning critical thinking ability includes all the following skills except
    15·1 answer
  • Although the original BBS system was simple, it increased people's ability to communicate
    14·1 answer
  • What was the impact of the rise of the Japanese auto industry and the semiconductor industry in south eastern​ Asia? A. It incre
    13·1 answer
  • Briefly define "address space" and discuss its major tradeoffs (advantages/costs). What problem is it addressing?
    10·1 answer
  • write a program in C# that reads a set of integers and then finds and prints the sum of the even and odd integers?​
    12·1 answer
  • Please help I’m not trying to fail
    7·2 answers
  • What is the best food to eat before workout? why?​
    10·2 answers
  • 2. How can Tailwind Traders ensure applications use geo-redundancy to create highly available storage applications?
    10·1 answer
  • What are the different elements of a window?​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!