Results 1 to 12 of 12
  1. #1
    TylerJoeWatts is offline Member
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0

    Angry Object Oriented Programming

    Hi everyone,
    I'm fairly new to Java and have been finding it quite difficult to grasp.
    We got given this to program in one of my workshops.
    I can't figure out what i'm doing wrong. Any help would be greatly appreciated.



    Ball.Java
    Java Code:
    public class Ball
    {
      public double diameter;
      public String colour;
      public double height;
    
      public void bounce()
      {
        System.out.println("Boing");
      }
       
      public void roll()
      {
        System.out.println(this.colour+" blur! ");
      }
    }
    Main.Java
    Java Code:
    public class Main
    {
      public static void main(String[] args)
      {
        Ball tennisBall = new Ball();
        tennisBall.diameter = 6.5;
        tennisBall.colour = "green";
    
        Ball cricketBall = new Ball();
        cricketBall.diameter = 9;
        cricketBall.colour = "red";
       cricketBall.height = cricketBall.diameter * 2;
    
    
        System.out.println("we bounced " + cricketBall.height + "cm high");
      }
    }
    The objective is to get it to print "we bounced (the height of the bounce) cm high".
    The height is the diameter of the ball x2.
    The program is running fine. But when I try to test for a medal (reward system my university uses), it displays an error saying this is not the desired output. But this program does calculate the height of the bounce by multiplying the diameter by 2. Have I done anything wrong?

    Thanks
    Last edited by TylerJoeWatts; 11-26-2013 at 12:35 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: Object Oriented Programming

    When posting code please use code tags.
    I've done it for you this time.

    What is the problem you are having?
    Errors?
    Exceptions?

    Please post the full text and highlight the part(s) of your code these problems are coming from.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    TylerJoeWatts is offline Member
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0

    Default Re: Object Oriented Programming

    I've edited the post. Thanks, and sorry. I'm new to this site. Thanks again

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Object Oriented Programming

    Please use code formating: Guide For New Members
    I'm sure the compiler/VM reported some errors/Exceptions. Post the exact messages you got here.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: Object Oriented Programming

    Quote Originally Posted by TylerJoeWatts View Post
    The program is running fine. But when I try to test for a medal (reward system my university uses), it displays an error saying this is not the desired output. But this program does calculate the height of the bounce by multiplying the diameter by 2. Have I done anything wrong?

    Thanks
    OK, so presumably it isn't doing what's expected of it.
    Is there a description of what the code is supposed to do?
    Is there anymore output from the test harness?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    TylerJoeWatts is offline Member
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0

    Default Re: Object Oriented Programming

    Object Oriented Programming-screen-shot-2013-11-26-12.02.17.png

    Object Oriented Programming-screen-shot-2013-11-26-12.02.35.png

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: Object Oriented Programming

    The sentence starting with "Specifically, we said..." is what you're missing.
    This is all about writing it in the bounce() method...which you aren't doing.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    TylerJoeWatts is offline Member
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0

    Default Re: Object Oriented Programming

    so how would I do that?

  9. #9
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,703
    Rep Power
    5

    Default Re: Object Oriented Programming

    Quote Originally Posted by TylerJoeWatts View Post
    so how would I do that?
    Well the gist of it is that you have to properly read the instructions you've been given and do what it tells you to do, quite literally. The bounce() method needs to be the one that prints "we bounced X high", so that System.out statement that is now in your main() has to move to it at the very least.

    But before that you probably need to snuggle up with a good Java book and get some firmer understanding of the material you're trying to use here.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  10. #10
    maddy14 is offline Member
    Join Date
    May 2013
    Posts
    25
    Blog Entries
    1
    Rep Power
    0

    Default Re: Object Oriented Programming

    Try creating a function in the class Ball to calculated how much height did the ball reach.Pass paramters as diameter to the function.And if you want print in that function only how much height did the ball bounce.I could have given you the exact code but you wont learn much like that

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: Object Oriented Programming

    Quote Originally Posted by maddy14 View Post
    Try creating a function in the class Ball to calculated how much height did the ball reach.Pass paramters as diameter to the function.And if you want print in that function only how much height did the ball bounce.I could have given you the exact code but you wont learn much like that
    The requirements are pretty clear what they have to do, though.
    They have to change the bounce() method...and call it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  12. #12
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,703
    Rep Power
    5

    Default Re: Object Oriented Programming

    Quote Originally Posted by Tolls View Post
    The requirements are pretty clear what they have to do, though.
    They have to change the bounce() method...and call it.
    Which is immensely difficult if you don't first learn how to work with methods and object instances of course.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Object Oriented Programming Need Help!
    By JavaAddict in forum Java Applets
    Replies: 4
    Last Post: 11-14-2013, 04:02 PM
  2. new to object oriented programming and arrays
    By maximumammo in forum New To Java
    Replies: 11
    Last Post: 04-22-2012, 08:25 PM
  3. help for Object Oriented Programming RMI
    By clapton in forum New To Java
    Replies: 0
    Last Post: 03-20-2012, 06:42 PM
  4. Simple Problem with Object-Oriented Programming...
    By CuppaCoffee in forum New To Java
    Replies: 12
    Last Post: 01-04-2012, 10:12 PM
  5. Help in object oriented programming .
    By renu in forum New To Java
    Replies: 18
    Last Post: 10-26-2010, 07:57 PM

Tags for this Thread

Posting Permissions

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