|
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 |
| -} |
| 1 | +package com.codefortomorrow.intermediate.chapter11.practice.JingleRelays; |
| 2 | + |
| 3 | +/* |
| 4 | +This is the first of a series of problems. |
| 5 | +Credit: Christopher Haver, Computer Science, South Brunswick High School, New Jersey |
| 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 | +Only write code where the comments direct you to. |
| 15 | +*/ |
| 16 | + |
| 17 | +public class Jingle1 { |
| 18 | + |
| 19 | + public static void main(String[] args) { |
| 20 | + String song = ""; //DO NOT CHANGE THESE |
| 21 | + String winningString = |
| 22 | + "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 += ""; //Build your string here using the methods below to match the winning string |
| 26 | + |
| 27 | + /****** WRITE CODE ABOVE, NO CHANGES BELOW *******/ |
| 28 | + |
| 29 | + System.out.println(song); |
| 30 | + if (song.equals(winningString)) win(); else System.out.println( |
| 31 | + "Sorry, not quite right" |
| 32 | + ); |
| 33 | + } |
| 34 | + |
| 35 | + // YOU MAY NOT CHANGE ANY OF THE METHODS BELOW |
| 36 | + |
| 37 | + public static String jingle() { |
| 38 | + return "J\ni\nn\ng\nl\ne\n\n"; |
| 39 | + } |
| 40 | + |
| 41 | + public static String end(double x) { |
| 42 | + String outString = "A\nl\nl\n\n"; |
| 43 | + x *= -3.3; |
| 44 | + if (x < 0) outString += "N\ni\ng\nh\nt\n\n"; |
| 45 | + if (x != 0) outString += "T\nh\ne\n\nW\na\ny\n\n"; else outString += |
| 46 | + "Y\no\nu\n\nW\na\nn\nt\n\n"; |
| 47 | + return outString; |
| 48 | + } |
| 49 | + |
| 50 | + public static String jingleBells(int x) { |
| 51 | + String outString = ""; |
| 52 | + if (x == 2) { |
| 53 | + outString += jingle() + "B\ne\nl\nl\ns\n\n"; |
| 54 | + } |
| 55 | + outString += jingle() + "B\ne\nl\nl\ns\n\n"; |
| 56 | + return outString; |
| 57 | + } |
| 58 | + |
| 59 | + public static void win() { |
| 60 | + System.out.println("\n YOU WIN! \n"); |
| 61 | + System.out.println(" ((\\o/)) "); |
| 62 | + System.out.println(" .-----//^\\\\-----. "); |
| 63 | + System.out.println(" | /`| |`\\ | "); |
| 64 | + System.out.println(" | | | | "); |
| 65 | + System.out.println(" | | | | "); |
| 66 | + System.out.println(" | | | | "); |
| 67 | + System.out.println(" '------===------' \n\n"); |
| 68 | + } |
| 69 | +} |
0 commit comments