Skip to content

Commit 4e0a8aa

Browse files
committed
Add Jingle Bell Solutions
Create solutions to Jingle Bell Relay Problems
1 parent 79e5c8a commit 4e0a8aa

File tree

5 files changed

+460
-0
lines changed

5 files changed

+460
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.codefortomorrow.intermediate.chapter11.solutions.JingleRelays;
2+
/*
3+
This is the first of a series of problems.
4+
Problem Credit: Christopher Haver, Computer Science, South Brunswick High School, New Jersey
5+
6+
7+
Jingle Bell Challenge! Problem 1
8+
9+
Using ony method calls and the String song. Print
10+
"Jingle Bells Jingle Bells Jingle All The Way" vertically
11+
with one letter on each line. If you do so correctly
12+
the "You Win!" graphic will print at the bottom.
13+
14+
This is one of a few possible solutions.
15+
*/
16+
17+
public class Jingle1{
18+
19+
public static void main(String[]args){
20+
21+
String song = ""; //DO NOT CHANGE THESE
22+
String winningString = "J\ni\nn\ng\nl\ne\n\nB\ne\nl\nl\ns\n\nJ\ni\nn\ng\nl\ne\n\nB\ne\nl\nl\ns\n\nJ\ni\nn\ng\nl\ne\n\nA\nl\nl\n\nT\nh\ne\n\nW\na\ny\n\n";
23+
24+
/***** ONLY WRITE THE CODE BETWEEN THESE COMMENTS TO CALL METHODS FOR A SOLUTION ******/
25+
song += jingleBells(2) + jingle() + end(-2);
26+
27+
/****** WRITE CODE ABOVE, NO CHANGES BELOW *******/
28+
29+
System.out.println(song);
30+
if (song.equals(winningString))
31+
win();
32+
else
33+
System.out.println("Sorry, not quite right");
34+
35+
}
36+
37+
// YOU MAY NOT CHANGE ANY OF THE METHODS BELOW
38+
39+
public static String jingle(){
40+
return "J\ni\nn\ng\nl\ne\n\n";
41+
}
42+
43+
public static String end(double x){
44+
String outString = "A\nl\nl\n\n";
45+
x *= -3.3;
46+
if (x < 0)
47+
outString += "N\ni\ng\nh\nt\n\n";
48+
if (x != 0)
49+
outString += "T\nh\ne\n\nW\na\ny\n\n";
50+
else
51+
outString += "Y\no\nu\n\nW\na\nn\nt\n\n";
52+
return outString;
53+
}
54+
55+
public static String jingleBells(int x){
56+
String outString = "";
57+
if (x == 2){
58+
outString += jingle() + "B\ne\nl\nl\ns\n\n";
59+
}
60+
outString += jingle() + "B\ne\nl\nl\ns\n\n";
61+
return outString;
62+
63+
64+
}
65+
66+
67+
public static void win(){
68+
System.out.println("\n YOU WIN! \n");
69+
System.out.println(" ((\\o/)) ");
70+
System.out.println(" .-----//^\\\\-----. ");
71+
System.out.println(" | /`| |`\\ | ");
72+
System.out.println(" | | | | ");
73+
System.out.println(" | | | | ");
74+
System.out.println(" | | | | ");
75+
System.out.println(" '------===------' \n\n");
76+
77+
}
78+
79+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package com.codefortomorrow.intermediate.chapter11.solutions.JingleRelays;
2+
/*
3+
This is the second of a series of problems.
4+
Problem Credit: Christopher Haver, Computer Science, South Brunswick High School, New Jersey
5+
6+
7+
Jingle Bell Challenge! Problem 2
8+
9+
Using ony method calls and the String song. Print
10+
"Jingle Bells Jingle Bells Jingle All The Way" vertically
11+
with one letter on each line. If you do so correctly
12+
the "You Win!" graphic will print at the bottom.
13+
14+
This is one of a few possible solutions.
15+
*/
16+
17+
public class Jingle2{
18+
19+
public static void main(String[]args){
20+
21+
String song = ""; //DO NOT CHANGE THESE
22+
String winningString = "J\ni\nn\ng\nl\ne\n\nB\ne\nl\nl\ns\n\nJ\ni\nn\ng\nl\ne\n\nB\ne\nl\nl\ns\n\nJ\ni\nn\ng\nl\ne\n\nA\nl\nl\n\nT\nh\ne\n\nW\na\ny\n\n";
23+
24+
/***** ONLY WRITE THE CODE BETWEEN THESE COMMENTS TO CALL METHODS FOR A SOLUTION ******/
25+
song += ingleElls("j","b") + ingleElls("j","b") + J() + ingle() + end(true,false);
26+
27+
28+
29+
/****** WRITE CODE ABOVE, NO CHANGES BELOW *******/
30+
31+
System.out.println(song);
32+
if (song.equals(winningString))
33+
win();
34+
else
35+
System.out.println("Sorry, not quite right");
36+
37+
}
38+
39+
// YOU MAY NOT CHANGE ANY OF THE METHODS BELOW
40+
41+
public static String ingle(){
42+
return "i\nn\ng\nl\ne\n\n";
43+
}
44+
45+
public static String J(){
46+
return "J\n";
47+
}
48+
49+
public static String B(){
50+
return "B\n";
51+
}
52+
53+
public static String end(boolean x, boolean y){
54+
String outString = "A\nl\nl\n\n";
55+
if (!(x || !y))
56+
outString += "N\ni\ng\nh\nt\n\n";
57+
if (x !=y && !y)
58+
outString += "T\nh\ne\n\nW\na\ny\n\n";
59+
if (x == y && x)
60+
outString += "Y\no\nu\n\nW\na\nn\nt\n\n";
61+
return outString;
62+
}
63+
64+
public static String ingleElls(String a, String b){
65+
66+
switch (a) {
67+
case "j": a = J();
68+
break;
69+
case "J": a = "j\n\n";
70+
break;
71+
default:
72+
a = "B\n\n";
73+
}
74+
switch (b){
75+
case "b": b = B();
76+
break;
77+
case "B": b = "b\n\n";
78+
break;
79+
default: a = "J\n\n";
80+
81+
}
82+
83+
84+
return a + ingle()+ b + "e\nl\nl\ns\n\n";
85+
86+
87+
}
88+
89+
90+
public static void win(){
91+
System.out.println("\n YOU WIN! \n");
92+
System.out.println(" ((\\o/)) ");
93+
System.out.println(" .-----//^\\\\-----. ");
94+
System.out.println(" | /`| |`\\ | ");
95+
System.out.println(" | | | | ");
96+
System.out.println(" | | | | ");
97+
System.out.println(" | | | | ");
98+
System.out.println(" '------===------' \n\n");
99+
100+
}
101+
102+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.codefortomorrow.intermediate.chapter11.solutions.JingleRelays;
2+
/*
3+
This is the third of a series of problems.
4+
Problem Credit: Christopher Haver, Computer Science, South Brunswick High School, New Jersey
5+
6+
7+
Jingle Bell Challenge! Problem 3
8+
9+
Using ony method calls and the String song. Print
10+
"Jingle Bells Jingle Bells Jingle All The Way" vertically
11+
with one letter on each line. If you do so correctly
12+
the "You Win!" graphic will print at the bottom.
13+
14+
This is one of a few possible solutions.
15+
*/
16+
public class Jingle3{
17+
18+
public static void main(String[]args){
19+
20+
String song = ""; //DO NOT CHANGE THESE
21+
String winningString = "J\ni\nn\ng\nl\ne\n\nB\ne\nl\nl\ns\n\nJ\ni\nn\ng\nl\ne\n\nB\ne\nl\nl\ns\n\nJ\ni\nn\ng\nl\ne\n\nA\nl\nl\n\nT\nh\ne\n\nW\na\ny\n\n";
22+
23+
/***** ONLY WRITE THE CODE BETWEEN THESE COMMENTS TO CALL METHODS FOR A SOLUTION ******/
24+
25+
song += jingleBells(6,1) + jingleBells(6,1) + jingle() + end(98,99,100,101,102);
26+
27+
28+
/****** WRITE CODE ABOVE, NO CHANGES BELOW *******/
29+
30+
System.out.println(song);
31+
if (song.equals(winningString))
32+
win();
33+
else
34+
System.out.println("Sorry, not quite right");
35+
36+
}
37+
38+
// YOU MAY NOT CHANGE ANY OF THE METHODS BELOW
39+
40+
public static String jingle(){
41+
return "J\ni\nn\ng\nl\ne\n\n";
42+
}
43+
44+
public static String end(int a, int b, int c, int d, int e){
45+
String outString = "A\nl\nl\n\n";
46+
int sum = a + b + c + d + e;
47+
double mean = (a + b + c + d + e) / 5.0;
48+
if (sum >= 473)
49+
if (a != b && b != c && c!= d && d != e )
50+
if (mean == 100.0)
51+
outString += "T\nh\ne\n\nW\na\ny\n\n";
52+
else
53+
outString += "N\ni\ng\nh\nt\n\n";
54+
else
55+
outString += "Y\no\nu\n\nW\na\nn\nt\n\n";
56+
else
57+
outString += "A\nr\no\nu\nn\nd\n\n";
58+
return outString;
59+
}
60+
61+
public static String jingleBells(int a,int b){
62+
String outputString = "";
63+
switch (a % 7) {
64+
case 6: outputString += "J\n";
65+
case 5: outputString += "i\n";
66+
case 4: outputString += "n\n";
67+
case 3: outputString += "g\n";
68+
case 2: outputString += "l\n";
69+
case 1: outputString += "e\n";
70+
default: outputString += "\n";
71+
72+
}
73+
74+
switch (a /b ){
75+
case 6: outputString += "B\ne\nl\nl\ns\n\n";
76+
break;
77+
default: outputString += "B\nl\no\nr\np\n\n";
78+
}
79+
return outputString;
80+
81+
82+
}
83+
84+
85+
public static void win(){
86+
System.out.println("\n YOU WIN! \n");
87+
System.out.println(" ((\\o/)) ");
88+
System.out.println(" .-----//^\\\\-----. ");
89+
System.out.println(" | /`| |`\\ | ");
90+
System.out.println(" | | | | ");
91+
System.out.println(" | | | | ");
92+
System.out.println(" | | | | ");
93+
System.out.println(" '------===------' \n\n");
94+
95+
}
96+
97+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package com.codefortomorrow.intermediate.chapter11.solutions.JingleRelays;
2+
/*
3+
This is the fourth of a series of problems.
4+
Problem Credit: Christopher Haver, Computer Science, South Brunswick High School, New Jersey
5+
6+
Jingle Bell Challenge! Problem 4
7+
8+
Using ony method calls and the String song. Print
9+
"Jingle Bells Jingle Bells Jingle All The Way" vertically
10+
with one letter on each line. If you do so correctly
11+
the "You Win!" graphic will print at the bottom.
12+
13+
This is one of a few possible solutions.
14+
*/
15+
public class Jingle4{
16+
17+
public static void main(String[]args){
18+
19+
String song = ""; //DO NOT CHANGE THESE
20+
String winningString = "J\ni\nn\ng\nl\ne\n\nB\ne\nl\nl\ns\n\nJ\ni\nn\ng\nl\ne\n\nB\ne\nl\nl\ns\n\nJ\ni\nn\ng\nl\ne\n\nA\nl\nl\n\nT\nh\ne\n\nW\na\ny\n\n";
21+
22+
/***** ONLY WRITE THE CODE BETWEEN THESE COMMENTS TO CALL METHODS FOR A SOLUTION ******/
23+
24+
song += jingleBells(46) + jingleBells(57) + jingleBells(58) + jingleBells(46) + jingleBells(57) + jingleBells(58) + jingleBells(46) + end(true,true,true,false);
25+
/****** WRITE CODE ABOVE, NO CHANGES BELOW *******/
26+
27+
System.out.println(song);
28+
if (song.equals(winningString))
29+
win();
30+
else
31+
System.out.println("Sorry, not quite right");
32+
33+
}
34+
35+
// YOU MAY NOT CHANGE ANY OF THE METHODS BELOW
36+
37+
38+
public static String end(boolean a, boolean b, boolean c, boolean d){
39+
boolean flag = (!(a && !b) || c && !d);
40+
String outString = "";
41+
if (flag)
42+
outString = "A\nl\nl\n\nT\nh\ne\n\nW\na\ny\n\n";
43+
else
44+
outString = "A\nl\nl\n\nD\na\ny\n\nL\no\nn\ng\n\n";
45+
46+
47+
48+
return outString;
49+
}
50+
51+
public static String jingleBells(int a){
52+
String outputString = "";
53+
switch ((a/2) % 17) {
54+
case 12: outputString += "\n";
55+
break;
56+
case 11: outputString += "B\n";
57+
case 10: outputString += "e\n";
58+
case 9: outputString += "l\n";
59+
case 8: outputString += "l\n";
60+
case 7: outputString += "s\n";
61+
break;
62+
63+
case 6: outputString += "J\n";
64+
case 5: outputString += "i\n";
65+
case 4: outputString += "n\n";
66+
case 3: outputString += "g\n";
67+
case 2: outputString += "l\n";
68+
case 1: outputString += "e\n\n";
69+
break;
70+
71+
}
72+
73+
74+
return outputString;
75+
76+
77+
}
78+
79+
80+
public static void win(){
81+
System.out.println("\n YOU WIN! \n");
82+
System.out.println(" ((\\o/)) ");
83+
System.out.println(" .-----//^\\\\-----. ");
84+
System.out.println(" | /`| |`\\ | ");
85+
System.out.println(" | | | | ");
86+
System.out.println(" | | | | ");
87+
System.out.println(" | | | | ");
88+
System.out.println(" '------===------' \n\n");
89+
90+
}
91+
92+
}

0 commit comments

Comments
 (0)