Skip to content

Commit 61b8773

Browse files
committed
beer-song: Adding beer song problem
1 parent 675bbe1 commit 61b8773

10 files changed

Lines changed: 176 additions & 4 deletions

File tree

‎config.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"simple-linked-list",
4242
"linked-list",
4343
"nth-prime",
44-
"pascals-triangle"
44+
"pascals-triangle",
45+
"beer-song"
4546
],
4647
"deprecated": [
4748
],

‎exercises/beer-song/build.gradle‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apply plugin: "java"
2+
apply plugin: "eclipse"
3+
apply plugin: "idea"
4+
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
testCompile "junit:junit:4.10"
11+
}

‎exercises/beer-song/src/example/java/.keep‎

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
public class BeerSong {
2+
public static String verse(int number)
3+
{
4+
switch (number)
5+
{
6+
case 0:
7+
return "No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n\n";
8+
case 1:
9+
return "1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n\n";
10+
case 2:
11+
return "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n\n";
12+
default:
13+
return String.format("%d bottles of beer on the wall, %d bottles of beer.\nTake one down and pass it around, %d bottles of beer on the wall.\n\n", number, number, number - 1);
14+
}
15+
}
16+
17+
public static String sing(int start, int stop)
18+
{
19+
StringBuilder songOutput = new StringBuilder();
20+
21+
for (int i=start; i>=stop; i--) {
22+
songOutput.append(verse(i));
23+
}
24+
25+
return songOutput.toString();
26+
}
27+
28+
public static String singSong() {
29+
return sing(99,0);
30+
}
31+
}

‎exercises/beer-song/src/main/java/.keep‎

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class BeerSong {
2+
3+
}

‎exercises/beer-song/src/test/java/.keep‎

Whitespace-only changes.

‎exercises/beer-song/src/test/java/BeerSongTest.java‎

Lines changed: 127 additions & 0 deletions
Large diffs are not rendered by default.

‎exercises/binary/src/test/java/BinaryTest.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ public static Collection<Object[]> data() {
2828
{"5", 0},
2929
{"9", 0},
3030
{"134678", 0},
31-
{"abc10", 0},
32-
{"10z", 0},
33-
{"10a10", 0},
31+
{"abc10z", 0},
3432
{"011", 3}
3533
});
3634
}

‎exercises/settings.gradle‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ include 'acronym'
33
include 'allergies'
44
include 'anagram'
55
include 'atbash-cipher'
6+
include 'beer-song'
67
include 'binary'
78
include 'bob'
89
include 'crypto-square'

0 commit comments

Comments
 (0)