1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- 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
- Scanner in2 = new Scanner(System.in);
- System.out.println("What is the first number?");
- input1 = in2.nextInt();
-
- //Get input of type of function
- Scanner in1 = new Scanner(System.in);
- System.out.println("Which operation would you like to perform? \n +, -, *, /");
- String operation = in1.nextLine();
-
- //Get input of second number
- Scanner in3 = new Scanner(System.in);
- System.out.println("What is the second number?");
- input2 = in3.nextInt();
-
- //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.
- }
- }
-
-
|