Results 1 to 3 of 3
Thread: what am I doing wrong?
- 11-02-2012, 04:59 AM #1
Member
- Join Date
- Oct 2012
- Posts
- 17
- Rep Power
- 0
what am I doing wrong?
heres what I have so far. When I try to do (take note for my returns I just put a temp random return to come back to later to set.)
it Errors but I just did a program with the same setup and it worked fine.Java Code:public class Temperature0000 { public static void main(String[] args) { Temperature t2; t2 = new Temperature(); }
Java Code:public class Temperature0000 { public static void main(String[] args) { Temperature t2; t2 = new Temperature(); System.out.println ("Welcome to the Temperature Converter"); System.out.println ("please enter a degree"); t1.setNewDegrees(); } }
Java Code:import java.util.*; public class Temperature { Scanner keyboard = new Scanner(System.in); private double degrees; private char units; private boolean C; private boolean F; public Temperature(double NewDegrees, char newUnits) { set(NewDegrees, newUnits); } public Temperature(double newDegrees) { set(newDegrees); } public Temperature(char newUnits) { set (newUnits); } // set methods public void set(double newDegrees, char newUnits) { newDegrees = 0; newUnits = 0; } public void set(double newDegrees) { newDegrees = 0; } public void set(char newUnits) { newUnits = 0; } //public get accessors public double getC() { return 5; } public double getF() { return 5; } //comoparison methods public boolean equals() { if( C == F) System.out.println("hello"); return C; } public boolean isGreaterThan() { if(C && F) System.out.println("C.isgreaterthen F"); return true; } public double isLessThan() { if( C && F) { System.out.println("C is less then F"); } System.out.println("C is not less then F"); return 3.4 + 2.5; } }Last edited by Tolls; 11-02-2012 at 10:23 AM. Reason: Fixed code tags
- 11-02-2012, 05:05 AM #2
Member
- Join Date
- Mar 2011
- Posts
- 44
- Rep Power
- 0
Re: what am I doing wrong?
ok, for a start, have another look at your class name.
Its Temperature0000
yet you are using a constructor of Temperature().
Cheers
- 11-02-2012, 05:08 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 44
- Rep Power
- 0
Re: what am I doing wrong?
With a quick look, you create a Temperature variable t2,
yet you call t1.setNewDegrees();
when you have no t1 variable created
I would also recommend you move the Scanner out of the temperature class. Its probably more appropriate in your class with the main method.
Try to consider your Temperature class as an object, so it may have 'things' that all objects have. For example a person, has arms, legs etc.
You can consider these items in an object as defining the 'state' of an object.
your Temperature object may have :
temperature in degrees,
units - Fahrenheight or Celsius,
maybe a maximum temperature and minimum temperature
etc..
other than state, objects also have behaviour.
for example, you can :
increase or decrease the temperature,
convert the temperature to other units
etc..
So try to think of things as objects having state (things that identify it) and behaviour (actions that the object can perform).
If you think about it like this, I find it much easier to create more useable classes.
I know the above is slightly off topic, but I believe it's useful to understand object oriented practices in order to create better applications.
See how it goes after you look at what I put in the top of my post and if there are still errors, post more details, perhaps include the error you are getting.Last edited by sibernewf; 11-02-2012 at 05:20 AM.
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 DuncanHollows in forum New To JavaReplies: 2Last Post: 04-08-2012, 05:33 PM -
What did I do wrong?
By Astralogic in forum New To JavaReplies: 6Last Post: 04-05-2012, 12:16 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 -
what wrong
By pro85 in forum New To JavaReplies: 3Last Post: 02-09-2009, 01:07 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks