I need to write a code for 12 twelve days of Christmas using 12 Controlled Repetition and 2 Switch Statements and need to put it on dialog box which is i don't know how. this is the code I have so far.
This is what my prof said "Your program should have a counter-controlled repitition, from 1 to 12, and two switch statements.In the second switch statement, the cases are ordered 12 to 1, and there is no break statement. Use conditional operator (? to output "A" or "and a" depending on if it is the first day"
JTextArea songArea = new JTextArea(20, 30);
JScrollPane scroller = new JScrollPane(songArea);
songArea.setText(songString);
JOptionPane.showMessageDialog(null, scroller, "Twelve Days of Christmas",
JOptionPane.PLAIN_MESSAGE);
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
public class Assig5 {
public static void main(String[] args) {
int number;
String prize = "";
String day = "";
String song = "";
System.out.print("");
number = 12;
System.out.println();
for (int j = 1; j <= number; j++)
{
switch (j)
{
case 1:
day = "First";
prize = "A Partridge in a Pear Tree \n ";
break;
case 2:
day = "Second";
prize = "\nTwo turtle doves, \nAnd " + prize;
break;
case 3:
day = "Third";
prize = "\nThree French Hens," + prize;
break;
case 4:
day = "Fourth";
prize = "\nFour Calling Birds," + prize;
break;
case 5:
day = "Five";
prize = "\nFive Golden Rings," + prize;
break;
case 6:
day = "Six";
prize = "\nSix Geese a Laying," + prize;
break;
case 7:
day = "Seven";
prize = "\nSeven Swans a Swimming," + prize;
break;
case 8:
day = "Eight";
prize = "\nEight Maids a Milking," + prize;
break;
case 9:
day = "Nine";
prize = "\nNine Ladies Dancing," + prize;
break;
case 10:
day = "Ten";
prize = "\nTen Lords a Leaping," + prize;
break;
case 11:
day = "Eleven";
prize = "\nEleven Pipers Piping," + prize;
break;
case 12:
day = "Twelve";
prize = "\n12 Drummers Drumming," + prize;
break;
}
song +="\nOn the " + day + " day of Christmas \nmy true love sent to me: " + prize;
}
System.out.println(song);
}
}