-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPolyCalc.java
64 lines (58 loc) · 1.41 KB
/
PolyCalc.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
public class PolyCalc {
private int[] nums;
private int divisor;
public PolyCalc(){
nums = {1, 2, 1};
}
public PolyCalc(int a, int b, int c){
nums = {a, b, c};
}
public int getDivisor() {
if (divisor != 0) return divisor;
updateDivisor();
return getDivisor();
}
public int getA() {
return nums[0]/(divisor==0? 1 : divisor);
}
public int getB() {
return nums[1]/(divisor==0? 1 : divisor);
}
public int getC() {
return nums[2]/(divisor==0? 1 : divisor);
}
public int setA(int num) {
int temp = nums[0];
nums[0] = num;
updateDivisor();
return temp;
}
public int setB(int num) {
int temp = nums[1];
nums[1] = num;
updateDivisor();
return temp;
}
public int setC(int num) {
int temp = nums[2];
nums[2] = num;
updateDivisor();
return temp;
}
private int updateDivisor() {
if (a<2) {
divisor = 1;
return divisor;
}
int i = 2;
for(i; i <= a && !(a%i==0 && b%i==0 && c%i==0); i++) {
System.out.println("Trying " + i)
}
divisor = i;
return divisor;
}
public static void main(String args[]) {
PolyCalc test = new PolyCalc();
PolyCalc tes2 = new PolyCalc();
}
}