Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a java program a + b; a - b; a * b; a/b where a and b can be either positive or negative integers.

write a java program

a + b; a - b; a * b; a/b

where a and b can be either positive or negative integers. There may be spaces or no space between a and a valid arithmetic operation and also similarly between the valid arithmetic operation and b. Some valid examples are given below:

a + b, a + -b, a+ -b, a +-b, a+-b

-a + b, -a + -b, -a+ -b, -a +-b, -a+-b

a - b, a - -b, a- -b, a --b, a--b

-a - b, -a - -b, -a- -b, -a --b, -a--b

a * b, a * -b, a* -b, a *-b, a*-b

-a * b, -a * -b, -a* -b, -a *-b, -a*-b

a / b, a / -b, a/ -b, a /-b, a/-b

-a / b, -a / -b, -a/ -b, -a /-b, -a/-b

Your program should detect any non valid arithmetic operations by informing the user its an invalid arithmetic operator and prompting the user to retry. A maximum of three tries are given to the user and the program terminates when the user exceeds the number of tries.

In addition to the main class create two classes in this program: addSubtract and multiplyDivide.

In the main class, the program reads the user entry and first determines if the entry is valid. Next, it determines the integers a and b and also the sign of the operation. Based on the sign, they are then passed on to one of the classes.

In both addSubtract and multiplyDivide classes the arithmetic operations are carried out and also the result of the operation is printed.

In the multiplyDivide class, the output is in a Double format.

An important function in the developed program solution is testing. Your program should test for all possible valid data entries and invalid ones too. Some of the valid ones are given below

Replace a and b with any values not exceeding 1000.

a + b, a + -b, a+ -b, a +-b, a+-b

-a + b, -a + -b, -a+ -b, -a +-b, -a+-b

a - b, a - -b, a- -b, a --b, a--b

-a - b, -a - -b, -a- -b, -a --b, -a--b

a * b, a * -b, a* -b, a *-b, a*-b

-a * b, -a * -b, -a* -b, -a *-b, -a*-b

a / b, a / -b, a/ -b, a /-b, a/-b

-a / b, -a / -b, -a/ -b, -a /-b, -a/-b

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions