Skip to content
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Susan
Jeremiah
Josh
Kati
Sher
Lin
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SUSAN
JEREMIAH
JOSH
KATI
SHER
LIN
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
35
94
16
38
82
87
52
60
86
59
72
7
60
56
63
11
67
77
67
82
28
13
100
92
85
69
75
6
83
100
76
51
13
84
59
30
21
72
15
28
15
95
87
61
80
22
45
9
73
85
85
2
90
75
60
80
91
21
80
41
82
27
48
43
37
52
78
21
54
20
15
49
42
89
63
24
10
62
44
63
51
34
36
21
2
49
64
77
34
80
7
83
51
46
11
25
59
96
21
65
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
35
94
16
38
82
87
52
60
86
59
72
7
60
56
63
11
67
77
67
82
28
13
100
92
85
69
75
6
83
100
76
51
13
84
59
30
21
72
15
28
15
95
87
61
80
22
45
9
73
85
85
2
90
75
60
80
91
21
80
41
82
27
48
43
37
52
78
21
54
20
15
49
42
89
63
24
10
62
44
63
51
34
36
21
2
49
64
77
34
80
7
83
51
46
11
25
59
96
21
65
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.codefortomorrow.advanced.chapter13.examples;

// Convert the iterative gcd algorithm to a recursive algorithm.

public class IterToRecursive {

public static void main(String[] args) {
System.out.println("With iterative function:");

int a = 72, b = 20;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
Each variable declaration must be in its own statement.

while (a != b) {
if (a > b) a -= b; else if (b > a) b -= a;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
'if' construct must use '{}'s.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
'if' construct must use '{}'s.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
Only one statement per line allowed.

}
System.out.println("GCD:" + a);

System.out.println("With recursive function:");
System.out.println("GCD:" + gcd(72, 20));
}

// Recursive function
public static int power(int base, int exp) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
Missing a Javadoc comment.

// Base case: exp = 0, so the result is 1.
if (exp == 0) return 1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
'if' construct must use '{}'s.


// Multiply once by the previous power.
return power(base, exp - 1) * base;
}

public static int gcd(int a, int b) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
Missing a Javadoc comment.

// Base case
if (a == b) return a; else if (a > b) return gcd(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
'if' construct must use '{}'s.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
'if' construct must use '{}'s.

a - b,
b
); else return gcd(a, b - a);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
Only one statement per line allowed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
'else' construct must use '{}'s.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
Only one statement per line allowed.

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.codefortomorrow.advanced.chapter13.practice;

/*
Implement the iterative code as a recursive
function to clarify what the algorithm does.
*/

public class NegativeSum {

public static void main(String[] args) {
System.out.println("Iterative:");
int a = 50, b = 40;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
Each variable declaration must be in its own statement.

while (a + b > 0) {
if (Math.pow(a, 2) + Math.pow(b, 2) > 10000) {
a *= 8;
b *= -4;
} else {
a *= 3;
b /= 2;
}
}
System.out.println("a + b: " + (a + b));

System.out.println("Recursive:");
System.out.println(negSum(50, 40));
}

public static int negSum(int a, int b) {
// Insert code here and change return statement.
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.codefortomorrow.advanced.chapter13.practice;

/*
Implement the iterative code as a recursive
function to clarify what the algorithm does.
*/

public class NegativeSum {

public static void main(String[] args) {
System.out.println("Iterative:");
int a = 50, b = 40;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
Each variable declaration must be in its own statement.

while (a + b > 0) {
if (Math.pow(a, 2) + Math.pow(b, 2) > 10000) {
a *= 8;
b *= -4;
} else {
a *= 3;
b /= 2;
}
}
System.out.println("a + b: " + (a + b));

System.out.println("Recursive:");
System.out.println(negSum(50, 40));
}

public static int negSum(int a, int b) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
Missing a Javadoc comment.

if (a + b <= 0) return a + b;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
'if' construct must use '{}'s.

if (Math.pow(a, 2) + Math.pow(b, 2) > 10000) return negSum(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
'if' construct must use '{}'s.

a * 8,
b * -4
); else return negSum(a * 3, b / 2);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
'else' construct must use '{}'s.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
Only one statement per line allowed.

}
}
27 changes: 27 additions & 0 deletions src/com/codefortomorrow/advanced/chapter14/examples/FileIO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.codefortomorrow.advanced.chapter14.examples;

import java.io.*;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
Using the '.' form of import should be avoided - java.io..


public class FileIO {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
Abbreviation in name 'FileIO' must contain no more than '1' consecutive capital letters.


public static void main(String[] args) throws IOException {
FileInputStream in = null;
FileOutputStream out = null;
File file = new File("names.txt");

try {
in = new FileInputStream(file);
out = new FileOutputStream("names_upper.txt");
int c;
while ((c = in.read()) != -1) out.write(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
'while' construct must use '{}'s.

Character.toUpperCase((char) c)
);
} catch (IOException e) {
System.out.println("An IO Exception occurred.");
e.printStackTrace(); // Prints error output stream.
} finally {
if (in != null) in.close();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
'if' construct must use '{}'s.

if (out != null) out.close();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
'if' construct must use '{}'s.

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.codefortomorrow.advanced.chapter14.examples;

public class MyException extends Exception {

public MyException() {}

public MyException(String message) {
super(message);
}
}
19 changes: 19 additions & 0 deletions src/com/codefortomorrow/advanced/chapter14/examples/Throw.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.codefortomorrow.advanced.chapter14.examples;

public class Throw {

public static void main(String[] args) {
try {
System.out.println(divide(7, 2));
} catch (ArithmeticException e) {
System.out.println("There was an arithmetic exception.");
}
}

public static int divide(int a, int b) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
Missing a Javadoc comment.

int result = a / b;
if (result != (double) a / (double) b) throw new ArithmeticException();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reviewdog] reported by reviewdog 🐶
'if' construct must use '{}'s.

System.out.println("Got to end of divide()");
return a / b;
}
}
Loading