|
@@ -0,0 +1,65 @@
|
|
1
|
+import java.util.Scanner;
|
|
2
|
+
|
|
3
|
+/**
|
|
4
|
+ * Basic class to perform basic functions for our Graphing Calculator
|
|
5
|
+ * (+, -, *, /)
|
|
6
|
+ * Lauren Green
|
|
7
|
+ * 10/19/18
|
|
8
|
+ */
|
|
9
|
+public class Basic
|
|
10
|
+{
|
|
11
|
+ int input1 = 0;
|
|
12
|
+ int input2 = 0;
|
|
13
|
+ int answer;
|
|
14
|
+
|
|
15
|
+ public Basic()
|
|
16
|
+ {
|
|
17
|
+ boolean validInput = false;
|
|
18
|
+
|
|
19
|
+ while(!validInput) {
|
|
20
|
+ //Get input of first number
|
|
21
|
+ Scanner in2 = new Scanner(System.in);
|
|
22
|
+ System.out.println("What is the first number?");
|
|
23
|
+ input1 = in2.nextInt();
|
|
24
|
+
|
|
25
|
+ //Get input of type of function
|
|
26
|
+ Scanner in1 = new Scanner(System.in);
|
|
27
|
+ System.out.println("Which operation would you like to perform? \n +, -, *, /");
|
|
28
|
+ String operation = in1.nextLine();
|
|
29
|
+
|
|
30
|
+ //Get input of second number
|
|
31
|
+ Scanner in3 = new Scanner(System.in);
|
|
32
|
+ System.out.println("What is the second number?");
|
|
33
|
+ input2 = in3.nextInt();
|
|
34
|
+
|
|
35
|
+ //Do the math depending on the input.
|
|
36
|
+ if (operation.equals("+")) {
|
|
37
|
+ answer = input1 + input2;
|
|
38
|
+ System.out.println(answer);
|
|
39
|
+ validInput = true;
|
|
40
|
+
|
|
41
|
+ } else if (operation.equals("-")) {
|
|
42
|
+ answer = input1 - input2;
|
|
43
|
+ System.out.println(answer);
|
|
44
|
+ validInput = true;
|
|
45
|
+
|
|
46
|
+ } else if (operation.equals("*")) {
|
|
47
|
+ answer = input1 * input2;
|
|
48
|
+ System.out.println(answer);
|
|
49
|
+ validInput = true;
|
|
50
|
+
|
|
51
|
+ } else if (operation.equals("/")) {
|
|
52
|
+ answer = input1 / input2;
|
|
53
|
+ System.out.println(answer);
|
|
54
|
+ validInput = true;
|
|
55
|
+
|
|
56
|
+ } else {
|
|
57
|
+ System.out.println("Error, try again \n");
|
|
58
|
+
|
|
59
|
+ }
|
|
60
|
+}
|
|
61
|
+ //Insert return to main menu.
|
|
62
|
+}
|
|
63
|
+}
|
|
64
|
+
|
|
65
|
+
|