Advertisement
Guest User

code

a guest
Apr 3rd, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. import comp102x.IO;
  2. import java.util.Scanner;
  3. /**
  4. * Write a description of class Calculator here.
  5. *
  6. * @author (your name)
  7. * @version (a version number or a date)
  8. */
  9. public class Calculator
  10. {
  11. Scanner user_input = new Scanner(System.in);
  12. int a=0,b=0;
  13. int answer = 0;
  14. String op = "Continue";
  15. public void numbers() {
  16. IO.outputln("a = ");
  17. a = user_input.nextInt();
  18. IO.outputln("b = ");
  19. b = user_input.nextInt();
  20. IO.outputln("add/sub/mul/div/rem");
  21. String Menu = user_input.next();
  22. if (Menu.equals("add")) {
  23. answer = a + b;
  24. }
  25. else if (Menu.equals("sub")) {
  26. answer = a - b;
  27. }
  28. else if (Menu.equals("mul")) {
  29. answer = a * b;
  30. }
  31. else if (Menu.equals("div")) {
  32. answer = a / b;
  33. }
  34. else if (Menu.equals("rem")) {
  35. //this is where I want it to divide with a remainder.
  36. }
  37. System.out.println("a = " + a + "," + " b = " + b + ", function = " + Menu);
  38. System.out.println("Answer = " + answer);
  39. System.out.println("What is your option? Continue or Exit");
  40. op = user_input.next();
  41. if (op.equals("Continue")) {
  42. numbers();
  43. }
  44. if (op.equals("Exit")) {
  45. user_input.close();
  46. System.exit(0);
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement