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

Thread: Will someone please tell me what I'm doing wrong with this?

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

    Default Re: Will someone please tell me what I'm doing wrong with this?

    Quote Originally Posted by psx2514 View Post
    Should it be
    Java Code:
     public boolean equals(t1)
    ?
    Your original equals() method signature was correct, before you edited your original post.
    It was just the code inside the method that was wrong.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  2. #22
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    384
    Rep Power
    4

    Default Re: Will someone please tell me what I'm doing wrong with this?

    Actually, let me throw you a method I tend to use in my classes:
    Java Code:
    public void debug(String s)
    {
      System.out.println(s);
    }
    It's a simple enough method; it's mostly as a way to show how method declarations should look. You need to specify the type of variable that is sent to the method; in this case, it will accept a String.

  3. #23
    psx2514 is offline Member
    Join Date
    Oct 2012
    Posts
    50
    Rep Power
    0

    Default Re: Will someone please tell me what I'm doing wrong with this?

    Quote Originally Posted by Toll View Post
    Have a look at the Java Method tutorial.
    nevermind. you're not really helping me. Like I said. I tried everything I could, and came here as a last resort. That would be looking at resources outside of this forum. So, directing me towards resources outside of this forum is a moot point since I already did so. So, please, help me directly with my problem, or don't help me at all.

  4. #24
    psx2514 is offline Member
    Join Date
    Oct 2012
    Posts
    50
    Rep Power
    0

    Default Re: Will someone please tell me what I'm doing wrong with this?

    Also, I'm not supposed to edit the TemperatureTest class. Only the Temperature class. Please read my OP if you haven't done so.

  5. #25
    psx2514 is offline Member
    Join Date
    Oct 2012
    Posts
    50
    Rep Power
    0

    Default Re: Will someone please tell me what I'm doing wrong with this?

    Will someone just please tell me how to fix this? I don't have time to figure this out anymore. I give up. I've spent too much time on this.

  6. #26
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    384
    Rep Power
    4

    Default Re: Will someone please tell me what I'm doing wrong with this?

    As Tolls said, your original equals was correct in its definition, it just had the wrong code in it. Also, you should be able to make use of some of your methods in the Temperature class to avoid having to convert the temperatures in your equals method.

  7. #27
    psx2514 is offline Member
    Join Date
    Oct 2012
    Posts
    50
    Rep Power
    0

    Default Re: Will someone please tell me what I'm doing wrong with this?

    Quote Originally Posted by Toll View Post
    As Tolls said, your original equals was correct in its definition, it just had the wrong code in it. Also, you should be able to make use of some of your methods in the Temperature class to avoid having to convert the temperatures in your equals method.
    Please be more specific. WHAT PART of the code is wrong? Which lines?

  8. #28
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    384
    Rep Power
    4

    Default Re: Will someone please tell me what I'm doing wrong with this?

    Let's go over it line by line. Please answer each question.
    Java Code:
      public boolean equals() {
        if (type == 'F') { // I assume you're planning to add another case for Celsius once this one works?
          double TempC = (degrees - 32) * 5/9; // Okay, so you have the degree in Celsius in TempC.
          double result = Math.round(TempC*10)/10.0; // Why do you have the division in there?
          return (this.degrees == result); // In which cases would the degrees and result actually be the same?
        }
        else {
          return false; // This means that anytime this Temperature object is in Celsius, it returns false. I'm assuming this will change once Fahrenheit works.
        }
      }
    Also... Where does it compare two different Temperature objects in there?

  9. #29
    psx2514 is offline Member
    Join Date
    Oct 2012
    Posts
    50
    Rep Power
    0

    Default Re: Will someone please tell me what I'm doing wrong with this?

    Quote Originally Posted by Toll View Post
    Let's go over it line by line. Please answer each question.
    Java Code:
      public boolean equals() {
        if (type == 'F') { // I assume you're planning to add another case for Celsius once this one works?
          double TempC = (degrees - 32) * 5/9; // Okay, so you have the degree in Celsius in TempC.
          double result = Math.round(TempC*10)/10.0; // Why do you have the division in there?
          return (this.degrees == result); // In which cases would the degrees and result actually be the same?
        }
        else {
          return false; // This means that anytime this Temperature object is in Celsius, it returns false. I'm assuming this will change once Fahrenheit works.
        }
      }
    Also... Where does it compare two different Temperature objects in there?
    I need to prove that 212 degrees F is equal to 100 degrees C.

    Look, this isn't going anywhere. Just tell me the answer. I don't care anymore. I'll learn from this for the next time I need to do this. This is just making me more frustrated. So, I don't care if I can't figure it out myself. Please just give me the solution, and I'll figure out what I did wrong based on that. This is due very soon, and I won't be able to figure it out by then. Thanks.
    Last edited by psx2514; 10-30-2012 at 02:17 PM.

  10. #30
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    384
    Rep Power
    4

    Default Re: Will someone please tell me what I'm doing wrong with this?

    That doesn't answer a single question I asked though...

  11. #31
    psx2514 is offline Member
    Join Date
    Oct 2012
    Posts
    50
    Rep Power
    0

    Default Re: Will someone please tell me what I'm doing wrong with this?

    Quote Originally Posted by Toll View Post
    That doesn't answer a single question I asked though...
    I don't have time to play 20 questions. This is due very shortly.

    I need one comparison method named equals():

    example: returns true if temperature1 is equivalent to temperature2


    Note:

    This means 32F should be equal to 0C.You should convert all temperatures to either Celsius or Fahrenheit (using the get methods) so you are comparing similar values. Method returns a boolean.

  12. #32
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    384
    Rep Power
    4

    Default Re: Will someone please tell me what I'm doing wrong with this?

    I'm not trying to play 20 questions with you. I'm trying to guide you towards solving this yourself. The one thing I won't do is to just hand you the code you need though; you'll need to code it yourself.

    The note did say you should use the get methods though, yet I don't see those actually being used anywhere in the code. Try using those in your equals method.

  13. #33
    psx2514 is offline Member
    Join Date
    Oct 2012
    Posts
    50
    Rep Power
    0

    Default Re: Will someone please tell me what I'm doing wrong with this?

    Quote Originally Posted by Toll View Post
    I'm not trying to play 20 questions with you. I'm trying to guide you towards solving this yourself. The one thing I won't do is to just hand you the code you need though; you'll need to code it yourself.

    The note did say you should use the get methods though, yet I don't see those actually being used anywhere in the code. Try using those in your equals method.
    See lines 57-64 and 67-76

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

    Default Re: Will someone please tell me what I'm doing wrong with this?

    Quote Originally Posted by psx2514 View Post
    This means 32F should be equal to 0C.You should convert all temperatures to either Celsius or Fahrenheit (using the get methods) so you are comparing similar values. Method returns a boolean.
    There's your answer right there.
    Pick one.
    Either compare the F value (using getF for both Temperature objects) or compare the C value (using the getC method for both).
    No need to even check the 'type' variable.
    It's a straight 'return x == y'.

    Of course you need to revert your signature to the original.

    And we do not provide fully coded answers here.

    So try and write the above.
    Here's the skeleton again:
    Java Code:
    public boolean equals(Temperature t1) {
     // your code goes in here
    }
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  15. #35
    psx2514 is offline Member
    Join Date
    Oct 2012
    Posts
    50
    Rep Power
    0

    Default Re: Will someone please tell me what I'm doing wrong with this?

    Okay. I got it! I finished (except for test case 2, which is extra credit). Is there anything I can do to clean my code up a little, or is it fine the way it is.

    Also, any tips on how to do the extra credit, which is to "Implement a readInput() method to prompt user for degrees and type and then reads the values. The Scanner class does not have a specific method for reading chars. No input checking is done for units. It is assumed that user inputs only a 'C' or 'F' for units Lower case 'c' and 'f' are acceptable and do not need to be changed to upper case

    Hint:

    Read the input as a string and pick out first element from the string (which is the character you want)."

  16. #36
    SJF
    SJF is offline Senior Member
    Join Date
    Oct 2012
    Posts
    108
    Rep Power
    0

    Default Re: Will someone please tell me what I'm doing wrong with this?

    Toll is trying to help you figure out your problem. I fail to see how that is wasting anyone's time but his/(her?) own.

    Your equals is broken. equals should always be in the form Object.equals(Object obj) (Or in this case Temperature.equals(Temperature temp) ) Object (Java Platform SE 7 )

    AND t1.equals(t1) must always be true //REFLEXIVE
    AND if t1.equals(t2) then t2.equals(t1) must also be true. //SYMMETRIC
    AND if t1.equals(t3) and t3.equals(t2) then t1.equals(t2) must be true //TRANSITIVE

    If you don't have a Temperature.equals(Temperature t) defined, the Java Compiler will use Object.equals(Object obj) for the comparison. This will end poorly as they are not the same Object.

  17. #37
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    384
    Rep Power
    4

    Default Re: Will someone please tell me what I'm doing wrong with this?

    A bit late on that reply, I think :P And I'm horribly rusty with Scanner, so all I can give there is Scanner (Java Platform SE 6)

  18. #38
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Will someone please tell me what I'm doing wrong with this?

    Anyone else think OP is acting like a butthole?
    DarrylBurke likes this.

  19. #39
    DrummondAW is offline Member
    Join Date
    Oct 2012
    Posts
    13
    Rep Power
    0

    Default Re: Will someone please tell me what I'm doing wrong with this?

    Quote Originally Posted by Junky View Post
    Anyone else think OP is acting like a butthole?
    First time I've ever seen someone declare that someone trying to help them was wasting their time.
    Fubarable and DarrylBurke like this.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 4
    Last Post: 06-11-2013, 01:37 AM
  2. I can't find anything wrong with this but somehow it's wrong.
    By Biscuit Tickler in forum New To Java
    Replies: 2
    Last Post: 09-12-2012, 09:28 PM
  3. What am I doing wrong?!
    By WidmarkRob in forum New To Java
    Replies: 4
    Last Post: 04-20-2012, 05:19 AM
  4. What Am I doing Wrong?
    By siren1111 in forum New To Java
    Replies: 3
    Last Post: 12-20-2011, 02:01 AM
  5. what am i doing wrong here?
    By GPB in forum New To Java
    Replies: 3
    Last Post: 03-21-2010, 04:04 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
  •