Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CODE IN JAVA, PLEASE USE UML DIAGRAM Declare and use methods that return a value

ID: 669645 • Letter: C

Question

CODE IN JAVA, PLEASE USE UML DIAGRAM

Declare and use methods that return a value

Declare and use methods with multiple parameters

Write a class declaration based on a class diagram

Test the class by creating an instance of the class and by calling the methods declared in the class

Description:

Create a project called LabCalculator
The project has 2 classes: Calculator and CalculatorApp
Declare class Calculator based on the description in the class diagram

In class CalculatorApp create the main method. Inside main do the following:
Create an instance of Calculator
Allow the user to enter 2 numbers

Use the methods of class Calculator to calculate the sum, difference, and product of the numbers entered by the user.
Print the results (see output)

+ add (lhs: int, rhs: int) : int

+ subtract (lhs: int, rhs: int) : int

+ multiply (lhs: int, rhs: int) : int

CALCULATOR .

+ add (lhs: int, rhs: int) : int

+ subtract (lhs: int, rhs: int) : int

+ multiply (lhs: int, rhs: int) : int

Explanation / Answer

import java.util.Scanner; public class CALCULATOR{ int add(int a, int b) { int answer = a+b; return answer; } int subtract(int a, int b) { int answer = a-b; return answer; } int multiply(int a, int b) { int answer= a*b; return answer; } } public class CalculatorApp { public static void main(String[] args) { Scanner input = new Scanner(System.in); CALCULATOR cal = new CALCULATOR(); int answer = 0; int inputA, inputB; System.out.print("Please enter your numbers: "); inputA = input.nextInt(); inputB = input.nextInt(); answer = cal.add(inputA, inputB); System.out.print("Addition is: "+answer); answer = cal.subtract(inputA, inputB); System.out.print("Substraction is: "+answer); answer = cal.multiply(inputA, inputB); System.out.print("Multiplication is: "+answer); input.close(); } } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote