2. A method named isAnOperation that takes a character and returns true if the character is one of the operations +, -, *, /, %, and false otherwise.

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter7: Using Methods
Section: Chapter Questions
Problem 1E: Create a C# statement that uses each of the following built-in methods you have used in previous...
icon
Related questions
Question

solve question 2, Java

1. A method named isANumber that takes a character and returns true if the character is a
number (1-9) and false otherwise.
2. A method named isAnOperation that takes a character and returns true if the character
is one of the operations +, -, *, /, %, and false otherwise.
3. A method named getResult that takes three characters: the first two must contain
numbers (1-9), the third must contain one of the five operations: +, -, *, /, %. The method
returns a String that includes the two numbers, the operation, and the result. It must make
sure that the first two characters are numbers by invoking the isANumber method, and
that the third character is one of the valid operations by invoking the isAnOperation
method. If not, it must return the statement “Invalid Input!".
For example, if the first two characters contain the numbers '3' and 4', and the operation
+ is passed to the method it must return the following String:
3+4=7
4. In your main method, define a character named operation and initialize it with one of
the characters: +, -, *, /, %. Iterate over the characters from 1' to '9', print out the result
of performing the operation defined in operation for each one of them with the characters
from '1' to '9', each on a separate line. Test your code by changing the operation
variable for the five possible operations.
Note: use the printf method with %s to make your output aligned, such that each arithmetic
statement takes 8 fields.
Your output must look something like this (example if operation is +).
1+1=2 1+2=3 1+3=4 1+4=5 1+5=6
.... .....
2+1=3 2+2=4 _2+3=5 2+4=6 2+5=7
9+1=10 9+2=11 9+3=12 9+4=13 9+5=14
..... ...
Transcribed Image Text:1. A method named isANumber that takes a character and returns true if the character is a number (1-9) and false otherwise. 2. A method named isAnOperation that takes a character and returns true if the character is one of the operations +, -, *, /, %, and false otherwise. 3. A method named getResult that takes three characters: the first two must contain numbers (1-9), the third must contain one of the five operations: +, -, *, /, %. The method returns a String that includes the two numbers, the operation, and the result. It must make sure that the first two characters are numbers by invoking the isANumber method, and that the third character is one of the valid operations by invoking the isAnOperation method. If not, it must return the statement “Invalid Input!". For example, if the first two characters contain the numbers '3' and 4', and the operation + is passed to the method it must return the following String: 3+4=7 4. In your main method, define a character named operation and initialize it with one of the characters: +, -, *, /, %. Iterate over the characters from 1' to '9', print out the result of performing the operation defined in operation for each one of them with the characters from '1' to '9', each on a separate line. Test your code by changing the operation variable for the five possible operations. Note: use the printf method with %s to make your output aligned, such that each arithmetic statement takes 8 fields. Your output must look something like this (example if operation is +). 1+1=2 1+2=3 1+3=4 1+4=5 1+5=6 .... ..... 2+1=3 2+2=4 _2+3=5 2+4=6 2+5=7 9+1=10 9+2=11 9+3=12 9+4=13 9+5=14 ..... ...
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
C-string
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
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,