Results 21 to 39 of 39
- 10-30-2012, 01:44 PM #21
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
- 10-30-2012, 01:46 PM #22
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:
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.Java Code:public void debug(String s) { System.out.println(s); }
- 10-30-2012, 01:47 PM #23
Member
- Join Date
- Oct 2012
- Posts
- 50
- Rep Power
- 0
Re: Will someone please tell me what I'm doing wrong with this?
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.
- 10-30-2012, 01:49 PM #24
Member
- Join Date
- Oct 2012
- Posts
- 50
- Rep Power
- 0
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.
- 10-30-2012, 01:55 PM #25
Member
- Join Date
- Oct 2012
- Posts
- 50
- Rep Power
- 0
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.
- 10-30-2012, 01:59 PM #26
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.
- 10-30-2012, 02:02 PM #27
Member
- Join Date
- Oct 2012
- Posts
- 50
- Rep Power
- 0
- 10-30-2012, 02:10 PM #28
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.
Also... Where does it compare two different Temperature objects in there?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. } }
- 10-30-2012, 02:12 PM #29
Member
- Join Date
- Oct 2012
- Posts
- 50
- Rep Power
- 0
Re: Will someone please tell me what I'm doing wrong with this?
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-2012, 02:14 PM #30
Re: Will someone please tell me what I'm doing wrong with this?
That doesn't answer a single question I asked though...
- 10-30-2012, 02:19 PM #31
Member
- Join Date
- Oct 2012
- Posts
- 50
- Rep Power
- 0
Re: Will someone please tell me what I'm doing wrong with this?
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.
- 10-30-2012, 02:23 PM #32
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.
- 10-30-2012, 02:25 PM #33
Member
- Join Date
- Oct 2012
- Posts
- 50
- Rep Power
- 0
- 10-30-2012, 02:27 PM #34
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Will someone please tell me what I'm doing wrong with this?
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.
- 10-30-2012, 11:17 PM #35
Member
- Join Date
- Oct 2012
- Posts
- 50
- Rep Power
- 0
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)."
- 10-31-2012, 12:40 AM #36
Senior Member
- Join Date
- Oct 2012
- Posts
- 108
- Rep Power
- 0
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.
- 10-31-2012, 12:43 AM #37
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)
- 10-31-2012, 12:55 AM #38
Re: Will someone please tell me what I'm doing wrong with this?
Anyone else think OP is acting like a butthole?
- 10-31-2012, 03:40 AM #39
Member
- Join Date
- Oct 2012
- Posts
- 13
- Rep Power
- 0
Similar Threads
-
I can't find anything wrong with this but somehow it's wrong.
By Biscuit Tickler in forum New To JavaReplies: 2Last Post: 09-12-2012, 09:28 PM -
What am I doing wrong?!
By WidmarkRob in forum New To JavaReplies: 4Last Post: 04-20-2012, 05:19 AM -
What Am I doing Wrong?
By siren1111 in forum New To JavaReplies: 3Last Post: 12-20-2011, 02:01 AM -
what am i doing wrong here?
By GPB in forum New To JavaReplies: 3Last Post: 03-21-2010, 04:04 PM -
Wrong output (well.. the one who's wrong is probably me ;) )
By shacht1 in forum New To JavaReplies: 2Last Post: 11-22-2009, 03:48 PM


3Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks