Skip to content

Commit 79e5c8a

Browse files
committed
Add Jingle Relay problems
Add Jingle Relay problems to Ch. 11 Java
1 parent d061ae5 commit 79e5c8a

File tree

5 files changed

+443
-0
lines changed

5 files changed

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

0 commit comments

Comments
 (0)