Thread: Help in my Java

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2014
    Posts
    3
    Rep Power
    0

    Help in my Java


    I have this code and I need to use 12 controlled repetition and 2 switch statements and then i have to put in Dialog box

    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);



    // Assign5 by Stephanie Aniag

    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);
    }
    }
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2014
    Posts
    3
    Rep Power
    0
    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.
  4. #3
  5. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,663
    Rep Power
    1958
    Never heard the expression "Controlled Repetition" as reference to loops.
    You are sure you need 12 of those?

    Would make more sense the requirement was 2 loops ("Controlled Repetition") and one switch with 12 cases.

    For Dialog box, maybe it will be good enough if you let the user ask how many days they want printed.
    In here the first loop would also be placed, to validate that the user only select 1 to 12 days.

    Then rest seems to be fine, using one loop and the switch with the 12 cases.

    Just one note about you number, you didn't use the ordered number all places, e.g. you started to use five instead fifth, six instead of sixth etc.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2014
    Posts
    3
    Rep Power
    0
    Originally Posted by MrFujin
    Never heard the expression "Controlled Repetition" as reference to loops.
    You are sure you need 12 of those?

    Would make more sense the requirement was 2 loops ("Controlled Repetition") and one switch with 12 cases.

    For Dialog box, maybe it will be good enough if you let the user ask how many days they want printed.
    In here the first loop would also be placed, to validate that the user only select 1 to 12 days.

    Then rest seems to be fine, using one loop and the switch with the 12 cases.

    Just one note about you number, you didn't use the ordered number all places, e.g. you started to use five instead fifth, six instead of sixth etc.

    i don't know how to put it on scroll box

IMN logo majestic logo threadwatch logo seochat tools logo