• Trouble logging in? Send us a message with your username and/or email address for help.

Song Title game....

New posts
The Twelve Days of Christmas

import javax.swing.*;

public class twelveDaysOfChristmas
{
public static void main( String args [] )
{
JTextArea outputArea = new JTextArea( 40, 50 );

JScrollPane scroller = new JScrollPane( outputArea );

int day;

String output = " ";

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

output += "On the ";

switch ( day )
{

case 1:output +="first";break;

case 2:output +="second";break;

case 3:output +="third";break;

case 4:output +="fourth";break;

case 5:output +="fifth";break;

case 6:output +="sixth";break;

case 7:output +="seventh";break;

case 8:output +="eighth";break;

case 9:output +="ninth";break;

case 10:output +="tenth";break;

case 11:output +="eleventh";break;

case 12:output +="twelfth";break;
}
output += " day of Chrismas my true love gave to me\n";

switch ( day )
{
case 12:output +="Twelve drummers drumming\n";

case 11:output +="Eleven pipers piping\n";

case 10:output +="Ten lords a-leaping\n";

case 9:output +="Nine ladies dancing\n";

case 8:output +="Eight maids a-milking\n";

case 7:output +="Seven swans a-swimming\n";

case 6:output +="Six geese a-laying\n";

case 5:output +="FIVE GOLDEN RINGS\n";

case 4:output +="Four calling birds\n";

case 3:output +="Three French hens\n";

case 2:output +="Two turtle doves\n";

case 1:if(day == 1)output += "A partridge in a pear tree\n";

else output +="And a partridge in a pear tree\n";

}
}
outputArea.setText( output );

JOptionPane.showMessageDialog

(null, scroller, "TwelveDaysOfChristmas",

JOptionPane.PLAIN_MESSAGE );

System.exit( 0 );

}

}
 
Last edited:
New posts


Sign Up for SoWal Newsletter












                               
Back
Top