This program models weather conditions for different cities by instantiating weather objects, updating their attributes, and calculating weather-related values.
WeatherString city – Name of the city.double temperature – Temperature in Fahrenheit.int humidity – Humidity percentage.boolean isStormy – Indicates if it is stormy.char weatherSymbol – Represents the weather condition ('S' for Sunny, 'C' for Cloudy, 'R' for Rainy, etc.).city and temperature.city, temperature, humidity, and isStormy.updateCity(String newCity) – Updates the city name.updateTemperature(double newTemperature) – Updates the temperature.getHumidity() – Returns the humidity.getWeatherSymbol() – Returns the weather condition symbol.calculateHeatIndex() – Returns heat index as temperature + (humidity * 0.1).isExtremeWeather() – Returns true if extreme weather conditions exist.WeatherMainCreates Objects:
weather1 = new Weather();
weather2 = new Weather("New York", 75.5);
weather3 = new Weather("Los Angeles", 85.0, 40, false);
weather4 = new Weather("Chicago", 30.0, 85, true, 'R');
Calls Methods for Each Object:
BEGIN PROGRAM
CLASS Weather:
DECLARE city AS STRING
DECLARE temperature AS DOUBLE
DECLARE humidity AS INTEGER
DECLARE isStormy AS BOOLEAN
DECLARE weatherSymbol AS CHAR
METHOD Weather() # Default Constructor
SET city = "Unknown"
SET temperature = 0.0
SET humidity = 50
SET isStormy = false
SET weatherSymbol = 'C'
END METHOD
METHOD Weather(city, temperature)
SET city = city
SET temperature = temperature
SET humidity = 50
SET isStormy = false
SET weatherSymbol = 'S'
END METHOD
METHOD Weather(city, temperature, humidity, isStormy)
SET city = city
SET temperature = temperature
SET humidity = humidity
SET isStormy = isStormy
SET weatherSymbol = IF isStormy THEN 'R' ELSE 'C'
END METHOD
METHOD updateCity(newCity)
SET city = newCity
END METHOD
METHOD calculateHeatIndex()
RETURN temperature + (humidity * 0.1)
END METHOD
METHOD isExtremeWeather()
RETURN (temperature > 100 OR temperature < 32 OR humidity > 90 OR isStormy)
END METHOD
END CLASS
CLASS WeatherMain:
CREATE weather1 AS Weather()
CREATE weather2 AS Weather("New York", 75.5)
CREATE weather3 AS Weather("Los Angeles", 85.0, 40, false)
CREATE weather4 AS Weather("Chicago", 30.0, 85, true, 'R')
END CLASS
END PROGRAM
You will drop off 4 files into Google Classroom:
• Your files will be: (Remember the java program is dropped off first.)
• PX_lastname_Weather.java (Java program that is instantiated)
• PX_lastname_WeatherTester.java (Java program that instantiates the object)
• PX_lastname_Weather.png (Screenshot inside Eclipse)
• PX_lastname_Weather.mp4 (Video running the program)
If you do not understand this assignment,
ask Mr. Cusack and/or attend tutorials.