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

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Java language, solve question 3

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
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY