Question
I need help creating a new class MathOP2 that Inherits from MathOP. I need to add multiply method and divide method, both methods accepting two
I need help creating a new class MathOP2 that Inherits from MathOP. I need to add multiply method and divide method, both methods accepting two parameters and return a value.
And creating a test program with documentation to test all operators (+, -, /, and *)
Here is my MathOP so far:
class MathOP { int MathAdd(float a,float b) {
return (int) (a+b); }
int MathSub(float a,float b) {
return (int) (a-b); } }
And here is my Test program thus far:
import java.util.Scanner; class TestMathOP {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
System.out.print("Enter the First number:");
float first = sc.nextFloat();
System.out.print("Enter the Second number:");
float second = sc.nextFloat();
System.out.print("Enter Operator:"); MathOP c = new MathOP();
char choice=sc.next().charAt(0); //Output answers if(choice== '+') {
System.out.print("The answer is: "+c.MathAdd(first, second)); } else { System.out.print("The answer is: "+c.MathSub(first, second));
} System.out.print(" Do you want another operation (Y/N)? ");
if(sc.next().charAt(0)=='N') {
System.out.println("Thanks for using our system");
break;
}
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started