Weather forcast class

Reply

Join Date: Nov 2008
Posts: 5
Reputation: cbickle is an unknown quantity at this point 
Solved Threads: 0
cbickle cbickle is offline Offline
Newbie Poster

Weather forcast class

 
0
  #1
Nov 20th, 2008
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.
  1. [code = java]
  2. //Chris Bickle Homework Assignment #6
  3. //Write a weather forecast class
  4.  
  5. public class WeatherForcast
  6. {
  7. //Declare instance variables and set them to initial values
  8. private double temp;
  9. private String skyCondition;
  10.  
  11. //Overloaded constructor allows client to set values
  12. public WeatherForcast()
  13. {
  14. skyCondition = "sunny";
  15. temp = 70.0;
  16. }
  17.  
  18. public WeatherForcast(double startTemp, String startSky)
  19. {
  20. temp = startTemp;
  21. setSky(startSky, temp);
  22. }
  23.  
  24. //Accessor Methods
  25. public double getTemp()
  26. {
  27. return temp;
  28. }
  29.  
  30. public String getSky()
  31. {
  32. return skyCondition;
  33. }
  34.  
  35. //Mutator methods
  36. public void setTemp(double startTemp)
  37. {
  38. temp = startTemp;
  39. }
  40.  
  41. public void setSky(String startSky, double temp)
  42. {
  43. if((temp <= 32.0 && startSky != "snowy") || (temp >= 100.0 && startSky != "sunny"))
  44. {
  45. System.err.println("Conditions are not valid");
  46. }
  47. else
  48. skyCondition = startSky;
  49. }
  50.  
  51. public double convert()
  52. {
  53. return ((temp - 32) * (5/9));
  54. }
  55.  
  56. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 249
Reputation: Antenka has a spectacular aura about Antenka has a spectacular aura about Antenka has a spectacular aura about 
Solved Threads: 65
Antenka's Avatar
Antenka Antenka is offline Offline
Posting Whiz in Training

Re: Weather forcast class

 
0
  #2
Nov 20th, 2008
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.
Last edited by Antenka; Nov 20th, 2008 at 4:40 pm.
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC