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.
1
Expert's answer
2016-04-19T10:22:05-0400

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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS