By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,760 Members | 1,630 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,760 IT Pros & Developers. It's quick & easy.

almost got it .. Help please

P: 14
I need my result to print out only in the box created with a scroll bar. It has to look like this.

The Twelve Days of It
by John H. Howard

On the First day of It
My true LOVE of Computers
sent to me:
A one Gig Jump drive

On the Second day of It
My true LOVE of Computers
sent to me:
Two LCD Monitors
and A one Gig Jump drive

On the Third day of It
My true LOVE of Computers
sent to me:
Three Floppy disks
Two LCD Monitors
and A one Gig Jump drive

On the Fourth day of It
My true LOVE of Computers
sent to me:
Four 512Mg SIMM's
Three Floppy disks
Two LCD Monitors
and A one Gig Jump drive

On the Fifth day of It
My true LOVE of Computers
sent to me:
Five Zip disks
Four 512Mg SIMM's
Three Floppy disks
Two LCD Monitors
and A one Gig Jump drive

On the Sixth day of It
My true LOVE of Computers
sent to me:
Six Tape Drives
Five Zip disks
Four 512Mg SIMM's
Three Floppy disks
Two LCD Monitors
and A one Gig Jump drive

On the Seventh day of It
My true LOVE of Computers
sent to me:
Seven Java Reference Books
Six Tape Drives
Five Zip disks
Four 512Mg SIMM's
Three Floppy disks
Two LCD Monitors
and A one Gig Jump drive

On the Eighth day of It
My true LOVE of Computers
sent to me:
Eight External Hard Drives
Seven Java Reference Books
Six Tape Drives
Five Zip disks
Four 512Mg SIMM's
Three Floppy disks
Two LCD Monitors
and A one Gig Jump drive

On the Ninth day of It
My true LOVE of Computers
sent to me:
Nine Network ISP's
Eight External Hard Drives
Seven Java Reference Books
Six Tape Drives
Five Zip disks
Four 512Mg SIMM's
Three Floppy disks
Two LCD Monitors
and A one Gig Jump drive

On the Tenth day of It
My true LOVE of Computers
sent to me:
Ten Websites Java Driven
Nine Network ISP's
Eight External Hard Drives
Seven Java Reference Books
Six Tape Drives
Five Zip disks
Four 512Mg SIMM's
Three Floppy disks
Two LCD Monitors
and A one Gig Jump drive

On the Eleventh day of It
My true LOVE of Computers
sent to me:
Eleven E-Commerce Accounts
Ten Websites Java Driven
Nine Network ISP's
Eight External Hard Drives
Seven Java Reference Books
Six Tape Drives
Five Zip disks
Four 512Mg SIMM's
Three Floppy disks
Two LCD Monitors
and A one Gig Jump drive

On the Twelfth day of It
My true LOVE of Computers
sent to me:
Twelve Dedicated T3 Lines
Eleven E-Commerce Accounts
Ten Websites Java Driven
Nine Network ISP's
Eight External Hard Drives
Seven Java Reference Books
Six Tape Drives
Five Zip disks
Four 512Mg SIMM's
Three Floppy disks
Two LCD Monitors
and A one Gig Jump drive

but it needs to all be in the box that is created from the first part of the code. I need to build the loop display and add it to the current one each time the loop runs. I tried writing it to a file and then calling the file .. did not work. I know this is real close but I am still missing something.

Here is the code.::


public class TwelveDays {//beginning of the Class of Twelve Days

private static void showLyrics(String myLyrics) {//Class assigned box generator**********make it accessible
javax.swing.JTextArea outArea;
javax.swing.JScrollPane scroller;

outArea = new javax.swing.JTextArea(20, 35);
outArea.setText(myLyrics);
scroller = new javax.swing.JScrollPane(outArea);
javax.swing.JOptionPane.showMessageDialog(null, scroller,
"The Twelve Days of Technology",
javax.swing.JOptionPane.
INFORMATION_MESSAGE);
} //showLyrics

public static void main(String args[]) { //This is the Main Method
// print heading
System.out.println("The Twelve Days of It\n"
+ "by John H. Howard\n");

// loop through the twelve days
String toBeDisplayed = "";

for (int i = 1; i <= 12; i++) {
// print beginning of each day's verse
System.out.println("On the " + chooseDay(i) + " day of It");
System.out.println("My true LOVE of Computers\n" +
"sent to me:");

// count down through days already passed in reverse order
// if first day, final verse slightly different
// "A " vs. "and a "
// Eating my own doggie food..
if (i == 1) {
System.out.println("A " + myLyrics(i));
}
else {
for (int j = i; j >= 2; j--) {
System.out.println(myLyrics(j));
}
System.out.println("and A " + myLyrics(1));
toBeDisplayed = toBeDisplayed + "\n" + myLyrics(i);
}
// *****************Call the method

// song done, extra line
System.out.println();
}
TwelveDays.showLyrics(toBeDisplayed);

}

public static String chooseDay(int x) { //Method for the days-Case Begins
String day;

switch (x) {
case 1:
day = "First";
break;

case 2:
day = "Second";
break;

case 3:
day = "Third";
break;

case 4:
day = "Fourth";
break;

case 5:
day = "Fifth";
break;

case 6:
day = "Sixth";
break;

case 7:
day = "Seventh";
break;

case 8:
day = "Eighth";
break;

case 9:
day = "Ninth";
break;

case 10:
day = "Tenth";
break;

case 11:
day = "Eleventh";
break;

case 12:
day = "Twelfth";
break;

default:
day = "";
break;
}

return day;
}

public static String myLyrics(int x) { //Method to Reverse Order
String lyrics;

switch (x) { //Song Case list
case 1:
lyrics = "one Gig Jump drive";
break;

case 2:
lyrics = "Two LCD Monitors";
break;

case 3:
lyrics = "Three Floppy disks";
break;

case 4:
lyrics = "Four 512Mg SIMM's";
break;

case 5:
lyrics = "Five Zip disks";
break;

case 6:
lyrics = "Six Tape Drives";
break;

case 7:
lyrics = "Seven Java Reference Books";
break;

case 8:
lyrics = "Eight External Hard Drives";
break;

case 9:
lyrics = "Nine Network ISP's";
break;

case 10:
lyrics = "Ten Websites Java Driven";
break;

case 11:
lyrics = "Eleven E-Commerce Accounts";
break;

case 12:
lyrics = "Twelve Dedicated T3 Lines";
break;

default:
lyrics = "";
break;
}

return lyrics; //Reverse the Case Display
}
} //This is the end of the Twelve Days of It.

end of the code.

There does not need to be any println command. I just put those in to get my print out correct. Thought it would be easy to just move the print out to the box. Boy was I wrong.

Thanks for the help..
Oct 27 '06 #1
Share this Question
Share on Google+
2 Replies


10K+
P: 13,264
Expand|Select|Wrap|Line Numbers
  1. public class TwelveDays {//beginning of the Class of Twelve Days
  2.  
  3. private static void showLyrics(String myLyrics) {//Class assigned box generator**********make it accessible
  4. javax.swing.JTextArea outArea;
  5. javax.swing.JScrollPane scroller;
  6.  
  7. outArea = new javax.swing.JTextArea(20, 35);
  8. outArea.setText(myLyrics);
  9. scroller = new javax.swing.JScrollPane(outArea);
  10. javax.swing.JOptionPane.showMessageDialog(null, scroller,
  11. "The Twelve Days of Technology",
  12. javax.swing.JOptionPane.
  13. INFORMATION_MESSAGE);
  14. } //showLyrics
  15.  
  16. public static void main(String args[]) { //This is the Main Method
  17. // print heading
  18. System.out.println("The Twelve Days of It\n"
  19. + "by John H. Howard\n");
  20.  
  21. // loop through the twelve days
  22. String toBeDisplayed = "The Twelve Days of It\n"+ "by John H. Howard\n";
  23.  
  24. for (int i = 1; i <= 12; i++) {
  25. // print beginning of each day's verse
  26. System.out.println("On the " + chooseDay(i) + " day of It");
  27. toBeDisplayed += "\nOn the " + chooseDay(i) + " day of It\n";
  28. System.out.println("My true LOVE of Computers\n" + "sent to me:");
  29. toBeDisplayed += "My true LOVE of Computers" + "sent to me:\n";
  30. // count down through days already passed in reverse order
  31. // if first day, final verse slightly different
  32. // "A " vs. "and a "
  33. // Eating my own doggie food..
  34. if (i == 1) {
  35. System.out.println("A " + myLyrics(i));
  36. toBeDisplayed += "A " + myLyrics(i)+"\n";
  37. }
  38. else {
  39. for (int j = i; j >= 2; j--) {
  40. System.out.println(myLyrics(j));
  41. toBeDisplayed += myLyrics(j) + "\n";
  42. }
  43. System.out.println("and A " + myLyrics(1));
  44. toBeDisplayed += "and A " + myLyrics(1) + "\n";
  45. }
  46. // *****************Call the method
  47.  
  48. // song done, extra line
  49. System.out.println();
  50. }
  51. TwelveDays.showLyrics(toBeDisplayed);
  52.  
  53. }
  54.  
  55. public static String chooseDay(int x) { //Method for the days-Case Begins
  56. String day;
  57.  
  58. switch (x) {
  59. case 1:
  60. day = "First";
  61. break;
  62.  
  63. case 2:
  64. day = "Second";
  65. break;
  66.  
  67. case 3:
  68. day = "Third";
  69. break;
  70.  
  71. case 4:
  72. day = "Fourth";
  73. break;
  74.  
  75. case 5:
  76. day = "Fifth";
  77. break;
  78.  
  79. case 6:
  80. day = "Sixth";
  81. break;
  82.  
  83. case 7:
  84. day = "Seventh";
  85. break;
  86.  
  87. case 8:
  88. day = "Eighth";
  89. break;
  90.  
  91. case 9:
  92. day = "Ninth";
  93. break;
  94.  
  95. case 10:
  96. day = "Tenth";
  97. break;
  98.  
  99. case 11:
  100. day = "Eleventh";
  101. break;
  102.  
  103. case 12:
  104. day = "Twelfth";
  105. break;
  106.  
  107. default:
  108. day = "";
  109. break;
  110. }
  111.  
  112. return day;
  113. }
  114.  
  115. public static String myLyrics(int x) { //Method to Reverse Order
  116. String lyrics;
  117.  
  118. switch (x) { //Song Case list
  119. case 1:
  120. lyrics = "one Gig Jump drive";
  121. break;
  122.  
  123. case 2:
  124. lyrics = "Two LCD Monitors";
  125. break;
  126.  
  127. case 3:
  128. lyrics = "Three Floppy disks";
  129. break;
  130.  
  131. case 4:
  132. lyrics = "Four 512Mg SIMM's";
  133. break;
  134.  
  135. case 5:
  136. lyrics = "Five Zip disks";
  137. break;
  138.  
  139. case 6:
  140. lyrics = "Six Tape Drives";
  141. break;
  142.  
  143. case 7:
  144. lyrics = "Seven Java Reference Books";
  145. break;
  146.  
  147. case 8:
  148. lyrics = "Eight External Hard Drives";
  149. break;
  150.  
  151. case 9:
  152. lyrics = "Nine Network ISP's";
  153. break;
  154.  
  155. case 10:
  156. lyrics = "Ten Websites Java Driven";
  157. break;
  158.  
  159. case 11:
  160. lyrics = "Eleven E-Commerce Accounts";
  161. break;
  162.  
  163. case 12:
  164. lyrics = "Twelve Dedicated T3 Lines";
  165. break;
  166.  
  167. default:
  168. lyrics = "";
  169. break;
  170. }
  171.  
  172. return lyrics; //Reverse the Case Display
  173. }
  174. } //This is the end of the Twelve Days of It.
Like this?
Oct 28 '06 #2

P: 14
that is so excellent. I get it. Had a couple other things to fix, but I get it now.

Thanks so much. there are no Java tutors at school, and I knew the code was close but I was just messing it up with errors. I needed it looked at and reviewed. Thanks more than you know.

I now know where to come for help. You guys are great. I only have one project left. Thanks again..
Oct 28 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.