Skip to content

Commit eb3c4c0

Browse files
more refactoring
1 parent 4f261cb commit eb3c4c0

23 files changed

+99
-43
lines changed

.github/linters/java.xml

+6-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@
105105
<module name="JavadocType"/>
106106
<module name="JavadocVariable"/>
107107
<module name="JavadocStyle"/>
108-
<module name="MissingJavadocMethod"/>
108+
<module name="MissingJavadocMethod">
109+
<property name="ignoreMethodNamesRegex" value="^main.*$"/>
110+
</module>
109111

110112
<!-- Checks for Naming Conventions. -->
111113
<!-- See https://checkstyle.org/checks/naming/index.html -->
@@ -175,14 +177,15 @@
175177
<!-- See https://checkstyle.org/checks/design/index.html -->
176178
<module name="DesignForExtension"/>
177179
<module name="FinalClass"/>
178-
<module name="HideUtilityClassConstructor"/>
179180
<module name="InterfaceIsType"/>
180181
<module name="VisibilityModifier"/>
181182

182183
<!-- Miscellaneous other checks. -->
183184
<!-- See https://checkstyle.org/checks/misc/index.html -->
184185
<module name="ArrayTypeStyle"/>
185-
<module name="FinalParameters"/>
186+
<module name="FinalParameters">
187+
<property name="tokens" value="CTOR_DEF"/>
188+
</module>
186189
<module name="TodoComment"/>
187190
<module name="UpperEll"/>
188191

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package com.github.jonathanbirkey.chapter01;

src/com/github/jonathanbirkey/chapter02/Exercise07.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public static void main(String[] args) {
2020
input.close();
2121

2222
long years = minutes / (365 * 24 * 60);
23-
long minutes_remaining = minutes % (365 * 24 * 60);
24-
long days = minutes_remaining / (24 * 60);
23+
long minutesRemaining = minutes % (365 * 24 * 60);
24+
long days = minutesRemaining / (24 * 60);
2525
System.out.printf("%d minutes is approximately %d years and %d days\n", minutes, years, days);
2626
}
2727
}

src/com/github/jonathanbirkey/chapter02/Exercise11.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ public static void main(String[] args) {
1818
int numOfYears = input.nextInt();
1919
input.close();
2020

21-
double current_population = 312032486;
22-
long sec_per_year = 365 * 24 * 60 * 60;
23-
double births_per_year = sec_per_year / 7.0;
24-
double deaths_per_year = sec_per_year / 13.0;
25-
double immigrants_per_year = sec_per_year / 45.0;
26-
double growth_rate = births_per_year + immigrants_per_year - deaths_per_year;
21+
double currentPopulation = 312032486;
22+
long secPerYear = 365 * 24 * 60 * 60;
23+
double birthsPerYear = secPerYear / 7.0;
24+
double deathsPerYear = secPerYear / 13.0;
25+
double immigrantsPerYear = secPerYear / 45.0;
26+
double growthRate = birthsPerYear + immigrantsPerYear - deathsPerYear;
2727
for (int i = 0; i < numOfYears; i++) {
28-
current_population += growth_rate;
28+
currentPopulation += growthRate;
2929
}
30-
System.out.printf("The population in %d years is %d", numOfYears, (int) current_population);
30+
System.out.printf("The population in %d years is %d", numOfYears, (int) currentPopulation);
3131
}
3232
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package com.github.jonathanbirkey.chapter02;

src/com/github/jonathanbirkey/chapter03/Exercise04.java

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public static void main(String[] args) {
4747
break;
4848
case 11:
4949
System.out.println("December");
50+
default:
51+
System.out.print("Invalid");
5052
}
5153
}
5254
}

src/com/github/jonathanbirkey/chapter03/Exercise06.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ public static void main(String[] args) {
3232
double bmi = weightInKilograms / (heightInMeters * heightInMeters);
3333
// Display result
3434
System.out.println("BMI is " + bmi);
35-
if (bmi < 18.5) System.out.println("Underweight");
36-
else if (bmi < 25) System.out.println("Normal");
37-
else if (bmi < 30) System.out.println("Overweight");
38-
else System.out.println("Obese");
35+
if (bmi < 18.5) {
36+
System.out.println("Underweight");
37+
} else if (bmi < 25) {
38+
System.out.println("Normal");
39+
} else if (bmi < 30) {
40+
System.out.println("Overweight");
41+
} else {
42+
System.out.println("Obese");
43+
}
3944
}
4045
}

src/com/github/jonathanbirkey/chapter03/Exercise11.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ public static void main(String[] args) {
2929
System.out.print("January ");
3030
break;
3131
case 1:
32-
if (isLeapYear) daysPerMonth = 29;
33-
else daysPerMonth = 28;
34-
System.out.print("February ");
32+
if (isLeapYear) {
33+
daysPerMonth = 29;
34+
} else {
35+
daysPerMonth = 28;
36+
System.out.print("February ");
37+
}
3538
break;
3639
case 2:
3740
daysPerMonth = 31;
@@ -72,6 +75,8 @@ public static void main(String[] args) {
7275
case 11:
7376
daysPerMonth = 31;
7477
System.out.print("December ");
78+
default:
79+
System.out.print("Invalid Month");
7580
}
7681
System.out.printf("%d has %d days.", year, daysPerMonth);
7782
}

src/com/github/jonathanbirkey/chapter03/Exercise17.java

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public static void main(String[] args) {
3131
break;
3232
case 2:
3333
System.out.print("The computer is paper. ");
34+
default:
35+
System.out.print("Invalide");
3436
}
3537
switch (userPick) {
3638
case 0:
@@ -41,6 +43,8 @@ public static void main(String[] args) {
4143
break;
4244
case 2:
4345
System.out.print("You are paper");
46+
default:
47+
System.out.print("Invalide");
4448
}
4549
if (computerPick == userPick) {
4650
System.out.println(" too. It is a draw");

src/com/github/jonathanbirkey/chapter03/Exercise19.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ public static void main(String[] args) {
2020
int c = input.nextInt();
2121
input.close();
2222

23-
if (a + b < c || b + c < a || c + a < b) System.out.println("Invalid input.");
24-
else System.out.printf("perimeter is %d", a + b + c);
23+
if (a + b < c || b + c < a || c + a < b) {
24+
System.out.println("Invalid input.");
25+
} else {
26+
System.out.printf("perimeter is %d", a + b + c);
27+
}
2528
}
2629
}

src/com/github/jonathanbirkey/chapter03/Exercise21.java

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public static void main(String[] args) {
6464
break;
6565
case 6:
6666
System.out.println("Day of the week is Friday");
67+
default:
68+
System.out.print("Invalid");
6769
}
6870
}
6971
}

src/com/github/jonathanbirkey/chapter03/Exercise22.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ public static void main(String[] args) {
2424
input.close();
2525

2626
double distance = Math.pow(Math.pow(x - 0, 2) + Math.pow(y - 0, 2), 0.5);
27-
if (distance <= 10) System.out.printf("Point (%.2f, %.2f) is in the circle", x, y);
28-
else System.out.printf("Point (%.2f, %.2f) is not in the circle", x, y);
27+
if (distance <= 10) {
28+
System.out.printf("Point (%.2f, %.2f) is in the circle", x, y);
29+
} else {
30+
System.out.printf("Point (%.2f, %.2f) is not in the circle", x, y);
31+
}
2932
}
3033
}

src/com/github/jonathanbirkey/chapter03/Exercise23.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ public static void main(String[] args) {
2424
double y = input.nextDouble();
2525
input.close();
2626

27-
if (x > 5 || x < -5 || y > 5 || y < -5)
27+
if (x > 5 || x < -5 || y > 5 || y < -5) {
2828
System.out.printf("Point (%.2f, %.2f) is not in the rectangle", x, y);
29-
else System.out.printf("Point (%.2f, %.2f) is in the rectangle", x, y);
29+
} else {
30+
System.out.printf("Point (%.2f, %.2f) is in the rectangle", x, y);
31+
}
3032
}
3133
}

src/com/github/jonathanbirkey/chapter03/Exercise24.java

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public static void main(String[] args) {
5454
break;
5555
case 12:
5656
System.out.print("King of ");
57+
default:
58+
System.out.print("Invalid");
5759
}
5860
switch (suit) {
5961
case 0:
@@ -67,6 +69,8 @@ public static void main(String[] args) {
6769
break;
6870
case 3:
6971
System.out.print("Diamonds");
72+
default:
73+
System.out.print("Invalid");
7074
}
7175
}
7276
}

src/com/github/jonathanbirkey/chapter03/Exercise26.java

+14-6
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,24 @@ public static void main(String[] args) {
2121
input.close();
2222

2323
System.out.printf("Is %d divisible by 5 and 6? ", num);
24-
if (num % 5 == 0 && num % 6 == 0) System.out.println("true");
25-
else System.out.println("false");
24+
if (num % 5 == 0 && num % 6 == 0) {
25+
System.out.println("true");
26+
} else {
27+
System.out.println("false");
28+
}
2629

2730
System.out.printf("Is %d divisible by 5 or 6? ", num);
28-
if (num % 5 == 0 || num % 6 == 0) System.out.println("true");
29-
else System.out.println("false");
31+
if (num % 5 == 0 || num % 6 == 0) {
32+
System.out.println("true");
33+
} else {
34+
System.out.println("false");
35+
}
3036

3137
System.out.printf("Is %d divisible by 5 or 6, but not both? ", num);
32-
if ((num % 5 == 0 || num % 6 == 0) && !(num % 5 == 0 && num % 6 == 0))
38+
if ((num % 5 == 0 || num % 6 == 0) && !(num % 5 == 0 && num % 6 == 0)) {
3339
System.out.println("true");
34-
else System.out.println("false");
40+
} else {
41+
System.out.println("false");
42+
}
3543
}
3644
}

src/com/github/jonathanbirkey/chapter03/Exercise30.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ public static void main(String[] args) {
3838
// Compute the current hour
3939
long currentHour = (totalHours % 24) + offset;
4040

41-
if (currentHour > 12)
41+
if (currentHour > 12) {
4242
System.out.printf(
4343
"The current time is %d:%d:%d PM\n", currentHour - 12, currentMinute, currentSecond);
44-
else
44+
} else {
4545
System.out.printf(
4646
"The current time is %d:%d:%d AM\n", currentHour, currentMinute, currentSecond);
47+
}
4748
}
4849
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package com.github.jonathanbirkey.chapter03;

src/com/github/jonathanbirkey/chapter04/Exercise13.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ public static void main(String[] args) {
2828
|| letter == 'o'
2929
|| letter == 'O'
3030
|| letter == 'u'
31-
|| letter == 'U') System.out.printf("%c is a vowel", letter);
32-
else if (letter == 'b'
31+
|| letter == 'U') {
32+
System.out.printf("%c is a vowel", letter);
33+
} else if (letter == 'b'
3334
|| letter == 'B'
3435
|| letter == 'c'
3536
|| letter == 'C'
@@ -70,7 +71,10 @@ else if (letter == 'b'
7071
|| letter == 'y'
7172
|| letter == 'Y'
7273
|| letter == 'z'
73-
|| letter == 'Z') System.out.printf("%c is a consonant", letter);
74-
else System.out.printf("%c is an invalid input", letter);
74+
|| letter == 'Z') {
75+
System.out.printf("%c is a consonant", letter);
76+
} else {
77+
System.out.printf("%c is an invalid input", letter);
78+
}
7579
}
7680
}

src/com/github/jonathanbirkey/chapter04/Exercise26.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ public static void main(String[] args) {
2020
input.close();
2121

2222
String numberOfOneDollars;
23-
if (amount.length() == 3) numberOfOneDollars = "0";
24-
else numberOfOneDollars = amount.substring(0, amount.length() - 3);
23+
if (amount.length() == 3) {
24+
numberOfOneDollars = "0";
25+
} else {
26+
numberOfOneDollars = amount.substring(0, amount.length() - 3);
27+
}
2528

2629
int remainingAmount = Integer.parseInt(amount.substring(amount.length() - 2));
2730
int numberOfQuarters = remainingAmount / 25;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package com.github.jonathanbirkey.chapter04;

src/com/github/jonathanbirkey/chapter05/Exercise02.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
public class Exercise02 {
1414
public static void main(String[] args) {
15-
final int NUMBER_OF_QUESTIONS = 10;
15+
final int numberOfQuestions = 10;
1616
int correctCount = 0;
1717
int count = 0;
1818
long startTime = System.currentTimeMillis();
1919
String output = " ";
2020
Scanner input = new Scanner(System.in);
2121

22-
while (count < NUMBER_OF_QUESTIONS) {
22+
while (count < numberOfQuestions) {
2323
int number1 = (int) (Math.random() * 15) + 1;
2424
int number2 = (int) (Math.random() * 15) + 1;
2525

src/com/github/jonathanbirkey/chapter05/Exercise18.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ public static void main(String[] args) {
4646

4747
System.out.println("\nPattern D");
4848
for (int i = 1; i <= numOfLines; i++) {
49-
for (int k = 1; k < numOfLines - (numOfLines - i); k++) System.out.print(" ");
49+
for (int k = 1; k < numOfLines - (numOfLines - i); k++) {
50+
System.out.print(" ");
51+
}
5052
for (int j = 1; j <= numOfLines; j++) {
5153
if (j <= numOfLines - i + 1) {
5254
System.out.printf("%d ", j);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package com.github.jonathanbirkey.chapter05;

0 commit comments

Comments
 (0)