| | |
Weather forcast class
![]() |
•
•
Join Date: Nov 2008
Posts: 5
Reputation:
Solved Threads:
0
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.
Java Syntax (Toggle Plain Text)
[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.
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
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
![]() |
Similar Threads
- Nasties on board? (Viruses, Spyware and other Nasties)
- Another hotoffers hijacking problem.. (Viruses, Spyware and other Nasties)
Other Threads in the Java Forum
- Previous Thread: Need urgent help in code!
- Next Thread: Text File to Java to Oracle
| Thread Tools | Search this Thread |
account android applet application apps array automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error eventlistener exception expand fractal free game givemetehcodez graphics gui guidancer homework html ide image inheritance integer integration intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield jtree julia linux loop method midlethttpconnection migrate mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source oracle plazmic print problem program property ria scanner server set sharepoint smart sms smsspam sourcelabs splash sql sqlite subclass support swing testautomation textfield threads tree trolltech unlimited utility windows





