Bläddra i källkod

Group Project

NiraParikh 6 år sedan
förälder
incheckning
2aae86406b
6 ändrade filer med 517 tillägg och 34 borttagningar
  1. Binär
      .DS_Store
  2. 299
    0
      Calc.java
  3. 59
    8
      Console.java
  4. 7
    6
      MainApplication.java
  5. 96
    0
      Math_methods.java
  6. 56
    20
      package.bluej

Binär
.DS_Store Visa fil


+ 299
- 0
Calc.java Visa fil

@@ -0,0 +1,299 @@
1
+
2
+/**
3
+ * Write a description of class Math_methods here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+import java.io.IOException;
9
+import java.util.Scanner;
10
+import java.util.*;
11
+/**
12
+ * Write a description of class Calc here.
13
+ *
14
+ * @author (your name)
15
+ * @version (a version number or a date)
16
+ */
17
+public  class Calc {
18
+    public static void main(String[]args){
19
+        // instance variables - replace the example below with your own
20
+        Scanner scan = new Scanner(System.in);
21
+        double calcValue1;
22
+        double calcValue2;
23
+        double addTwoNumbers;
24
+        double getCalcValue;
25
+        int options = 0;
26
+
27
+        double answer;
28
+        double sum;
29
+        boolean off = false;
30
+        boolean on = true;
31
+        int num1 =0;
32
+        int num2 =0;
33
+
34
+        /* System.out.println("Enter Number1");
35
+        calcValue1 = scan.nextDouble();
36
+        System.out.println("Enter Number2");
37
+        calcValue2 = scan.nextDouble();
38
+        System.out.println("Enter Number1");*/
39
+        /*
40
+        System.out.println("Enter Number1 ");
41
+        num1= scan.nextInt();
42
+        System.out.println("Enter Number2 ");
43
+        num2 = scan.nextInt();
44
+         *//*
45
+
46
+        System.out.println("Please enter the number of what you want to do");
47
+        System.out.println("1. Add ");
48
+        System.out.println("2. Substract");
49
+        System.out.println("3. Multiply ");
50
+        System.out.println("4. Division");
51
+        System.out.println("5. Modulus ");
52
+        System.out.println("6. Square Root");
53
+        System.out.println("7. Average");
54
+         */
55
+
56
+        // String abc = keyboard.System.in();
57
+        //try{
58
+
59
+        //...
60
+
61
+        System.out.print("Let's crunch some numbers");
62
+        while (on){
63
+
64
+            System.out.println("Please enter the number of what you want to do");
65
+            System.out.println("1.  Add ");
66
+            System.out.println("2.  Substract");
67
+            System.out.println("3.  Multiply ");
68
+            System.out.println("4.  Division");
69
+            System.out.println("5.  Modulus ");
70
+            System.out.println("6.  Square Root");
71
+            System.out.println("7.  Avg");
72
+            System.out.println("8.  Exp");
73
+            System.out.println("9.  Mode");
74
+            System.out.println("10. Max");
75
+            System.out.println("11. Min");
76
+            System.out.println("12. Abs");
77
+            System.out.println("13. Round");
78
+            System.out.println("14. Sin");
79
+            System.out.println("15. Cos");
80
+            System.out.println("16. tan");
81
+            System.out.println("17. Quit");
82
+            scan.hasNextInt();
83
+            options = scan.nextInt();
84
+
85
+            try{
86
+                //System.out.println("Enter Number1 ");
87
+
88
+                //System.out.println("Enter Number2 "_);                                                                        
89
+                //options = scan.nextInt();
90
+                switch (options){
91
+
92
+                    case 1:  //Sum
93
+                    //System.out.print('\u000C');
94
+
95
+                    System.out.println("Enter Number1 ");
96
+                    num1= scan.nextInt();
97
+
98
+                    System.out.println("Enter Number2 ");
99
+                    num2 = scan.nextInt();
100
+
101
+                    answer = Math_methods.add(num1,num2);
102
+                    System.out.println(answer);
103
+                    break;
104
+
105
+                    case 2:   //difference:
106
+                    //System.out.print('\u000C');
107
+                    System.out.println("Enter Number1 ");
108
+                    num1= scan.nextInt();
109
+
110
+                    System.out.println("Enter Number2 ");
111
+                    num2 = scan.nextInt();
112
+                    answer = Math_methods.minus(num1,num2);
113
+                    System.out.println(answer);
114
+                    break;
115
+
116
+                    case 3:  // multiply:
117
+                    //System.out.print('\u000C');
118
+                    System.out.println("Enter Number1 ");
119
+                    num1= scan.nextInt();
120
+
121
+                    System.out.println("Enter Number2 ");
122
+                    num2 = scan.nextInt();
123
+                    answer =  Math_methods.mult(num1,num2);
124
+                    System.out.println(answer);
125
+                    break;
126
+
127
+                    case  4:   //divide:
128
+                    //System.out.print('\u000C');
129
+                    System.out.println("Enter Number1 ");
130
+                    num1= scan.nextInt();
131
+
132
+                    System.out.println("Enter Number2 ");
133
+                    num2 = scan.nextInt();
134
+                    answer =  Math_methods.div(num1,num2);
135
+                    System.out.println(answer);
136
+                    break;
137
+
138
+                    case 5:  //modulus: 
139
+                    //System.out.print('\u000C');
140
+                    System.out.println("Enter Number1 ");
141
+                    num1= scan.nextInt();
142
+
143
+                    System.out.println("Enter Number2 ");
144
+                    num2 = scan.nextInt();
145
+                    answer = Math_methods.mod(num1,num2);
146
+                    System.out.println(answer);
147
+                    break;
148
+
149
+                    case 6: //squareRoot:
150
+                    //System.out.print('\u000C');
151
+                    System.out.println("Enter Number1 ");
152
+                    num1= scan.nextInt();
153
+
154
+<<<<<<< HEAD
155
+                    
156
+                    answer = Math_methods.squ(num1);
157
+=======
158
+                    System.out.println("Enter Number2 ");
159
+                    num2 = scan.nextInt();
160
+                    answer = Math_methods.sqrt(num1);
161
+>>>>>>> a1fd4c3acf4fcab569f625e2c3c96cf0fc0d7b8a
162
+                    System.out.println(answer); 
163
+                    break;
164
+
165
+                    case 7: //Average:
166
+                    //System.out.print('\u000C');
167
+                    System.out.println("Enter Number1 ");
168
+                    num1= scan.nextInt();
169
+
170
+                    System.out.println("Enter Number2 ");
171
+                    num2 = scan.nextInt();
172
+                    answer = Math_methods.ave(num1,num2);
173
+                    System.out.println(answer); 
174
+                    break;
175
+
176
+                    case 8: //Exponent:
177
+                    //System.out.print('\u000C');
178
+                    System.out.println("Enter Number1 ");
179
+                    num1= scan.nextInt();
180
+
181
+                    System.out.println("Enter Number2 ");
182
+                    num2 = scan.nextInt();
183
+                    answer = Math_methods.exp(num1,num2);
184
+                    System.out.println(answer);
185
+                    break;
186
+
187
+                    case 9: //Mod:
188
+                    //System.out.print('\u000C');
189
+                    System.out.println("Enter Number1 ");
190
+                    num1= scan.nextInt();
191
+
192
+                    System.out.println("Enter Number2 ");
193
+                    num2 = scan.nextInt();
194
+                    answer = Math_methods.mod(num1,num2);
195
+                    System.out.println(answer);
196
+                    break;
197
+
198
+                    case 10: //Maximum:
199
+                    //System.out.print('\u000C');
200
+                    System.out.println("Enter Number1 ");
201
+                    num1= scan.nextInt();
202
+
203
+                    System.out.println("Enter Number2 ");
204
+                    num2 = scan.nextInt();
205
+                    answer = Math_methods.max(num1,num2);
206
+                    System.out.println(answer);
207
+                    break;
208
+
209
+                    case 11: //Minimum:
210
+                    //System.out.print('\u000C');
211
+                    System.out.println("Enter Number1 ");
212
+                    num1= scan.nextInt();
213
+
214
+                    System.out.println("Enter Number2 ");
215
+                    num2 = scan.nextInt();
216
+                    answer = Math_methods.min(num1,num2);
217
+                    System.out.println(answer);
218
+                    break;
219
+
220
+                    case 12: //Absolute value:
221
+                    //System.out.print('\u000C');
222
+                    System.out.println("Enter Number1 ");
223
+                    num1= scan.nextInt();
224
+                    
225
+                    answer = Math_methods.abs(num1);
226
+                    System.out.println(answer);
227
+                    break;
228
+
229
+                    case 13: 
230
+                    System.out.println("Enter Number1 ");
231
+                    num1= scan.nextInt();
232
+
233
+                    answer = Math_methods.round(num1);
234
+                    System.out.println(answer);
235
+                    break;
236
+
237
+                    case 14:
238
+                    System.out.println("Enter Number1 ");
239
+                    num1= scan.nextInt();
240
+
241
+                    answer = Math_methods.sin(num1);
242
+                    System.out.println(answer);
243
+                    break;
244
+                    
245
+                    case 15:
246
+                    System.out.println("Enter Number1 ");
247
+                    num1= scan.nextInt();
248
+
249
+                    answer = Math_methods.cos(num1);
250
+                    System.out.println(answer);
251
+                    break;
252
+                    
253
+                    case 16:
254
+                    System.out.println("Enter Number1 ");
255
+                    num1= scan.nextInt();
256
+
257
+                    answer = Math_methods.tan(num1);
258
+                    System.out.println(answer);
259
+                    break;
260
+
261
+                    case 17:
262
+                    System.exit(0);
263
+                    break;
264
+
265
+                    default:
266
+                    System.out.println("Hello");
267
+                    System.out.print('\u000C');
268
+
269
+                }
270
+
271
+            }
272
+            catch(NumberFormatException e){
273
+                //catch(Exception e){
274
+                System.out.printf("Wrong number or not enough numbers");
275
+
276
+            }
277
+            /* while(options == 0){
278
+            break;
279
+            }*/
280
+        }
281
+    }
282
+}
283
+
284
+/*catch(IOException e){
285
+System.out.println(error);
286
+abc.displayErrorMessage("Please Enter 2 digit");
287
+}
288
+/*
289
+public void addNum2(int Number1, int Number2){
290
+
291
+calcValue1 = Number1 + Number2;
292
+
293
+}
294
+
295
+public int getCalcValue(){
296
+
297
+return calculationValue;
298
+ */
299
+

+ 59
- 8
Console.java Visa fil

@@ -5,8 +5,9 @@ import java.util.Scanner;
5 5
 /**
6 6
  * Created by leon on 2/9/18.
7 7
  */
8
-public class Console {
9 8
 
9
+public class Console {
10
+    
10 11
     public static void print(String output, Object... args) {
11 12
         System.out.printf(output, args);
12 13
     }
@@ -14,19 +15,69 @@ public class Console {
14 15
     public static void println(String output, Object... args) {
15 16
         print(output + "\n", args);
16 17
     }
17
-
18
+/*
18 19
     public static String getStringInput(String prompt) {
19 20
         Scanner scanner = new Scanner(System.in);
20 21
         println(prompt);
21 22
         String userInput = scanner.nextLine();
22 23
         return userInput;
23 24
     }
24
-
25
-    public static Integer getIntegerInput(String prompt) {
26
-        return null;
25
+*/
26
+     public static int add(int num1,int num2){
27
+            return num1 + num2;
27 28
     }
28
-
29
-    public static Double getDoubleInput(String prompt) {
30
-        return null;
29
+    
30
+    public static int minus(int num1,int num2){
31
+            return  num1 - num2;
32
+    }
33
+    
34
+    public static int mult(int num1,int num2){
35
+            return  num1 * num2;
36
+    }
37
+    public static int pow(double num1,double num2){
38
+          
39
+        double r = Math.pow(num1,num2);
40
+        return (int)Math.round(r);
41
+            
42
+    }
43
+    public static double squ(int num1){
44
+    
45
+        return (double) Math.sqrt(num1);
46
+    }
47
+    public static int min(int num1, int num2){
48
+        return Math.min(num1,num2);
49
+    }
50
+    public static int max(int num1, int num2){
51
+        return Math.max(num1,num2);
52
+    }    
53
+    public static double exp (double num1){         
54
+        return  Math.pow(2.718,num1);
55
+    }
56
+    public static double tenthpow(double num1){
57
+        return Math.pow(10,num1);
58
+    }
59
+    public static int abs(int num1){
60
+        return Math.abs(num1);
61
+    }
62
+    public static double round(double num1){
63
+        return Math.round(num1);
64
+    }
65
+    
66
+    public static long exp (int num1, int num2){ 
67
+        int neg = -2147483647;
68
+        int pos = 2147483647;
69
+        long t = 0;
70
+        
71
+        
72
+        if(num1 >= -1 || num1 <= neg){
73
+            double re = Math.pow(num1,num2);
74
+            return (long)re;
75
+        }
76
+        else if(num2 >= 1 || num2 <= pos ){
77
+            
78
+            double re2 = Math.pow(num2,num1);
79
+            return (long)re2;        
80
+        }
81
+        return t;
31 82
     }
32 83
 }

+ 7
- 6
MainApplication.java Visa fil

@@ -4,14 +4,15 @@
4 4
  * Created by leon on 2/9/18.
5 5
  */
6 6
 public class MainApplication {
7
-    public static void main(String[] args) {
7
+    
8
+ /*public static void main(String[] args) {
8 9
         Console.println("Welcome to my calculator!");
9 10
         String s = Console.getStringInput("Enter a string");
10
-        Integer i = Console.getIntegerInput("Enter an integer");
11
-        Double d = Console.getDoubleInput("Enter a double.");
11
+       // Integer i = Console.getIntegerInput("Enter an integer");
12
+      //  Double d = Console.getDoubleInput("Enter a double.");
12 13
 
13 14
         Console.println("The user input %s as a string", s);
14
-        Console.println("The user input %s as a integer", i);
15
-        Console.println("The user input %s as a d", d);
16
-    }
15
+        //Console.println("The user input %s as a integer", i);
16
+        //Console.println("The user input %s as a d", d);
17
+    }*/
17 18
 }

+ 96
- 0
Math_methods.java Visa fil

@@ -0,0 +1,96 @@
1
+
2
+/**
3
+ * Write a description of class Math_methods here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class Math_methods
9
+{   
10
+    
11
+    //Console.Math_basic = new Console();
12
+    //Integer i = Console.getIntegerInput("Enter an integer");
13
+    //Double d = Console.getDoubleInput("Enter a double.");
14
+   
15
+    public static int add(int num1,int num2){
16
+            return num1 + num2;
17
+    }
18
+    
19
+    public static int minus(int num1,int num2){
20
+            return  num1 - num2;
21
+    }
22
+    
23
+    public static int mult(int num1,int num2){
24
+            return  num1 * num2;
25
+    }
26
+     public static int div(int num1,int num2){
27
+            return  num1 / num2;
28
+    }
29
+     public static int mod(int num1,int num2){
30
+            return  num1 % num2;
31
+    }
32
+    public static int pow(double num1,double num2){
33
+          
34
+        double r = Math.pow(num1,num2);
35
+        return (int)Math.round(r);
36
+            
37
+    }
38
+    public static double sqrt(int num1){
39
+    
40
+        return (double) Math.sqrt(num1);
41
+    }
42
+    public static int min(int num1, int num2){
43
+        return Math.min(num1,num2);
44
+    }
45
+    public static int max(int num1, int num2){
46
+        return Math.max(num1,num2);
47
+    }    
48
+    public static double exp (double num1){         
49
+        return  Math.pow(2.718,num1);
50
+    }
51
+    public static double tenthpow(double num1){
52
+        return Math.pow(10,num1);
53
+    }
54
+    public static double abs(int num1){
55
+        return (double)Math.abs(num1);
56
+    }
57
+    public static double round(double num1){
58
+        return Math.round(num1);
59
+    }
60
+    public static double ave(double num1,double num2){
61
+         return num1 + num2 / 2;
62
+        
63
+    }
64
+    
65
+    public static long exp (int num1, int num2){ 
66
+        int neg = -2147483647;
67
+        int pos = 2147483647;
68
+        long t = 0;
69
+        
70
+        
71
+        if(num1 >= -1 || num1 <= neg){
72
+            double re = Math.pow(num1,num2);
73
+            return (long)re;
74
+        }
75
+        else if(num2 >= 1 || num2 <= pos ){
76
+            
77
+            double re2 = Math.pow(num2,num1);
78
+            return (long)re2;        
79
+        }
80
+        return t;
81
+    }
82
+    public static double sin(double num1){
83
+         return (int)Math.sin(num1);
84
+        
85
+    }
86
+    public static double cos(double num1){
87
+         return (int)Math.cos(num1);
88
+        
89
+    }
90
+    public static double tan(double num1){
91
+         return (int)Math.tan(num1);
92
+        
93
+    }
94
+    
95
+   }
96
+

+ 56
- 20
package.bluej Visa fil

@@ -1,23 +1,45 @@
1 1
 #BlueJ package file
2
-dependency1.from=MainApplication
3
-dependency1.to=Console
2
+dependency1.from=Calc
3
+dependency1.to=Math_methods
4 4
 dependency1.type=UsesDependency
5
+<<<<<<< HEAD
5 6
 editor.fx.0.height=722
6 7
 editor.fx.0.width=800
7
-editor.fx.0.x=640
8
-editor.fx.0.y=23
9
-objectbench.height=214
8
+editor.fx.0.x=240
9
+editor.fx.0.y=26
10
+=======
11
+<<<<<<< HEAD
12
+editor.fx.0.height=709
13
+editor.fx.0.width=800
14
+editor.fx.0.x=480
15
+editor.fx.0.y=38
16
+=======
17
+editor.fx.0.height=0
18
+editor.fx.0.width=0
19
+editor.fx.0.x=0
20
+editor.fx.0.y=0
21
+>>>>>>> 635b8c5fbb09e83e7e4fa1e9271cded4360b54a9
22
+>>>>>>> 4faaaaae5148324316aec7470eb2248b688fee59
23
+objectbench.height=198
10 24
 objectbench.width=595
11
-package.divider.horizontal=0.6
12
-package.divider.vertical=0.6847360912981455
13
-package.editor.height=473
25
+package.divider.horizontal=0.5993322203672788
26
+package.divider.vertical=0.685099846390169
27
+package.editor.height=439
14 28
 package.editor.width=493
15
-package.editor.x=35
16
-package.editor.y=60
17
-package.frame.height=759
29
+package.editor.x=446
30
+<<<<<<< HEAD
31
+package.editor.y=23
32
+=======
33
+<<<<<<< HEAD
34
+package.editor.y=37
35
+=======
36
+package.editor.y=23
37
+>>>>>>> 635b8c5fbb09e83e7e4fa1e9271cded4360b54a9
38
+>>>>>>> 4faaaaae5148324316aec7470eb2248b688fee59
39
+package.frame.height=709
18 40
 package.frame.width=619
19 41
 package.numDependencies=1
20
-package.numTargets=2
42
+package.numTargets=4
21 43
 package.showExtends=true
22 44
 package.showUses=true
23 45
 project.charset=UTF-8
@@ -27,16 +49,30 @@ readme.width=47
27 49
 readme.x=10
28 50
 readme.y=10
29 51
 target1.height=50
30
-target1.name=Console
52
+target1.name=Math_methods
31 53
 target1.showInterface=false
32 54
 target1.type=ClassTarget
33
-target1.width=80
34
-target1.x=80
35
-target1.y=200
55
+target1.width=120
56
+target1.x=90
57
+target1.y=10
36 58
 target2.height=50
37
-target2.name=MainApplication
59
+target2.name=Console
38 60
 target2.showInterface=false
39 61
 target2.type=ClassTarget
40
-target2.width=120
41
-target2.x=70
42
-target2.y=70
62
+target2.width=80
63
+target2.x=80
64
+target2.y=200
65
+target3.height=50
66
+target3.name=Calc
67
+target3.showInterface=false
68
+target3.type=ClassTarget
69
+target3.width=80
70
+target3.x=200
71
+target3.y=70
72
+target4.height=50
73
+target4.name=MainApplication
74
+target4.showInterface=false
75
+target4.type=ClassTarget
76
+target4.width=120
77
+target4.x=80
78
+target4.y=260