Page 2 of 4 FirstFirst 1234 LastLast
Results 21 to 40 of 77
Like Tree1Likes

Thread: I have tried this many times and I don't get the correct code.

  1. #21
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default Re: I have tried this many times and I don't get the correct code.

    I compiled this and got no errors.
    Good, you are making progress.
    What happened when you executed it?

    When posting code be sure to wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  2. #22
    Clemson is offline Member
    Join Date
    Feb 2014
    Posts
    49
    Rep Power
    0

    Default Re: I have tried this many times and I don't get the correct code.

    When I try ( I am using NotePad) and it says it can't find Abbott_Assign4

  3. #23
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default Re: I have tried this many times and I don't get the correct code.

    Please copy the full text of the console window and paste it here so we can see where the command was, what command was executed and what the full text of the error message is.

    What is "Abbott_Assign4"
    If you don't understand my response, don't ignore it, ask a question.

  4. #24
    Clemson is offline Member
    Join Date
    Feb 2014
    Posts
    49
    Rep Power
    0

    Default Re: I have tried this many times and I don't get the correct code.

    I did this:
    class HelloObject
    {
    String greeting;

    HelloObject( String st )
    {
    greeting = st;
    }

    void speak()
    {
    System.out.println( greeting );
    }
    }

    class HelloTester
    {
    public static void main ( String[] args )
    {
    HelloObject hello1 = new HelloObject("Good Morning; everybody!");
    HelloObject hello2 = new HelloObject("Good Afternoon; everybody!");
    HelloObject hello3 = new HelloObject("Good Evening; everybody!");
    HelloObject hello4 = new HelloObject("Good Night; everybody!");
    }
    }

    For the first part. I think it's correct?

  5. #25
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default Re: I have tried this many times and I don't get the correct code.

    I think it's correct?
    Did it compile without errors?
    What happened when you executed it?

    It's time to start wrapping your code in code tags:

    When posting code be sure to wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  6. #26
    Clemson is offline Member
    Join Date
    Feb 2014
    Posts
    49
    Rep Power
    0

    Default Re: I have tried this many times and I don't get the correct code.

    I compiled it and don't have any errors. I still am confused on how to execute it.

  7. #27
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,431
    Blog Entries
    7
    Rep Power
    20

    Default Re: I have tried this many times and I don't get the correct code.

    Where do you call the speak() method on your objects? They won't speak if you don't tell them to do so ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #28
    Clemson is offline Member
    Join Date
    Feb 2014
    Posts
    49
    Rep Power
    0

    Default Re: I have tried this many times and I don't get the correct code.

    I haven't out the speak() method in yet.

  9. #29
    Clemson is offline Member
    Join Date
    Feb 2014
    Posts
    49
    Rep Power
    0

    Default Re: I have tried this many times and I don't get the correct code.

    The problem is, with the format they gave us do I put my code underneath it, or do I put it within the code?

  10. #30
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default Re: I have tried this many times and I don't get the correct code.

    how to execute it.
    Use the java command with the name of the class (without file extension):
    java TheClassNameHere
    If you don't understand my response, don't ignore it, ask a question.

  11. #31
    Clemson is offline Member
    Join Date
    Feb 2014
    Posts
    49
    Rep Power
    0

    Default Re: I have tried this many times and I don't get the correct code.

    class HelloObject
    {
    String greeting;

    HelloObject( String st )
    {
    HelloObject hello1 = new HelloObject("Good Morning; everybody!");
    HelloObject hello2 = new HelloObject("Good Afternoon; everybody!");
    HelloObject hello3 = new HelloObject("Good Evening; everybody!");
    HelloObject hello4 = new HelloObject("Good Night; everybody!");
    greeting = st;
    }

    public static void speak()
    {
    HelloObject hello1;speak();
    HelloObject hello2;speak();
    HelloObject hello3;speak();
    HelloObject hello4;speak();

    System.out.println( greeting );
    }
    }

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

    }
    }


    Here is my code so far, do I have things in the wrong place?

  12. #32
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default Re: I have tried this many times and I don't get the correct code.

    When posting code be sure to wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    My suggestion: Make ONE change at a time to the working code from post#1. The last post has too many changes.
    Do it this way:
    make change
    compile
    execute
    repeat when there are no errors
    If you don't understand my response, don't ignore it, ask a question.

  13. #33
    Clemson is offline Member
    Join Date
    Feb 2014
    Posts
    49
    Rep Power
    0

    Default Re: I have tried this many times and I don't get the correct code.

    I don't understand what you mean by that.

  14. #34
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default Re: I have tried this many times and I don't get the correct code.

    I don't understand what you mean by that.
    I'm not sure what you don't understand. Which of these steps are the problem:
    1) copy the code from post#1 into a file named: HelloTester.java
    2) compile that file using the javac command
    3) execute the output of the compiler with the java command
    4) copy the full contents of the console window and paste it here
    If you don't understand my response, don't ignore it, ask a question.

  15. #35
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,431
    Blog Entries
    7
    Rep Power
    20

    Default Re: I have tried this many times and I don't get the correct code.

    Quote Originally Posted by Clemson View Post
    I haven't out the speak() method in yet.
    You have created those four objects in your main( ... ) method; for simplicity make them all four speak in your main( ... ) method; don't fiddle diddle with what you have now, just add those four speak() calls to your main method ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  16. #36
    Clemson is offline Member
    Join Date
    Feb 2014
    Posts
    49
    Rep Power
    0

    Default Re: I have tried this many times and I don't get the correct code.

    public static void main ( String[] args )
    {
    HelloObject hello1 = new HelloObject("1 greeting");
    HelloObject hello2 = new HelloObject("2 greeting");
    HelloObject hello3 = new HelloObject("3 greeting");
    HelloObject hello4 = new HelloObject("4 greeting");

    speak();
    speak();
    speak();
    speak();
    }
    }

    Is that how I add Speak?

  17. #37
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default Re: I have tried this many times and I don't get the correct code.

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    Put
    [code]
    in front of the code
    and put
    [/code]
    after the code
    If you don't understand my response, don't ignore it, ask a question.

  18. #38
    Clemson is offline Member
    Join Date
    Feb 2014
    Posts
    49
    Rep Power
    0

    Default Re: I have tried this many times and I don't get the correct code.

    public static void main ( String[] args )
    {
    [ HelloObject hello1 = new HelloObject("1 greeting");]
    [ HelloObject hello2 = new HelloObject("2 greeting");]
    [HelloObject hello3 = new HelloObject("3 greeting");]
    [ HelloObject hello4 = new HelloObject("4 greeting");]

    [ speak();]
    [speak();]
    [speak();]
    [speak();]
    }
    }

    Is that how I add Speak?

  19. #39
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default Re: I have tried this many times and I don't get the correct code.

    Put one of these
    [code]
    in front of the code

    THE CODE GOES HERE


    and put one of these
    [/code]
    after the code
    If you don't understand my response, don't ignore it, ask a question.

  20. #40
    Clemson is offline Member
    Join Date
    Feb 2014
    Posts
    49
    Rep Power
    0

    Default Re: I have tried this many times and I don't get the correct code.

    Java Code:
     class HelloObject
    {
    String greeting;
    
    HelloObject( String st )
    {
    greeting = st;
    
    }
    
    void speak()
    {
    System.out.println( greeting );
    }
    }
    
    class Assign4_Abbott
    {
    public static void main ( String[] args )
    {
    	HelloObject hello1 = new HelloObject("1 greeting");
    	HelloObject hello2 = new HelloObject("2 greeting");
        HelloObject hello3 = new HelloObject("3 greeting");
        HelloObject hello4 = new HelloObject("4 greeting");
    
        speak();
    	speak();
    	speak();
        speak();
    }
    }

Page 2 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. hello need help to correct my code
    By yanalvine in forum New To Java
    Replies: 2
    Last Post: 10-18-2013, 11:20 AM
  2. Very new to Java. Please help me correct my code.
    By jpab29 in forum New To Java
    Replies: 5
    Last Post: 06-29-2012, 04:05 PM
  3. Please correct this JSP code
    By rajesh4851 in forum New To Java
    Replies: 5
    Last Post: 06-13-2011, 12:12 PM
  4. Replies: 10
    Last Post: 06-06-2010, 10:12 AM

Posting Permissions

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