Hey everyone im working on a class in java that does several things. it is supposed to take a sky condition either sunny snowy cloudy or rainy and a temp between -50 and 150 f. the default sky is sunny and temp is 70. it needs a method that converts farenheit to celcius and a method that checks if conditions are consistent (temp < 32 not snowing temp > 100 not sunny, and a client to test it. I wrote a version of the class and some of it works, but im having a few problems. First off i cant seem to get my setTemp and setSky methods to work, and secondly I cant get the convert method to work. any help would be greatly appreciated.

[code = java]
//Chris Bickle Homework Assignment #6
//Write a weather forecast class

public class WeatherForcast
{
	//Declare instance variables and set them to initial values
	private double temp;
	private String skyCondition;
	
	//Overloaded constructor allows client to set values
	public WeatherForcast()
	{
		skyCondition = "sunny";
		temp = 70.0;
	}
	
	public WeatherForcast(double startTemp, String startSky)
	{
		temp = startTemp;
		setSky(startSky, temp);
	}
	
	//Accessor Methods
	public double getTemp()
	{
		return temp;
	}
	
	public String getSky()
	{
		return skyCondition;
	}
	
	//Mutator methods
	public void setTemp(double startTemp)
	{
		temp = startTemp;
	}
	
	public void setSky(String startSky, double temp)
	{
		if((temp <= 32.0 && startSky != "snowy") || (temp >= 100.0 && startSky != "sunny"))
		{
			System.err.println("Conditions are not valid");
		}
		else
			skyCondition = startSky;
	}

	public double convert()
	{
		return ((temp - 32) * (5/9));
	}

}

First: startSky != "snowy" and startSky != "sunny". Use method equals to campare stings.
Maybe it will be better for you to use enum instead strings "sunny", "snowy" etc.
In setSky method, when you get an error, you don't set the skyCondition.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.