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(“nDo you want another operation (Y/N)? “);
if(sc.next().charAt(0)==’N’)
{
System.out.println(“Thanks for using our system”);
break;
}
}
}
}