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
Why wont my account update from Expert to Ace? I have all the points and branliests to be Ace but it wont update
grin007 [14]

Answer:

Maybe you don't have all the points and brainliests needed. Double check and if you actually don't, try to reload your device. If it still isn't working, there is something wrong with your device.

Explanation:

PLEASE MARK ME AS BRAINLIEST I REALLY WANT TO LEVEL UP

8 0
2 years ago
Read 2 more answers
To get a page from the Web, a user must type in a URL, which stands for: a. Unknown Resource Locator b. Unknown Router Location
Afina-wow [57]

Answer:

Hey! The answer you're looking for is D. Uniform Resource Locator.

3 0
3 years ago
Epic is fuzzy-figure8
prohojiy [21]

Answer:

Mine is Chachee_girl if u wanna play

8 0
2 years ago
Read 2 more answers
// isOrdered
yarga [219]

Answer:

honestly i dont know but I used to have computer programming classes on java and I'd get all my answers from repl.it forums. Wist you best of luck!!

6 0
3 years ago
10. In cell R8, enter a formula using the AVERAGEIF function to determine the average number of post-secondary years for student
mart [117]

Answer:

On cell R8, type in the formula  "=AVERAGEIF(M2:M31,"Elected",D2:D31)".

Explanation:

Microsoft Excel is a spreadsheet application developed by Microsoft as a part of the office package, used for statistical analysis of data. It has several tools used for this purpose.

The AVERAGEIF function is used to give the average of numeric column based on a condition. The formula above uses the word 'Elected' in the M column to calculate the average of numbers in the D column.

7 0
3 years ago
Other questions:
  • You have just replaced the NIC on a server, making no other changes. It can communicate with all the computers on its network bu
    14·1 answer
  • JavaBeans are?A special Java classfileServletsAppletsA Special form of JSPNone of Given
    8·1 answer
  • Select the correct answer.
    6·1 answer
  • What landforms are likely to form at this boundary
    15·1 answer
  • Web résumés are posted to the Internet in HTML format.<br> true or false
    9·2 answers
  • Electronic mail is best used to:
    5·2 answers
  • An array, numbers, of integers is filled with 100 random numbers whose values are greater than 10 and less than 255. You DO NOT
    7·1 answer
  • Select the correct answer.
    13·1 answer
  • Match the parts of the website address with its correct explanation. http://www.usa.gov/Agencies/federal.shtm/​
    5·2 answers
  • What is malware? What are some signs that malware may be impacting the performance of your computer? How can you avoid malware?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!