Hi Guys!I need help starting off a program I am trying to write for class. The class should contain a private instance variable to represent temperature in Degrees Celsius and it should have the following methods: Temperature(float); and Temperature()-which sets the temperature to 0.0 degrees celsius.There are more methods but I want to try them myself! I just am confused as to how to start this program because I dont know what should go in the Temperature (float) method!v
Beginner - Temperature method
Page 1 of 13 Replies - 991 Views - Last Post: 27 February 2014 - 08:03 AM
Replies To: Beginner - Temperature method
#2
Re: Beginner - Temperature method
Posted 27 February 2014 - 07:32 AM
Post the code that you have so far.
I've changed your topic title. "Beginner Java question" is not a title, it tells us nothing about your question.
I've changed your topic title. "Beginner Java question" is not a title, it tells us nothing about your question.
#3
Re: Beginner - Temperature method
Posted 27 February 2014 - 07:48 AM
so far I have
but im pretty sure this isnt right which is why I am asking for help, because I am not sure how to start this!
public class Temperature{
private float celsius;
private Temperature(float){
}
private Temperature(){
celsius=0.0f;
}
}
but im pretty sure this isnt right which is why I am asking for help, because I am not sure how to start this!
#4
Re: Beginner - Temperature method
Posted 27 February 2014 - 08:03 AM
Variables have type and name. Method parameters are variables. So you might want to name the float.
Also, why are your constructors private?
private Temperature(float celsius){
//assign the method parameter to the instance variable
this.celsius = celsius;
}
Also, why are your constructors private?
Page 1 of 1

New Topic/Question
Reply


MultiQuote





|