Guest User

Untitled

a guest
May 27th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. package exercise1;
  2.  
  3. import acm.program.ConsoleProgram;
  4.  
  5. public class ConsoleComp1 extends ConsoleProgram {
  6.     private double perform_operation (double a, double b, String c) {
  7.         double d = 0;
  8.         if (c == "+") {
  9.             d = a+b;
  10.         }
  11.         if (c == "-") {
  12.             d = a-b;
  13.         }
  14.         if (c == "*") {
  15.             d = a*b;
  16.         }
  17.         if (c == "/") {
  18.             d = a/b;
  19.         }
  20.         if (c == "%") {
  21.             d = a%b;
  22.         }
  23.         return d;
  24.     }
  25.    
  26.     public void run () {
  27.     System.out.println("Please enter your first number: ");
  28.     double a = readDouble();
  29.     System.out.println("Please enter your second number: ");
  30.     double b = readDouble();
  31.     System.out.println("Please enter your operator (+,-,*,/,%): ");
  32.     String c = readLine();
  33.     System.out.println("the value of c is " +c);
  34.     double d = perform_operation(a,b,c);
  35.     System.out.println("The answer to your input is: " +d);
  36.    
  37.     }
  38. }
Add Comment
Please, Sign In to add comment