Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. public static void main(String[] args) {
  2.  
  3. String FirstNumber = "1";
  4. String SecondNumber = "1";
  5. String method = "add";
  6. int finalNumber = 0;
  7.  
  8. // makes the strings and ints
  9.  
  10. FirstNumber = JOptionPane.showInputDialog(null, "What is the First number?");
  11. SecondNumber = JOptionPane.showInputDialog(null, "What is the Second number?");
  12. method = JOptionPane.showInputDialog(null, "Would you like to add, subtract, multiply, or divide them? You can also type exit to exit the program.");
  13.  
  14. exitProgram(method);
  15.  
  16. int firstNumber = Integer.valueOf(FirstNumber);
  17. int secondNumber = Integer.valueOf(SecondNumber);
  18.  
  19. // takes in the inputs
  20. // sets the string equal to ints
  21.  
  22. JOptionPane.showMessageDialog(null,
  23. "The first number is " + firstNumber + " and the second number is " + secondNumber);
  24.  
  25. methodsCalculator(firstNumber, secondNumber, method, finalNumber);
  26.  
  27.  
  28. }
  29.  
  30. public static String exitProgram(String method){
  31.  
  32. if (method.equals("exit")){
  33. JOptionPane.showMessageDialog(null, "This program will now shut down");
  34. System.exit(0);
  35. }
  36.  
  37. //by using the system.exit this program will end if method equals exit
  38.  
  39. return method;
  40. }
  41.  
  42. public static int methodsCalculator(int firstNumber, int secondNumber, String method, int finalNumber) {
  43.  
  44. // finds the correct method and does the operation
  45. // it also outputs the result
  46.  
  47. if (method.equals("add")) {
  48. JOptionPane.showMessageDialog(null, "They are going to be Added");
  49. finalNumber = firstNumber + secondNumber;
  50.  
  51. JOptionPane.showMessageDialog(null, "The answer is " + finalNumber);
  52.  
  53. return finalNumber;
  54. }
  55.  
  56. if (method.equals("subtract")) {
  57. JOptionPane.showMessageDialog(null, "They are going to be Subtracted");
  58. finalNumber = firstNumber - secondNumber;
  59.  
  60. JOptionPane.showMessageDialog(null, "The answer is " + finalNumber);
  61.  
  62. return finalNumber;
  63. }
  64.  
  65. if (method.equals("multiply")) {
  66. JOptionPane.showMessageDialog(null, "They are going to Multiply");
  67. finalNumber = firstNumber * secondNumber;
  68.  
  69. JOptionPane.showMessageDialog(null, "The answer is " + finalNumber);
  70.  
  71. return finalNumber;
  72. }
  73.  
  74. if (method.equals("divide")) {
  75. JOptionPane.showMessageDialog(null, "They are going to Divide");
  76. finalNumber = firstNumber / secondNumber;
  77.  
  78. JOptionPane.showMessageDialog(null, "The answer is " + finalNumber);
  79.  
  80. return finalNumber;
  81. }
  82.  
  83. else {
  84. return finalNumber;
  85. }
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement