Page 3 of 4 FirstFirst 1234 LastLast
Results 41 to 60 of 77
Like Tree1Likes

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

  1. #41
    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.

    Now I am confused as to where I put the Speak at.

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

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

    Congratulations on the formatting.

    Now look at the code in post#1 to see how the speak() method was called.
    If you don't understand my response, don't ignore it, ask a question.

  3. #43
    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("Good Morning; everyone!");
    	HelloObject hello2 = new HelloObject("Good Afternoon; everyone!");
        HelloObject hello3 = new HelloObject("Good Evening; everyone!");
        HelloObject hello4 = new HelloObject("Good Night; everyone!");
    
        anObject.speak();
    	anObject.speak();
    	anObject.speak();
        anObject.speak();
    }
    }
    Is that what it is looking for?

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

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

    What happens when that code is compiled and executed?


    It would be easier if you'd add one line at a time to a working program instead of replacing 2 lines of code that work with 8 lines that need to be debugged and fixed.
    If you don't understand my response, don't ignore it, ask a question.

  5. #45
    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.

    It would be easier if you showed me how to execute it I execute it and I get a javac error, I tried and edited my Path and it still doesn't work.

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

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

    Did the code from post#1 compile and execute without any errors?

    If so, start with that code and add ONE line to define a new HelloObject object
    and add a second line to use the reference to that object to call its speak() method.

    Compile and execute that new version of the class.
    If there are any errors, copy the full contents of console window and paste it here.
    If you don't understand my response, don't ignore it, ask a question.

  7. #47
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,538
    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
    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();
    }
    }
    Smalltalk does a better job than Java does: if you call a non-static method, you call it 'on' an object, i.e. when you do 'object.method()' you're telling 'object' to do 'method()'. In your example you're trying to make what to speak()? hello1, ... hello4 know how to speak(), but you're not asking them to speak(), your code is just yelling around to 'speak()'. What is supposed to speak()?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #48
    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.

    Quote Originally Posted by JosAH View Post
    Smalltalk does a better job than Java does: if you call a non-static method, you call it 'on' an object, i.e. when you do 'object.method()' you're telling 'object' to do 'method()'. In your example you're trying to make what to speak()? hello1, ... hello4 know how to speak(), but you're not asking them to speak(), your code is just yelling around to 'speak()'. What is supposed to speak()?

    kind regards,


    I'm asking it to Speak the 4 greetings that are used in the top.
    Jos

    I'm asking it to Speak the 4 greetings that are used in the top.

  9. #49
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

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

    does ti compile?

  10. #50
    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.

    It compiles yes.

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

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

    It compiles yes.
    What happens when it executes? Can you copy the console window?
    If you don't understand my response, don't ignore it, ask a question.

  12. #52
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

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

    It is little strange if it compiles because you don't have speak() method inside Assign4_Abbott class?!

  13. #53
    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 hit Compile Java App on NotePad and I don't get any errors.

  14. #54
    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("Good Morning; everyone!");
    	HelloObject hello2 = new HelloObject("Good Afternoon; everyone!");
        HelloObject hello3 = new HelloObject("Good Evening; everyone!");
        HelloObject hello4 = new HelloObject("Good Night; everyone!");
    
        hello1.speak();
    	hello2.speak();
    	hello3.speak();
        hello4.speak();
    }
    }

    Would this make sense?

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

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

    Does it compile and execute without any errors?
    If you don't understand my response, don't ignore it, ask a question.

  16. #56
    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've tried executing it via javac and I get the same error over and over. If someone could talk Via Voice over IP or something it would help.

  17. #57
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

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

    javac? you mean to compile it? what is the error?

  18. #58
    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.

    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.

    C:\Users\Bradley Abbott>cd C:\java

    C:\Java>dir
    Volume in drive C is OS
    Volume Serial Number is F055-8C4A

    Directory of C:\Java

    02/23/2014 01:21 PM <DIR> .
    02/23/2014 01:21 PM <DIR> ..
    02/23/2014 02:08 PM 615 Assign4_abbott.java
    02/23/2014 01:24 PM 454 HelloObject.class
    2 File(s) 1,069 bytes
    2 Dir(s) 567,071,186,944 bytes free

    C:\Java>javac Assign4_abbott.java
    'javac' is not recognized as an internal or external command,
    operable program or batch file.

    C:\Java>

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

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

    Find the location of the javac.exe file and copy the full path to the file.
    Use the full path when compiling. For example:
    D:\Java\jdk1.7.0_45\bin\javac.exe -cp . -Xlint TestCode16.java


    How did you get the HelloObject.class? That would require a java compiler execution to create that file.
    If you don't understand my response, don't ignore it, ask a question.

  20. #60
    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.

    How do I get the location?

Page 3 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
  •