Bläddra i källkod

Added Basic Functions

Lauren Green 6 år sedan
förälder
incheckning
2f8a5cb9f6
3 ändrade filer med 84 tillägg och 12 borttagningar
  1. 65
    0
      Basic.java
  2. 2
    2
      Trig.java
  3. 17
    10
      package.bluej

+ 65
- 0
Basic.java Visa fil

@@ -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
+        

+ 2
- 2
Trig.java Visa fil

@@ -73,7 +73,7 @@ public class Trig
73 73
             toDegrees(answer);
74 74
     } else {
75 75
         System.out.println("Have a nice day!");
76
-        ///Return to Main Application
76
+        //Insert Return to Main Menu
77 77
 }
78 78
     }
79 79
 
@@ -81,7 +81,7 @@ public class Trig
81 81
     {
82 82
         double conversion = Math.toDegrees(answer);
83 83
         System.out.println(conversion);
84
-        ///Return to Main Application
84
+        //Insert Return to Main Menu
85 85
     }
86 86
 }
87 87
 

+ 17
- 10
package.bluej Visa fil

@@ -17,7 +17,7 @@ package.editor.y=60
17 17
 package.frame.height=759
18 18
 package.frame.width=619
19 19
 package.numDependencies=1
20
-package.numTargets=3
20
+package.numTargets=4
21 21
 package.showExtends=true
22 22
 package.showUses=true
23 23
 project.charset=UTF-8
@@ -27,23 +27,30 @@ readme.width=47
27 27
 readme.x=10
28 28
 readme.y=10
29 29
 target1.height=50
30
-target1.name=Console
30
+target1.name=Basic
31 31
 target1.showInterface=false
32 32
 target1.type=ClassTarget
33 33
 target1.width=80
34
-target1.x=80
35
-target1.y=200
34
+target1.x=320
35
+target1.y=180
36 36
 target2.height=50
37
-target2.name=Trig
37
+target2.name=Console
38 38
 target2.showInterface=false
39 39
 target2.type=ClassTarget
40 40
 target2.width=80
41
-target2.x=320
42
-target2.y=70
41
+target2.x=80
42
+target2.y=200
43 43
 target3.height=50
44
-target3.name=MainApplication
44
+target3.name=Trig
45 45
 target3.showInterface=false
46 46
 target3.type=ClassTarget
47
-target3.width=120
48
-target3.x=70
47
+target3.width=80
48
+target3.x=320
49 49
 target3.y=70
50
+target4.height=50
51
+target4.name=MainApplication
52
+target4.showInterface=false
53
+target4.type=ClassTarget
54
+target4.width=120
55
+target4.x=70
56
+target4.y=70