1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import java.util.Scanner;
  2. /**
  3. * Basic class to perform basic functions for our Graphing Calculator
  4. * (+, -, *, /)
  5. * Lauren Green
  6. * 10/19/18
  7. */
  8. public class Basic
  9. {
  10. int input1 = 0;
  11. int input2 = 0;
  12. int answer;
  13. public Basic()
  14. {
  15. boolean validInput = false;
  16. while(!validInput) {
  17. //Get input of first number
  18. input1 = Console.getIntegerInput("What is the first number?");
  19. //Get input of type of function
  20. String operation = Console.getStringInput("Which operation would you like to perform? \n +, -, *, /");
  21. //Get input of second number
  22. input2 = Console.getIntegerInput("What is the second number?");
  23. //Do the math depending on the input.
  24. if (operation.equals("+")) {
  25. answer = input1 + input2;
  26. System.out.println(answer);
  27. validInput = true;
  28. } else if (operation.equals("-")) {
  29. answer = input1 - input2;
  30. System.out.println(answer);
  31. validInput = true;
  32. } else if (operation.equals("*")) {
  33. answer = input1 * input2;
  34. System.out.println(answer);
  35. validInput = true;
  36. } else if (operation.equals("/")) {
  37. answer = input1 / input2;
  38. System.out.println(answer);
  39. validInput = true;
  40. } else {
  41. System.out.println("Error, try again \n");
  42. }
  43. }
  44. //Insert return to main menu.
  45. }
  46. }