Page 2 of 2 FirstFirst 12
Results 21 to 32 of 32
Like Tree3Likes

Thread: unsure on a method

  1. #21
    jwood is offline Senior Member
    Join Date
    Jun 2013
    Posts
    136
    Rep Power
    0

    Default Re: unsure on a method

    OK, one issue compiling my tester:

    HotelTest.java:28: error: method occupancyPercentage in class Hotel cannot be applied to given types;
    System.out.println("Occupancy Percentage: " + newHotel.occupancyPercentage()); arrow points to the . before occupanyPercentage

    Here is the method in the Hotel class:

    Java Code:
    public double occupancyPercentage(double percentage)
            {
                percentage = occupiedCnt/theRooms.length;
                return percentage;
            }
    do I need to cast double like this:

    percentage = (double) occupiedCnt/(double) theRooms.length;?
    Last edited by jwood; 07-30-2013 at 07:43 PM.

  2. #22
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: unsure on a method

    Will you please go through the tutorial I linked at #5 and the one I referred to at #14?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #23
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,377
    Rep Power
    5

    Default Re: unsure on a method

    It appears you edited your thread and removed replied to content. Now Darryl's reply does not make sense.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  4. #24
    jwood is offline Senior Member
    Join Date
    Jun 2013
    Posts
    136
    Rep Power
    0

    Default Re: unsure on a method

    Quote Originally Posted by jim829 View Post
    It appears you edited your thread and removed replied to content. Now Darryl's reply does not make sense.

    Regards,
    Jim
    Actually it does. In the tutorial he referenced on #14 talks about printf.....something I have not learned yet, but which worked and allowed my tester to compile. Now getting it to run.....BLEH.....one error, but a big one....

  5. #25
    jwood is offline Senior Member
    Join Date
    Jun 2013
    Posts
    136
    Rep Power
    0

    Default Re: unsure on a method

    Quote Originally Posted by jwood View Post
    Actually it does. In the tutorial he referenced on #14 talks about printf.....something I have not learned yet, but which worked and allowed my tester to compile. Now getting it to run.....BLEH.....one error, but a big one....

    I take it back....though it compiles, it does not work in the tester.....this "should" be one of the easier methods in the class....

    Java Code:
    public double occupancyPercentage(double percentage)
            {
                percentage = occupiedCnt/numOfRooms;
                return percentage;
            }
    Oh it compiles fine, but when I try to call it in the tester to print I get
    method occupancyPercentage in class Hotel cannot be applied to given types;

    System.out.println("Occupancy Percentage: " + newHotel.occupancyPercentage());
    ^

    when I tried the printf there was no error, but all it did was give me 0.0

  6. #26
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,662
    Rep Power
    5

    Default Re: unsure on a method

    Note how the method has a parameter and you're not passing one... So if it compiles, what you posted is NOT the code you're running.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #27
    jwood is offline Senior Member
    Join Date
    Jun 2013
    Posts
    136
    Rep Power
    0

    Default Re: unsure on a method

    Quote Originally Posted by gimbal2 View Post
    Note how the method has a parameter and you're not passing one... So if it compiles, what you posted is NOT the code you're running.
    Ohhh.....I think I see what you are saying......

    and it was compiling in the hotel class
    unsure on a method-capture.jpg


    just not when I tried to print it in the tester class...now it prints but still gives me the wrong answer of 0.0

  8. #28
    jwood is offline Senior Member
    Join Date
    Jun 2013
    Posts
    136
    Rep Power
    0

    Default Re: unsure on a method

    Quote Originally Posted by jwood View Post
    Ohhh.....I think I see what you are saying......




    just not when I tried to print it in the tester class...now it prints but still gives me the wrong answer of 0.0
    Figured it out!! Had to cast to doubles.....whew....one more thing to fix.....

  9. #29
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,662
    Rep Power
    5

    Default Re: unsure on a method

    What's with this posting of screenshots of an IDE that people keep doing? Post the code, not a picture of the code!
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  10. #30
    jwood is offline Senior Member
    Join Date
    Jun 2013
    Posts
    136
    Rep Power
    0

    Default Re: unsure on a method

    I was not posting that to show the code, but to show it did indeed compile with that code....sorry.

  11. #31
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,662
    Rep Power
    5

    Default Re: unsure on a method

    I was ranting in general, you're not the only one that does it. But it makes no sense, it is a lot more effort (for the people doing it) and a lot less useful (for the receiving end) :s
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  12. #32
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: unsure on a method

    Quote Originally Posted by jwood View Post
    I was not posting that to show the code, but to show it did indeed compile with that code....sorry.
    It also reveals that you haven't complied with my advice at #20. Did you not understand it?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 7
    Last Post: 04-11-2013, 05:31 AM
  2. Unsure of whether to use key bindings
    By kjkrum in forum AWT / Swing
    Replies: 1
    Last Post: 04-15-2012, 07:33 AM
  3. Replies: 3
    Last Post: 10-24-2011, 06:03 PM
  4. Replies: 1
    Last Post: 04-01-2010, 05:14 PM
  5. [SOLVED] Key listener, unsure abt the tab key
    By dbashby in forum New To Java
    Replies: 7
    Last Post: 04-16-2009, 05:49 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
  •