473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

almost got it .. Help please

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
2 1703
r035198x
13,262 8TB
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
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

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

Similar topics

3
by: Bart Nessux | last post by:
This is almost working. I've read up on queues and threads and I've learned a lot, still not enough to fully understand what I'm doing though, but I'm getting there. Much of this script was copied...
2
by: Irmen de Jong | last post by:
Hello I haven't received any responses on my original posting, and it could very well be that it never made it to the newsgroup (because I can't find it back on my news server here). So I'm...
8
by: Larry | last post by:
I have 2 pages on a site that will not validate as XHTML 2/CSS 2. They are http://www.ccmeonline.org/email.html and http://www.ccmeonline.org/pastpres.html. All the other pages validate without...
2
by: yoyo | last post by:
Hello I have four tables with the contractor field. These tables were created over the years by different people and the spelling is different in each table for the contractor field. I would to be...
12
by: eyoung | last post by:
Can someone tell me what I've done wrong here...this kinda works...but no cigar! I want to loop threw each "Service Number" and get all entries before going on to the next. What looks something...
1
by: swynne | last post by:
Hi friendly people...I am a newb to programming and need a little assistance. I have a small personal ad database created in Access, however all is well until I want the personal ad link to take me...
0
by: Jeff Rush | last post by:
The first regional Python unconference is coming to Houston on September 15-16 (Sat-Sun). Being held at the Texas Learning & Computing Center on the University of Houston main campus, this is a...
1
by: bearophileHUGS | last post by:
Once in a while I feel free to write about less defined things, saying mostly wrong things. This post is mostly chat, if you aren't interested please ignore it. Python is fit enough for newbie...
7
by: CodecSmash49 | last post by:
I am working on a game kind of like chess but with only 1 piece per a player. In the beginning they pick there stats(movement, HP, damage, and range of weapons). 10 pts to put where ever they like...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.