60 426
Assignments Done
98,1%
Successfully Done
In April 2018

Answer to Question #59273 in Java | JSP | JSF for Peter

Question #59273
Question: Create the following class in Java as specified in the UML diagram below:

SimpleCalc

+ SimpleCalc()
+ add(int, int):int
+ subtract (int, int):int
+ multiply (int, int): int
+ divide (int, int): double

• Create an application program (useCalc.java) with a main method. Within this method instantiate/create an object of SimpleCalc and test all four of its methods. Run the useCalc.java class.
Expert's answer

public class useCalc {
public static void main(String[] args) {
int a = 10, b = 3;
System.out.println("a = " + a);
System.out.println("b = " + b);
SimpleCalc calc = new SimpleCalc();
System.out.println("a + b = " + calc.add(a,b));
System.out.println("a - b = " + calc.subtract(a,b));
System.out.println("a * b = " + calc.multiply(a,b));
System.out.println("a / b = " + calc.divide(a,b));
}
}


public class SimpleCalc {

public SimpleCalc(){}

public int add(int a, int b){
return a + b;
}

public int subtract (int a, int b){
return a - b;
}
public int multiply (int a, int b){
return a * b;
}
public double divide (int a, int b){
return (double)a / b;
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions