Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: I need help for my JAVA

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I need help for my JAVA

    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);
    }
    }
    Last edited by stephzaniag; March 16th, 2014 at 08:20 PM.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: I need help for my JAVA

    Welcome to the forum! Please read this topic to learn how to post code correctly and other useful info for new members.

    Please post your code correctly. Ask specific questions or describe exactly what you need help with. There's not much we can do with what you've posted until you make these changes and add the info needed to help you.

  3. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need help for my JAVA

    I'm a beginner so I just really copy and paste it. still learning I need to make a dialog box but don't know how if that helps

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I need help for my JAVA

    Also posted at: Help in my Java
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need help for my JAVA

    i don't know how to edit it there