English Language Calculator Build a simple “English Language” calculator that does the following: Takes three inputs from the keyboard Two of the inputs are single-digit numbers (0 to 9) The third input is a char from the keyboard, representing one of the five operations from the keyboard: + (addition) - (subtraction) * (multiplication) / (division) ^ (exponentiation) Output the description of the operation in plain English, as well as the numeric result   Input and Output Instruction for the Calculator If the two input numbers are 5 and 3, and the operation is *, then the output should be five multiplied by three is 15 Note that the result is given as a number, not a word. If the two numbers are 2 and 9, and the operation is -, then the output should be two minus nine is -7 If the two numbers are 5 and 2, and the operation is ^, then the output should be five to the power two is 25 Hint: To perform the exponentiation, use the pow method of the Math class. If the two numbers are 5 and 0, and the operation is /, then the output should be Division by zero is not allowed Here the operation will not be performed. If the two numbers are 25 and 3, and the operation is +, then the output should be Invalid number Because 25 has two digits If the two numbers are 6 and 2, and the operation is /, then the output should be six divided by two is 3 If the two numbers are 2 and 3, and the operation is +, then the output should be two plus three is 5 If the two numbers are 23 and 3, and the operation is &, then the output should be Invalid operation and Invalid Number For the operations, they should be translated into English as follows: + plus - minus * multiplied by / divided by ^ to the power Hint: You should use the switch-case selection statement to translate the input values into words.   Special Situations You need to consider some special situations: For division, there is a special constraint: you cannot divide by 0, and you should therefore test whether the second number is 0. If it is 0, then you should output a message saying that you are not allowed to divide by zero. The “operator” is not one of the preceding five operators, in that case, output a message saying that the operator is not a valid one. Anyone or both of the input numbers is not a valid single-digit number: again, you should output a message saying an invalid number. Both operation and the numbers can be invalid in that case output a message accordingly.   Hint: you can deal with these special situations in the default statement of the switch block and possibly use some boolean variables to keep track of this information, as you may need it later in your program. You can also use if-else statements inside the switch-case blocks if needed.   Coding Instruction Create an HW4 project. Create a class EnglishLanguageCalculator in the project. Inside this class, you will have your main method, write all your code inside the main method.

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter8: Advanced Data Handling Concepts
Section: Chapter Questions
Problem 7PE
icon
Related questions
Question

English Language Calculator

Build a simple “English Language” calculator that does the following:

  • Takes three inputs from the keyboard
  • Two of the inputs are single-digit numbers (0 to 9)
  • The third input is a char from the keyboard, representing one of the five operations from the keyboard:
    • + (addition)
    • - (subtraction)
    • * (multiplication)
    • / (division)
    • ^ (exponentiation)
  • Output the description of the operation in plain English, as well as the numeric result

 

Input and Output Instruction for the Calculator

  • If the two input numbers are 5 and 3, and the operation is *, then the output should be

five multiplied by three is 15

Note that the result is given as a number, not a word.

  • If the two numbers are 2 and 9, and the operation is -, then the output should be

two minus nine is -7

  • If the two numbers are 5 and 2, and the operation is ^, then the output should be

five to the power two is 25

Hint: To perform the exponentiation, use the pow method of the Math class.

  • If the two numbers are 5 and 0, and the operation is /, then the output should be

Division by zero is not allowed

Here the operation will not be performed.

  • If the two numbers are 25 and 3, and the operation is +, then the output should be

Invalid number

Because 25 has two digits

  • If the two numbers are 6 and 2, and the operation is /, then the output should be

six divided by two is 3

  • If the two numbers are 2 and 3, and the operation is +, then the output should be

two plus three is 5

  • If the two numbers are 23 and 3, and the operation is &, then the output should be

Invalid operation and Invalid Number

For the operations, they should be translated into English as follows:

  • + plus
  • - minus
  • * multiplied by
  • / divided by
  • ^ to the power

Hint: You should use the switch-case selection statement to translate the input values into words.

 

Special Situations

You need to consider some special situations:

  • For division, there is a special constraint: you cannot divide by 0, and you should therefore test whether the second number is 0. If it is 0, then you should output a message saying that you are not allowed to divide by zero.
  • The “operator” is not one of the preceding five operators, in that case, output a message saying that the operator is not a valid one.
  • Anyone or both of the input numbers is not a valid single-digit number: again, you should output a message saying an invalid number.
  • Both operation and the numbers can be invalid in that case output a message accordingly.

 

Hint: you can deal with these special situations in the default statement of the switch block and possibly use some boolean variables to keep track of this information, as you may need it later in your program. You can also use if-else statements inside the switch-case blocks if needed.

 

Coding Instruction

Create an HW4 project. Create a class EnglishLanguageCalculator in the project. Inside this class, you will have your main method, write all your code inside the main method.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 11 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage