Question

Create a new class MathOP2 (MathOP2.java) that Inherits from MathOP You need to add multiply method...

Create a new class MathOP2 (MathOP2.java) that Inherits from MathOP

You need to add multiply method and divide method, both methods accepts two parameters and return a value.

Create a test program with documentation to test all operators (at least 4)

The TestMathOP should do the following

     Enter the First number >> 5.5

     Enter the Second Number >> 7.5

     The sum of the numbers is 13

     The subtract of the two numbers is -2.00

     Do you want to exist (Y/N)?

        // If Yes print "Thanks for using our system"

       // If No run the program again

5) Modify the code to prompt you for the operation so it will look like this

    Enter the First number >> 5.5

      Enter the Second Number >> 7.5

      Enter operator >> +

      The answer is 13

      Do you want another operation (Y/N)?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

TestOP code (Before modification) :

import java.util.Scanner;
public class TestMathOP {
public static void main(String args[]){
boolean status = true;
Scanner obj = new Scanner(System.in);
while(status){
System.out.println("Enter the First number >> ");
float a = obj.nextFloat();
System.out.println("Enter the Second number >> ");
float b = obj.nextFloat();
System.out.println("The sum of the numbers is "+(a+b));
System.out.println("The subtract of the two numbers is "+(a-b));
System.out.println("Do you want to exist (Y/N)");
obj.nextLine();
String yes = obj.nextLine();
if(yes.equals("Y")){
System.out.println("Thanks for using our system");
}
else{
break;
}
}
}
}

Screenshot of TestOP code :

import java.util.Scanner; public class TestMathoP ( public static void main (String args[]) boolean statustrue; scanner obj nOutput :

Enter the First number>> 5.5 Enter the Second number > 7.5 The sum of the numbers is 13.0 The subtract Do you want to exist (

TestMathOP Code (After Modification ) :

import java.util.Scanner;
public class TestMathOP {
public static void main(String args[]){
boolean status = true;
Scanner obj = new Scanner(System.in);//declaring scanner object
while(status){//while true runs he loop untill break occurs
System.out.println("Enter the First number >> ");//print statement
float a = obj.nextFloat();//takes first number from user
System.out.println("Enter the Second number >> ");//print statement
float b = obj.nextFloat();//takes second number from user
obj.nextLine();//consumes input line
System.out.println("Enter operator >>");//print statement
String op = obj.nextLine();//takes input character
if(op.equals("+"))
System.out.println("The answer is "+(a+b));//prints addition value
else
System.out.println("The answer is "+(a-b));//prints value
System.out.println("Do you want to exist (Y/N)");//print statement
obj.nextLine();//to consume new line
String yes = obj.nextLine();//takes input y/n from user
if(yes.equals("Y"))//if entered choce is yes
System.out.println("Thanks for using our system");
else//else stop the loop
break;
}
}
}

Screenshot of code :

import java.util.Scanner public class TestMathOP f public static void main (String args[]) boolean statustrue Scanner obj - nOUTPUT :

Enter the First number>> 5.5 Enter the Second number > 7.5 Enter operator The answer is 13.0 Do you want to exist (Y/N)

MathOP2 Code :

import java.util.Scanner;
class MathOP{
public float MathAdd(float a,float b){//addition method
return a+b;//return statement
}
public float MathSub(float a,float b){//subtraction method
return a-b;//return statement
}
}

public class MathOP2 extends MathOP {
public float Mathmult(float a,float b){//multiplication method
return a*b;//return statement
}
public float Mathdiv(float a,float b){//division method
return a/b;//return statement
}
public static void main(String args[]){//inherits class MathOP
Scanner obj = new Scanner(System.in);//scanner object
System.out.println("Enter the First number >> ");//print statement
float a = obj.nextFloat();//takes first number from user
System.out.println("Enter the Second number >> ");//print statement
float b = obj.nextFloat();//takes second number from user
MathOP mop = new MathOP();//creating object for class MathOP
MathOP2 mop2 = new MathOP2();//creating object for class MathOP2
System.out.println(" sum is"+mop.MathAdd(a, b));//printing sum value returned from method
System.out.println(" Difference is"+mop.MathSub(a, b));//printing difference value returned from method
System.out.println(" multiplication is"+mop2.Mathmult(a, b));//printing multiplication value returned from method
System.out.println(" Division is"+mop2.Mathdiv(a, b));//printing division value returned from method
}
}

Screenshot :

import java.util.Scanner; class MathOP public float MathAdd (float a, float b)t//addition method return atb//return statement

public class MathOP2 extends MathoP i public float Mathmult (float a,float b)//multiplication method return ab//return statem

Output :

Enter the Second number > 7.5 sum is13.0 Difference is-2.0 multiplication is41.25 Division is0.73333335

Note :

  • MathOP2  specification is not cleared.
Add a comment
Know the answer?
Add Answer to:
Create a new class MathOP2 (MathOP2.java) that Inherits from MathOP You need to add multiply method...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using C#, create a class in a file MathOP.cs. MathOP.cs needs to include the following methods MathAdd: to add two numb...

    Using C#, create a class in a file MathOP.cs. MathOP.cs needs to include the following methods MathAdd: to add two numbers MathSub: to subtract two numbers Next, create a new class MathOP2 (MathOP2.cs) that Inherits from MathOP.cs. MathOP2.cs needs to include the following methods MathMult: to multiply two numbers MathDiv: to divide two numbers Allinone: accepts two parameters and set 4 class variables: v_add, v_subtract, v_multiply, and v_divide and show how these values are retrieved. Finally, create a program TestMathOP.cs...

  • Create a 'simple' calculator. The calculator should be able to add, subtract, multiply, and divide two...

    Create a 'simple' calculator. The calculator should be able to add, subtract, multiply, and divide two numbers. You can use whatever format you want to receive the numbers (such as textboxes). You also can use whatever method (such as a button for each operation +, -, *, /) to determine what operation the user wants to accomplish. The output should be displayed in a similar format to "1 + 2 = 3" or "1 - 2 = -1". Make sure...

  • Please make a JAVA program for the following using switch structures Write a program that simulates...

    Please make a JAVA program for the following using switch structures Write a program that simulates a simple Calculator program. The program will display menu choices to the user to Add, Subtract, Multiply and Divide. The program will prompt the user to make a selection from the choices and get their choice into the program. The program will use a nested if….else (selection control structure) to determine the user’s menu choice. Prompt the user to enter two numbers, perform the...

  • Create a ComplexNo class for two imaginary numbers. Provide (in addition to add, subtract, multiply, and...

    Create a ComplexNo class for two imaginary numbers. Provide (in addition to add, subtract, multiply, and divide methods) a method for equals (which returns boolean), and toString( ) method (that returns a string representing the receiving object). Throw an exception if an attempt is made to divide by 0 (0 + 0i). Your implementation should return the results of each operation WITHOUT changing the operands. Exxample: Enter the first complex number's real part => 1.0 Enter the first complex number's...

  • Write a calculator that will give the user this menu options: 1)Add 2)Subtract 3)Multiply 4)Divide 5)Exit...

    Write a calculator that will give the user this menu options: 1)Add 2)Subtract 3)Multiply 4)Divide 5)Exit . Your program should continue asking until the user chooses 5. If user chooses to exit give a goodbye message. After the user selections options 1 - 4, prompt the user for two numbers. Perform the requested mathematical operation on those two numbers. Round the result to 1 decimal place. Please answer in python and make it simple. Please implement proper indentation, not just...

  • With this program you are going to design a math practice program for younger users. You...

    With this program you are going to design a math practice program for younger users. You will ask the user to enter two numbers. Only numbers may be entered. If the user enters a word, the program should disregard the entry and wait for an integer entry. There will not be another prompt if the user enters data other than whole numbers (integers). Here is a sample run: Your static methods should accept two integers and return an integer. Do...

  • Create a C++ calculator that allows you to add, multiply, divide, or subtract, and allows you...

    Create a C++ calculator that allows you to add, multiply, divide, or subtract, and allows you to inlcude an infinite amount of inputted numbers for it.

  • Write another program called calculator that inherits from class average and also has methods that has:...

    Write another program called calculator that inherits from class average and also has methods that has: two methods multiply() to calculate the product of the numbers. One method will have two parameters which are both ints. The second method has three parameters: two ints and a Double. Another method “Power” that finds the power of a number using methods. For example, if the user types in: 5 and 3, the program should print out 125. 3. And another method “Factorial”...

  • Write another program called calculator that inherits from class average and also has methods that has:...

    Write another program called calculator that inherits from class average and also has methods that has: two methods multiply() to calculate the product of the numbers. One method will have two parameters which are both ints. The second method has three parameters: two ints and a Double. Another method “Power” that finds the power of a number using methods. For example, if the user types in: 5 and 3, the program should print out 125. 3. And another method “Factorial”...

  • CE – Return and Overload in C++ You are going to create a rudimentary calculator. The...

    CE – Return and Overload in C++ You are going to create a rudimentary calculator. The program should call a function to display a menu of three options: 1 – Integer Math 2 – Double Math 3 – Exit Program The program must test that the user enters in a valid menu option. If they do not, the program must display an error message and allow the user to reenter the selection. Once valid, the function must return the option...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT