Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exercise1;
- import acm.program.ConsoleProgram;
- public class ConsoleComp1 extends ConsoleProgram {
- private double perform_operation (double a, double b, String c) {
- double d = 0;
- if (c == "+") {
- d = a+b;
- }
- if (c == "-") {
- d = a-b;
- }
- if (c == "*") {
- d = a*b;
- }
- if (c == "/") {
- d = a/b;
- }
- if (c == "%") {
- d = a%b;
- }
- return d;
- }
- public void run () {
- System.out.println("Please enter your first number: ");
- double a = readDouble();
- System.out.println("Please enter your second number: ");
- double b = readDouble();
- System.out.println("Please enter your operator (+,-,*,/,%): ");
- String c = readLine();
- System.out.println("the value of c is " +c);
- double d = perform_operation(a,b,c);
- System.out.println("The answer to your input is: " +d);
- }
- }
Add Comment
Please, Sign In to add comment