Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Describe two techniques for validating a domain mode

Answered: 1 week ago