1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import java.util.Scanner;
-
- /**
- * Basic class to perform basic functions for our Graphing Calculator
- * (+, -, *, /)
- * Lauren Green
- * 10/19/18
- */
- public class Basic
- {
- int input1 = 0;
- int input2 = 0;
- int answer;
-
- public Basic()
- {
- boolean validInput = false;
-
- while(!validInput) {
- //Get input of first number
- input1 = Console.getIntegerInput("What is the first number?");
-
- //Get input of type of function
- String operation = Console.getStringInput("Which operation would you like to perform? \n +, -, *, /");
-
- //Get input of second number
- input2 = Console.getIntegerInput("What is the second number?");
-
- //Do the math depending on the input.
- if (operation.equals("+")) {
- answer = input1 + input2;
- System.out.println(answer);
- validInput = true;
-
- } else if (operation.equals("-")) {
- answer = input1 - input2;
- System.out.println(answer);
- validInput = true;
-
- } else if (operation.equals("*")) {
- answer = input1 * input2;
- System.out.println(answer);
- validInput = true;
-
- } else if (operation.equals("/")) {
- answer = input1 / input2;
- System.out.println(answer);
- validInput = true;
-
- } else {
- System.out.println("Error, try again \n");
-
- }
- }
- //Insert return to main menu.
- }
- }
-
-
|