浏览代码

group Project

父节点
当前提交
603048113a
共有 5 个文件被更改,包括 474 次插入29 次删除
  1. 260
    0
      Cal.java
  2. 58
    7
      Console.java
  3. 2
    2
      MainApplication.java
  4. 120
    0
      Math_methods.java
  5. 34
    20
      package.bluej

+ 260
- 0
Cal.java 查看文件

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

+ 58
- 7
Console.java 查看文件

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

+ 2
- 2
MainApplication.java 查看文件

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

+ 120
- 0
Math_methods.java 查看文件

@@ -0,0 +1,120 @@
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
+     public static int add(int num1,int num2){
11
+            return num1 + num2;
12
+    }
13
+    
14
+    
15
+    public static int minus(int num1,int num2){
16
+            return  num1 - num2;
17
+    }
18
+    
19
+    
20
+    public static int mult(int num1,int num2){
21
+            return  num1 * num2;
22
+    }
23
+    
24
+    
25
+     public static int div(int num1,int num2){
26
+            return  num1 / num2;
27
+    }
28
+    
29
+    
30
+     public static int mod(int num1,int num2){
31
+            return  num1 % num2;
32
+    }
33
+    
34
+    
35
+    public static int pow(double num1,double num2){
36
+          
37
+        double r = Math.pow(num1,num2);
38
+        return (int)Math.round(r);
39
+            
40
+    }
41
+    
42
+    
43
+    public static double sqrt(int num1){
44
+    
45
+        return (double) Math.sqrt(num1);
46
+    }
47
+    
48
+    
49
+    public static int min(int num1, int num2){
50
+        return Math.min(num1,num2);
51
+    }
52
+    
53
+    
54
+    public static int max(int num1, int num2){
55
+        return Math.max(num1,num2);
56
+    } 
57
+    
58
+    
59
+    public static double exp (double num1){         
60
+        return  Math.pow(2.718,num1);
61
+    }
62
+    
63
+    
64
+    public static double tenthpow(double num1){
65
+        return Math.pow(10,num1);
66
+    }
67
+    
68
+    
69
+    public static double abs(int num1){
70
+        return (double)Math.abs(num1);
71
+    }
72
+    
73
+    
74
+    public static double round(double num1){
75
+        return Math.round(num1);
76
+    }
77
+    
78
+    
79
+    public static double ave(double num1,double num2){
80
+         return num1 + num2 / 2;
81
+        
82
+    }
83
+    
84
+    public static long exp (int num1, int num2){ 
85
+        int neg = -2147483647;
86
+        int pos = 2147483647;
87
+        long t = 0;
88
+        
89
+        
90
+        if(num1 >= -1 || num1 <= neg){
91
+            double re = Math.pow(num1,num2);
92
+            return (long)re;
93
+        }
94
+        else if(num2 >= 1 || num2 <= pos ){
95
+            
96
+            double re2 = Math.pow(num2,num1);
97
+            return (long)re2;        
98
+        }
99
+        return t;
100
+    }
101
+    
102
+    
103
+    public static double sin(double num1){
104
+         return (int)Math.sin(num1);
105
+        
106
+    }
107
+    
108
+    
109
+    public static double cos(double num1){
110
+         return (int)Math.cos(num1);
111
+        
112
+    }
113
+    
114
+    
115
+    public static double tan(double num1){
116
+         return (int)Math.tan(num1);
117
+        
118
+    }
119
+    
120
+}

+ 34
- 20
package.bluej 查看文件

@@ -1,23 +1,23 @@
1 1
 #BlueJ package file
2
-dependency1.from=MainApplication
3
-dependency1.to=Console
2
+dependency1.from=Cal
3
+dependency1.to=Math_methods
4 4
 dependency1.type=UsesDependency
5
-editor.fx.0.height=722
6
-editor.fx.0.width=800
7
-editor.fx.0.x=640
5
+editor.fx.0.height=715
6
+editor.fx.0.width=852
7
+editor.fx.0.x=428
8 8
 editor.fx.0.y=23
9
-objectbench.height=214
9
+objectbench.height=200
10 10
 objectbench.width=595
11 11
 package.divider.horizontal=0.6
12
-package.divider.vertical=0.6847360912981455
13
-package.editor.height=473
12
+package.divider.vertical=0.684931506849315
13
+package.editor.height=443
14 14
 package.editor.width=493
15
-package.editor.x=35
16
-package.editor.y=60
17
-package.frame.height=759
15
+package.editor.x=567
16
+package.editor.y=42
17
+package.frame.height=715
18 18
 package.frame.width=619
19 19
 package.numDependencies=1
20
-package.numTargets=2
20
+package.numTargets=4
21 21
 package.showExtends=true
22 22
 package.showUses=true
23 23
 project.charset=UTF-8
@@ -27,16 +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=Math_methods
31 31
 target1.showInterface=false
32 32
 target1.type=ClassTarget
33
-target1.width=80
34
-target1.x=80
35
-target1.y=200
33
+target1.width=120
34
+target1.x=240
35
+target1.y=50
36 36
 target2.height=50
37
-target2.name=MainApplication
37
+target2.name=Console
38 38
 target2.showInterface=false
39 39
 target2.type=ClassTarget
40
-target2.width=120
41
-target2.x=70
42
-target2.y=70
40
+target2.width=80
41
+target2.x=80
42
+target2.y=200
43
+target3.height=50
44
+target3.name=MainApplication
45
+target3.showInterface=false
46
+target3.type=ClassTarget
47
+target3.width=120
48
+target3.x=70
49
+target3.y=120
50
+target4.height=50
51
+target4.name=Cal
52
+target4.showInterface=false
53
+target4.type=ClassTarget
54
+target4.width=80
55
+target4.x=70
56
+target4.y=10