Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you add the multiply and divide method? both methods accept two parameters and return a value. import java.util.Scanner; class TestMathOP { public static void

Can you add the multiply and divide method? both methods accept two parameters and return a value.

import java.util.Scanner;

class TestMathOP { public static void main(String anrg[]) { int firstNum, secondNum, sum; char response; char operator;

Scanner data = new Scanner(System.in); /*********************** Purpose: Creating Object to recieve inputs from user ************************/ do // do while loop { /******************* Purpose: Deginning of do while loop **********************/ System.out.println(" ---Week #4 Assignment --- "); System.out.println(" + Add,Subtract -, * Multiply, / Divide ");

System.out.println("Enter two numbers! "); System.out.println("Enter first number>>"); firstNum = data.nextInt(); /*********************** Asking the user for the first number they'd like to add *********************************/ System.out.println(" Enter second number>>"); secondNum = data.nextInt(); // 2nd number for user input// System.out.println("Enter +, -, *, / operator>>"); operator = data.next().charAt(0);

if(operator == '+') { sum = MathAdd(firstNum, secondNum); System.out.println("The answer is =" + sum); } else if(operator == '-') { sum = MathSub(firstNum, secondNum); System.out.println("Thw answer is =" + sum); } else { System.out.println(" Sorry, you did not select either the + or - operator"); }

System.out.println(" Do you want another operation (Y/N) ?"); response = data.next().charAt(0); if(response == 'N') { System.out.println(" Thanks for using our system"); } else { System.out.println(" Lets do this again!"); continue; }

} while(response != 'N'); //do while loop }

public static int MathAdd(int num1, int num2) { int add; add = num1 + num2; return add; } // end MathAdd method

public static int MathSub(int num1, int num2) { int sub; sub = num1 - num2; return sub;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Below is the updated code that includes the MathMultiply and MathDivide methods to perform multiplic... 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

Java How To Program Late Objects Version

Authors: Paul Deitel, Deitel & Associates

8th Edition

0136123716, 9780136123712

More Books

Students also viewed these Programming questions