forked from MetroCS/SWQualityTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampleClass.java
More file actions
91 lines (84 loc) · 2.26 KB
/
Copy pathSampleClass.java
File metadata and controls
91 lines (84 loc) · 2.26 KB
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
/**
* Sample class.
* @author Dr. Jody Paul
* @version Demonstration
*/
public class SampleClass {
private boolean condition = false;
private static final int SMALL_MAX = 10;
private static final int ANSWER = 42;
/** Constructor. */
public SampleClass() {
this.condition = false;
}
/**
* A basic "hello world" main method.
* @param args command-line parameters; ignored
*/
public static void main(String[] args) {
System.out.println("Hello from SampleMain.main!");
}
/**
* Increment parameter value by 42.
* @param any any int value
* @return the value of the parameter plus 42
*/
public int fortyTwo(int any) {
return any + ANSWER;
}
/**
* Simple binary toggle.
* @return current condition after toggling
*/
public boolean toggle() {
return (condition = !condition);
}
/**
* Repeated concatenation.
* @return result of building a string in a loop
*/
public String concatInLoop() {
String builder = "[";
for (int i = 0; i < SMALL_MAX; i++) {
builder += " " + i;
}
builder += " ]";
return builder;
}
/**
* Strange code method.
* @return sum of numbers up to parameter
*/
public int strangeMethod(int parameter) {
int j = 0;
for (int i = 1; i < ANSWER; i++) {
j = i + 1;
}
return j;
}
/**
* Example of deeply embedded loops.
*/
public void embeddedLoops() {
int howmany = 0;
for (int x = 0; x < SMALL_MAX; x++) {
for (int i = 0; i < SMALL_MAX; i++) {
for (int j = i; j < SMALL_MAX; j++) {
for (int k = 0; k < 8; k++) {
if (0 == k % 2) {
howmany++;
} else {
if (0 == j % 2) {
if (1 == i % 2) {
if (0 == x % 2) {
howmany--;
}
}
}
}
}
}
}
}
}
}