Page 1 of 2 12 LastLast
Results 1 to 20 of 24
  1. #1
    rahilpatel is offline Member
    Join Date
    Feb 2009
    Posts
    7
    Rep Power
    0

    Question I need Help.....

    Hi.
    i am studying Ready To Program JAVA @ my school
    and my teacher has told us to write a christmas songs and the question is



    "Your task is to write a program to display the song "We wish you a Merry Christmas" with a java program that uses methods to display all the lyrics. write the methods and the main methods. only method calls may be used in the main method."



    :confused::confused:can any one help me out here thanxxx:):)

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Have you made an attempt yet? If not, why not give it a try, and post it here? Good luck.

  3. #3
    adrija_ghosh is offline Member
    Join Date
    Feb 2009
    Posts
    11
    Rep Power
    0

    Default

    You can try this you can put the name of the site where the song is written using JSP will make your program easy or else you can write servlets but that will be a long program where you have to write get and post methods......

    <html>
    <head>
    <title>jsp example</title>
    <body>jsp exampls
    <br>
    <%!
    String sitename = "....anything...." ;
    int counter = 0 ;

    private void increment Counter()
    {

    counter ++ ;
    }
    %>

  4. #4
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default hhhmmm....

    From what I understand, you have to write a java program that uses methods to print the lyrics of "We wish you a Merry Christmas" (I think adrija was trying to answer another post).
    Divide the song into paragraphs and create a method (for each paragraph) that prints out the lyrics for that paragraph
    Some pseudo code:
    Java Code:
    Main
    {
      xMasPara1();
      xMasPara2();
      .
      .
      .
    }
    
    public void xMasPara1()
    {
      System.out.print ("We wish you a merry christmas...");
    }
    
    public void xMasPara2()
    {
      System.out.print ("Dashing through the snow ... ");
    }
    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  5. #5
    adrija_ghosh is offline Member
    Join Date
    Feb 2009
    Posts
    11
    Rep Power
    0

    Default

    Hi Chris....
    I didn't mean that......I meant that a JSP page can refer to the link whre the lyrics of the song is written or else you can try the following code......

    import javax.servlet.*;
    public class SampleServlet implements Servlet {
    private ServletConfig config;

    public void init (ServletConfig config)
    throws ServletException {
    this.config = config;
    }

    public void destroy() {} // do nothing

    public ServletConfig getServletConfig() {
    return config;
    }

    public String getServletInfo() {
    return "A Simple Servlet";
    }

    public void service (ServletRequest req,
    ServletResponse res
    ) throws ServletException, IOException {
    res.setContentType( "text/html" );
    PrintWriter out = res.getWriter();
    out.println( "<html>" );
    out.println( "<head>" );
    out.println( "<title>Merry Christmas</title>" );
    out.println( "</head>" );
    out.println( "<body>" );
    out.println( "<h1>We wish you a Merry Christmas</h1>" );
    out.println( "<h1>We wish you a Merry Christmas</h1>" );
    out.println( "<h1>We wish you a Merry Christmas</h1>" );
    out.println( "<h1>We wish you a Merry Christmas and Happy New year</h1>" );
    out.println( "<h1> Good tidings we bring to you and your kin </h1>" );
    out.println( "<h1> Good tidings for Christmas and a Happy New Year</h1>" );
    out.println( "</body>" );
    out.println( "</html>" );
    out.close();
    }
    }

  6. #6
    adrija_ghosh is offline Member
    Join Date
    Feb 2009
    Posts
    11
    Rep Power
    0

    Default

    Well there are other ways to do it also I will think over and tell you between you guys can explore other ways as well...........

  7. #7
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default huh... ok...

    Sorry for the misunderstanding and thanks for the clarification. I found your post confusing because neither JSP, nor links to Christmas carol sites was mentioned in the OP's post. It only mentioned a main method that calls methods and the output is the lyrics to "We Wish You a Merry Christmas".
    Maybe the Op can clarify.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  8. #8
    adrija_ghosh is offline Member
    Join Date
    Feb 2009
    Posts
    11
    Rep Power
    0

    Default

    No....issues Chris....you don't need to be sorry.....in the first post I wrote the answer in a hurry.....so it was my mistake.....well I will think over other ways also and you also try one.........

  9. #9
    rahilpatel is offline Member
    Join Date
    Feb 2009
    Posts
    7
    Rep Power
    0

    Unhappy Re: Cjslman

    i puted the same methode here see but my teacher said it's wrong!!!
    so is my teacher stupid or sumthin cuz thats what i think
    see
    here is my code for it







    public class MerryChristmas
    {
    public static void main (String [] args)
    {

    S1();
    S1();
    S1();
    S2();
    S3();
    S4();
    S5();
    S6();
    S6();
    S6();
    S7();
    S3();
    S4();
    S5();
    S6();
    S8();
    S8();
    S8();
    S9();
    S3();
    S4();
    S5();
    S6();
    S1();
    S1();
    S1();
    S2();
    S3();
    S4();
    S5();
    S10();
    }
    public static void S1 ()
    {
    System.out.println("We wish you a merry christmas");
    }
    public static void S2 ()
    {
    System.out.println("And a happy New Year");
    }
    public static void S3 ()
    {
    System.out.println("Glad tidings we bring");
    }

    public static void S4 ()
    {
    System.out.println("To you and your kin;");
    }

    public static void S5 ()
    {
    System.out.println("Glad tidings for Christmas");
    }

    public static void S6 ()
    {
    System.out.println("We want some figgy pudding");
    }

    public static void S7 ()
    {
    System.out.println("Please bring it right here!");
    }

    public static void S8 ()
    {
    System.out.println("We won't go untill we get some");
    }
    public static void S9 ()
    {
    System.out.println("So bring it out here");
    }
    public static void S10()
    {
    System.out.println("And a happy New Year!");
    }
    }

  10. #10
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default huh... OK...

    OK, so we need some clarification...
    • Did your teacher tell you why it was wrong ?
    • This is not want he wants or it's not the way he wants it?

    If this is not what he wants, then you have to go back to you're teacher and ask him for more explicit directions what he wants. If what is wrong is the way he wants it then I can see some areas of improvement. Here's the complete lyrics of WWYAMC:
    We wish you a merry Christmas
    We wish you a merry Christmas
    We wish you a merry Christmas

    And a happy New Year.
    Glad tidings we bring
    To you and your kin;
    Glad tidings for Christmas
    And a happy New Year!


    Now bring us some figgy pudding
    Now bring us figgy pudding
    Now bring us figgy pudding

    And a cup of good cheer!
    Glad tidings we bring
    To you and your kin;
    Glad tidings for Christmas
    And a happy New Year!


    We won't go until we get some
    We won't go until we get some
    We won't go until we get some

    So bring it out here!
    Glad tidings we bring
    To you and your kin;
    Glad tidings for Christmas
    And a happy New Year!


    We wish you a Merry Christmas
    We wish you a Merry Christmas
    We wish you a Merry Christmas

    And a happy New Year.
    Glad tidings we bring
    To you and your kin;
    Glad tidings for Christmas
    And a happy New Year!
    I have tried to show some of the similarities in the lyrics. The colors represent repeating paragraphs and the bold represent repeating lines.
    Assuming this is what your teacher wants:
    • Create a method that prints the repeating paragraphs.. one for "Glad tidings", another for "We wish you..", etc
    • For the repeating lines (bold), the method probably should have a for loop that prints the line as many times as needed
    .
    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  11. #11
    rahilpatel is offline Member
    Join Date
    Feb 2009
    Posts
    7
    Rep Power
    0

    Default RE:

    but the methode that i have used is correct thoo rite?:confused::confused:

  12. #12
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default

    Java Code:
    but the methode that i have used is correct thoo rite?
    You can answer that question yourself: does your program run and give the output that you want/need?

    It is VERY bad programming to call a method three times in a row (S1()). It is much better to call the method once and have that method print "we wish ..." three times.
    Also, you must give you're methods a meaningful name like "weWish()", "nowBring()", etc.
    Besides, your teacher didn't like the way you used the methods.

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  13. #13
    sp_29 is offline Member
    Join Date
    Feb 2009
    Location
    philippines
    Posts
    16
    Rep Power
    0

    Default

    i think you're right. by the way, hello to all. i am a new member......

  14. #14
    rahilpatel is offline Member
    Join Date
    Feb 2009
    Posts
    7
    Rep Power
    0

    Default Re: Cjslman

    I'm new to this programing
    i just started like a week a ago
    so i am preety bad at it but still
    i would like to take ur advice on how to fix that or rearrange it sum how so that i done have to repeat (S1()); that many times.
    thanxxxxxx :):):)

  15. #15
    rahilpatel is offline Member
    Join Date
    Feb 2009
    Posts
    7
    Rep Power
    0

    Unhappy Need Help here also

    i am asked to
    *ask the user to input their name and age
    *ask the user to input the current year
    *determine with a method their age in year 2050
    *display their name ,their current age and their age in 2050;



    i've been trying to do this but it just doesnt work out i have been trying since last 2days:(:(:(:(:(:(

  16. #16
    Join Date
    Oct 2008
    Posts
    73
    Rep Power
    0

    Default

    write ur cide here then we can solve it
    not have time to write hole code...
    Rakesh Mehta

  17. #17
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Guys, let's not be doing people's trivial homework for them.
    This post isn't even on-topic. This is the Applets forum.

  18. #18
    Join Date
    Oct 2008
    Posts
    73
    Rep Power
    0

    Default

    yes, you are right...
    :)
    Rakesh Mehta

  19. #19
    rahilpatel is offline Member
    Join Date
    Feb 2009
    Posts
    7
    Rep Power
    0

    Question What's wrong in here..................

    import java.io.*;

    public class CourseCode
    {
    public static void main (String [] args) throws IOException
    {
    BufferedReader kb = new BufferedReader (new InputStreamReader(System.in));

    System.out.println ();
    System.out.println("The following program accepts course code information where there are four possibilities");
    System.out.println("============================== ================================================== ========");
    System.out.println ();

    System.out.println ("Choose the course code name: (NRE) Religion, (ENG)lish, (MAT)h, (ICS)or(IDC) Computer Science");
    String code = kb.readLine ();
    code= (code.toUpperCase());

    System.out.println ("Enter your course year: (3) grade 11 or (4) grade 12 ");
    String grade1 = kb.readLine ();
    int grade=Integer.parseInt (grade1);
    grade= (grade.toUpperCase());

    System.out.println ("Enter your course level: (A)cademic or (P) Applied or (B)asic ");
    String level = kb.readLine ();
    level= (level.toUpperCase());
    System.out.println (String setMessage(code,grade,level));
    }//main method
    public static String setMessage(String code, int grade, String level)
    {
    {
    String setMessage;
    if (code.equals("NRE"))
    setMessage= "Religion";
    else if (code.equals("ENG"))
    setMessage= "English";
    else if (code.equals("MAT"))
    setMessage= "Math";
    else if (code.equals("ICS"+"IDC"))
    setMessage= "Computer Science";
    }
    {
    String setMessage;
    if (grade.equals ("3"))
    setMessage= "grade 11";
    else if (grade.equals("4"))
    setMessage= "grade 12";
    }
    {
    String setMessage;
    if (level.equals("A"))
    setMessage= "Academic";
    else if (level.equals("P"))
    setMessage= "Applied";
    else if (level.equals("B"))
    setMessage= "Basic";
    }

    System.out.println ("You are studying "+grade + code+ "at the " +level+ "level");
    return setMessage;
    } // method setMessage
    } // coursecode






    this program is giving me an error in this line :(:(:(
    "System.out.println (String setMessage(code,grade,level));" with the word setMessage can any one help me out?:confused:
    thanxxxxxxxxxxxxxxxxxxxx

  20. #20
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    In here:
    Java Code:
    System.out.println (String setMessage(code,grade,level));
    get rid of the "String" keyword. There's no reason for that to be there.

    There are also lots of other problems in this code including your redeclaring variables that shouldn't be redeclared. Have you talked to your instructor recently about tutoring? If not you would benefit by doing so. Soon.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •