-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollatzFunction.java
99 lines (79 loc) · 1.6 KB
/
CollatzFunction.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import java.util.ArrayList ;
public class CollatzFunction
{
private int start ;
private int currentStep = start ;
private int stepCounter = 1 ;
private int horizLength = 0 ;
private int hLengthHold = 0 ;
//CONSTRUCTORS
public CollatzFunction ()
{
this.start = 2 ;
}
public CollatzFunction (int start)
{
this.start = start ;
this.currentStep = start ;
this.stepCounter = 1 ;
this.horizLength = 0 ;
this.hLengthHold = 0 ;
}
//GETTERS AND SETTERS
public void setStart (int start)
{
this.start = start ;
this.currentStep = start ;
this.stepCounter = 1 ;
this.horizLength = 0 ;
}
public int getStart ()
{
return this.start ;
}
public int getCurrentStep ()
{
return currentStep ;
}
public void setHorizLength (int hLength)
{
this.horizLength = hLength ;
}
public int getHorizLength ()
{
return this.horizLength ;
}
public int getHLengthHold ()
{
return this.hLengthHold ;
}
public void setHLengthHold (int hLengthHold)
{
this.hLengthHold = hLengthHold ;
}
public int getStepCounter ()
{
return this.stepCounter ;
}
//OTHER METHODS
public int nDivTwo ()
{
int quotient = currentStep / 2 ;
return quotient ;
}
public int threeNLessOne ()
{
int prodSum = 3 * currentStep + 1 ;
return prodSum ;
}
public void takeStep ()
{
int nextStep = (this.currentStep % 2 == 0) ? this.nDivTwo() : this.threeNLessOne() ;
this.currentStep = nextStep ;
this.stepCounter += 1 ;
}
public void addToHLength (int hAdd)
{
this.horizLength += hAdd ;
}
}