6 Replies - 10550 Views - Last Post: 09 June 2006 - 06:38 PM Rate Topic: -----

#1 Dakine69302  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-June 06

12 days of christmas

Posted 09 June 2006 - 11:14 AM

Hey, i'm new on the site, but hopefully you guys can help. I'm supposed to write a program that prints out the twelve days of christmas song, and each time you hit enter, it prints out the next day. so it's supposed to go " on the first day of christmas my true love gave to me...a partridge in a pear tree." then hit the enter key and it goes onto "on the second day of christmas......two turtle doves and a partridge in a pear tree." So far i have this:

[color=#FF6666]public class Days{

static java.util.Scanner cin = new java.util.Scanner(System.in);
static java.io.PrintStream cout = System.out;

public static void main(String[] args) throws Exception {

for(int day = 1; day<= 12; day++) {
switch(day) {

case 12: cout.println("Twelve Drummers Drumming");
case 11: cout.println("Eleven Pipers Piping" );
case 10: cout.println("Ten Lords A-leaping" );
case 9: cout.println("Nine Ladies Dancing" );
case 8: cout.println("Eight Maids A-milking" );
case 7: cout.println("Seven Swans A-swimming");
case 6: cout.println("Six Geese A-laying" );
case 5: cout.println("Five Golden Rings" );
case 4: cout.println("Four Calling Birds" );
case 3: cout.println("Three French Hens" );
case 2: cout.println("Two Turtle Doves" );
case 1: cout.println("A partridge in a pear tree");
}
cin.nextLine();
}
}

and it prints out the days, but it doesn't put the part where it says" on the first day of christmas..." "on the second day of christmas"....Can someone help me?

Is This A Good Question/Topic? 0
  • +

Replies To: 12 days of christmas

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: 12 days of christmas

Posted 09 June 2006 - 11:30 AM

Well, you never ask it print that line...simply modify your print statements to include it.
Was This Post Helpful? 0
  • +
  • -

#3 Dakine69302  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-June 06

Re: 12 days of christmas

Posted 09 June 2006 - 11:36 AM

ok, but how do i get it to change the day where it says "on the xxxx day of christmas...." because it's got to change that every print out with everytime that you hit enter...cause if i add it on to the print line it will put it before everyline and it won't look right
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: 12 days of christmas

Posted 09 June 2006 - 12:43 PM

Incorporate the variable 'day' in your output, it is incrementing 1-12 so it will add the correct number based on the current count.

This post has been edited by jayman9: 09 June 2006 - 12:44 PM

Was This Post Helpful? 0
  • +
  • -

#5 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: 12 days of christmas

Posted 09 June 2006 - 01:04 PM

Is the number sufficient, or do you require the text representation?
Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: 12 days of christmas

Posted 09 June 2006 - 01:42 PM

View PostAmadeus, on 9 Jun, 2006 - 11:56 AM, said:

Is the number sufficient, or do you require the text representation?

Didn't realize he could have meant text version.

Would then need to incorporate a string variable in each case to hold the actual text version. Then add the string variable to the output statement.
Was This Post Helpful? 0
  • +
  • -

#7 GorillaCheif  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 78
  • Joined: 24-April 06

Re: 12 days of christmas

Posted 09 June 2006 - 06:38 PM

View Postjayman9, on 9 Jun, 2006 - 12:34 PM, said:

View PostAmadeus, on 9 Jun, 2006 - 11:56 AM, said:

Is the number sufficient, or do you require the text representation?

Didn't realize he could have meant text version.

Would then need to incorporate a string variable in each case to hold the actual text version. Then add the string variable to the output statement.


Dakine, I don't think he cares.
I think yours is set up different from mine, but here's an idea.

String outputDay = "",
outputVerse = "";

for (int day=0; day <= 12; day++ ) {
switch ( day ) {
case 0:
outputDay = ("1st");
outputVerse += ("A partridge in a pear tree\n");
break;


That way, your verses come out in sequential order (notice the "+")
and the day comes out in a loop when the program hits a later line...

outputTextArea.append("\n On the "+outputDay+" day of Christmas \n My"+
" true love gave to me\n "+ outputVerse);

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1