Question
C reate a class called WeatherData that will store information about daily weather conditions for NASA. It should be able to store the current daily
C reate a class called WeatherData that will store information about daily weather conditions for NASA. It should be able to store the current daily temperature as well as wind speed. You also want to use good object-oriented programming (OOP) practices and ensure that the WeatherData class contains the following methods:
Default constructor: WeatherData() Overloaded constructor: WeatherData(double dailyTemp, int windSpeed) Mutators / set methods: void setDailyTemp(double newTemp), void setWindSpeed(int newWindSpeed) Accessors / get methods: double getDailyTemp(), int getWindSpeed() String method that returns a description of all class data as a string: String toString() Equals method that can compare WeatherData objects: boolean equals(Object obj)
Ensure that the WeatherData class is stored in a file called WeatherData.java. Thencreate another class called Test (within the same project) that contains the main() method with the following test code:
WeatherData day1 = new WeatherData(); // Next two lines will test the set() methods day1.setDailyTemp(75.0); day1.setWindSpeed(100); // This next line tests the toString() method in WeatherData for Day1 System.out.println("Day1->" + day1); WeatherData day2 = new WeatherData(52.0, 10); // This next line tests the toString() method in WeatherData for Day2 System.out.println("Day2->" + day2); // This next line will test the equals() method in WeatherData with two different objects if(day1 == day2) System.out.println("Day1 is equal to Day2"); else System.out.println("Day1 is NOT equal to Day2"); // This next line will test the equals() method in WeatherData with two equal objects WeatherData day3 = new WeatherData(75.0, 100); if(day1 == day3) System.out.println("Day1 is equal to Day3"); else System.out.println("Day1 is NOT equal to Day3"); // The next two lines will test the get() methods of the WeatherData class. System.out.println("Day2 Daily Temperature: " + day2.getDailyTemp()); System.out.println("Day3 Wind Speed: " + day3.getWindSpeed());
Ensure that the test class is stored in a file called Test.java. When you run the Test application, the output should be as follows:
Day1->Weather Data: Daily Temperature = 75.0 F. Wind Speed = 100 mph. Day2->Weather Data: Daily Temperature = 52.0 F. Wind Speed = 10 mph. Day1 is NOT equal to Day2 Day1 is equal to Day3 Day2 Daily Temperature: 52.0 Day3 WindSpeed: 100
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started