I have the following code which has no errors when i run it:
/* * 63. Write a class encapsulating the concept of the weather forecast, assuming * that it has the following attributes: the temperature and the sky conditions, * which could be sunny, snowy, cloudy, or rainy. Include a constructor, the * assessors and mutators,and methods toString and equals. Temperature, in * Fahrenheit, should be between - 50 and + 150; the default value is 70, if needed. * The default sky condition is sunny. Include a method that converts Fahrenheit * to Celsius. Celsius temperature = (Fahrenheit temperature - 32) * 5 / 9. * Also include a method that checks whether the weather attributes are consistent * (there are two cases where they are not consistent: when the temperature is * below 32 and it is not snowy, and when the temperature is above 100 and it * is not sunny).Write a client class to test all the methods in your class. */ package natashaepperson_chapter7_exercise_63; public class WeatherForecast { private double temperature; // in Fahrenheit private String sky; /** * initializes temperature to 70.0 and sky to "sunny" * calls mutator methods to validate these default values */ public WeatherForecast( ) { temperature = 70; sky = "sunny"; } /** * Overloaded constructor: * Allows client to set beginning values for temperature and sky * This constructor takes two parameters * Calls mutator methods to validate new values * @param newTemperature the temperature for the weather forecast * @param newSky the sky conditions for the weather forecast */ public WeatherForecast( double newTemperature, String newSky ) { temperature = newTemperature; sky = newSky; } /** getTemperature method * @return the temperature */ public double getTemperature( ) { return temperature; // add code here, insted of o.o we should return tempature } /** * Mutator method: * Allows client to set value of temperature * setTemperature sets the value of temperature * to 70.0 if newTemperature is less than -50 or greater than 150 * @param newTemperature the new number of temperature */ public void setTemperature( double newTemperature ) { // add code here // make sure falls in range of -50 to 100, need if else if(temperature >= 0) temperature = newTemperature; else { System.err.println( "Miles driven cannot be negative." ); System.err.println( "Value not changed."); } } /** getSky method * @return the sky conditions */ public String getSky( ) { return sky; // add code here, returns the string variable that represents your sky. You are going to some error checking and a syst // system.err make sure equal to sunny snowy cloudy rainy } /** * Mutator method:<BR> * Allows client to set value of sky * setSky sets the value of sky * to "sunny" if newSky is neither "sunny", "snowy", * "cloudy", nor "rainy" * This method is not case sensitive * @param newSky the new sky condition */ // @return the temperature and the sky conditions for the weather forecast @Override public String toString( ) { return( "temperature: " + temperature + "; sky: " + sky ); } /** * Compares two WeatherForecast objects for the same field values * @param wf another WeatherForecast object * @return a boolean, true if this object * has the same field values as the parameter wf */ public boolean equals( WeatherForecast wf ) { return ( Math.abs( temperature - wf.temperature ) < 0.0001 && sky.equals( wf.sky ) ); } /** * fahrenheitToCelsius method * Computes the degrees Celsius temperature * @return a double, the temperature value in degrees Celsius */ public double fahrenheitToCelsius( ) { temperature = temperature - 32; temperature = temperature * 5; temperature = temperature / 9; return temperature; // add code here complete method, do the coversioan return a double data type } /** * Checks if the temperature value and the sky conditions are compatible * @return a boolean, false if the temperature is below 32 and the sky is not snowy, * or if the temperature is greater than 100 and the sky is not sunny, true otherwise */ public boolean isConsistent( ) { return !( ( temperature < 32 && !sky.equals( "snowy" ) ) || ( temperature > 100 && !sky.equals( "sunny" ) ) ); } }
The problem seems to be in the call method class. I have this code:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package natashaepperson_chapter7_exercise_63; /** * * @author natasha */ /* WeatherForecast Client This class is complete, do not change. */ public class WeatherForecastClient { public static void main( String [] args ) { WeatherForecast wf1 = new WeatherForecast( 23,"sunny" ); WeatherForecast wf2 = new WeatherForecast( 200, "rainy" ); System.out.print( "The temperature of weather forecast #1 is " + wf1.getTemperature( ) ); System.out.println( "F or " + wf1.fahrenheitToCelsius( ) + "C"); System.out.println( "The sky condition of weather forecast #1 is " + wf1.getSky( ) ); System.out.println( "Weather forecast #2 is " + wf2.toString( ) + "\n" ); if ( wf1.isConsistent( ) ) System.out.println( "weather forecast " + wf1 + " is consistent" ); else System.out.println( "weather forecast " + wf1 + " is not consistent" ); if ( wf2.isConsistent( ) ) System.out.println( "weather forecast " + wf2 + " is consistent" ); else System.out.println( "weather forecast " + wf2 + " is not consistent" ); System.out.println( ); if ( wf1.equals( wf2 ) ) System.out.println( "Original weather forecasts #1 and #2 are identical" ); else System.out.println( "Original weather forecasts #1 and #2 are different" ); wf2.setTemperature( 23 ); wf2.setSky( "sunny" ); if ( wf1.equals( wf2 ) ) System.out.println( "Original weather forecast #1 and modified weather forecast #2 are identical" ); else System.out.println( "Original weather forecast #1 and modified weather forecast #2 are different" ); } }
This is the error i get when i run it
The temperature of weather forecast #1 is 23.0F or -5.0C
The sky condition of weather forecast #1 is sunny
Weather forecast #2 is temperature: 200.0; sky: rainy
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: natashaepperson_chapter7_exercise_63.WeatherForeca st.setSky
weather forecast temperature: -5.0; sky: sunny is not consistent
weather forecast temperature: 200.0; sky: rainy is not consistent
Original weather forecasts #1 and #2 are different
at natashaepperson_chapter7_exercise_63.WeatherForeca stClient.main(WeatherForecastClient.java:44)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)