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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education