3 Replies - 991 Views - Last Post: 27 February 2014 - 08:03 AM Rate Topic: -----

#1 desinerd93   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 63
  • Joined: 13-September 13

Beginner - Temperature method

Posted 27 February 2014 - 07:21 AM

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

Is This A Good Question/Topic? 0
  • +

Replies To: Beginner - Temperature method

#2 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

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.
Was This Post Helpful? 0
  • +
  • -

#3 desinerd93   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 63
  • Joined: 13-September 13

Re: Beginner - Temperature method

Posted 27 February 2014 - 07:48 AM

so far I have
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!
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

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.
private Temperature(float celsius){
 
    //assign the method parameter to the instance variable
    this.celsius = celsius; 
}



Also, why are your constructors private?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1