Question
Help me code the whole program in java Date.java public class Date { public int year; public int month; public int day; public int sYear;
Help me code the whole program in java Date.java public class Date { public int year; public int month; public int day; public int sYear; public int sMonth; public int sDay; //getter and setter methods public int getYear(){ return year; } public int getMonth(){ return month; } public int getDay(){ return day; } public void setYear(int sYear){ this.sYear=sYear; } public void setMonth(int sMonth){ this.sMonth= sMonth; } public void setDay(int sDay){ this.sDay= sDay; } } WeatherDay.java public class WeatherDay { //Attributes public Date date; public int tempHigh; public Double tempAvg; public int tempLow; public Double humidityAvg; public Double windAvg; public Double precipitation; public Double heatIndex; //getter methods public Date getDate(){ return date; } public int getTempHigh(){ return tempHigh; } public Double getTempAvg(){ return tempAvg; } public int getTempLow(){ return tempLow; } public Double getHumidityAvg(){ return humidityAvg; } public Double getWindAvg(){ return windAvg; } public Double getPrecipitation(){ return precipitation; } public Double calcHeatIndex(){ return heatIndex; } }
SeattleWeather.txt > https://ufile.io/7whj0upa
Project 5: Seattle Weather 1 Objective Now that we've created and used basic objects, we're moving forward to deeper object interactions. We're adding in two new concepts as well: reading data from a file and storing objects in an array. This program has no user interaction. But it will certainly have test methods that ensure all objects are behaving as intended, plus a Main class to demonstrate the code's capability. 2 Seattle Weather File 2.1 File Contents The file "SeattleWeather.txt" is provided for you. It contains sample weather data, one day per line. The first line contains a count of weather rows. The second line, a header that lets you know the contents of each column. The third and subsequent lines are weather data. Expect the file to cover multiple years. Months will be complete until near the end of the file; there, the most recent month will have at least one day of weather but isn't guaranteed to have more than that. Here's an example of what the first three lines of the file might look like, with the header line truncated for the sake of space: 424 Year, Month, Day, TempMax, TempAvg, TempMin, DewPointMax, DewPointAvg, DewPointMin... 2018,1,1,43,36,32,32,30.1, 28, 89, 79.5,62,12,8.7,5,29.9,29.9, 29.8,0 2.2 Weather Data Each data row contains multiple columns of weather data. While all the data must be read, not all of it must be stored in the Weather Day object; we'll narrow it down to make life easier for you. Most columns contain integer data; some (especially averages) are floating-point numbers. All rows contain the same number of columns. Consider opening this in Excel (choose Delimited, Commas) for inspection. 3 Objects In order of increasing complexity, here are the objects you'll create. 3.1 Date While there are certainly more date capabilities built into Java, we won't use them here. To practice with objects, we'll create our own Date object that consists of a year, a month, and a day. We'll provide simple, standard set/get methods for these. 3.2 Date Range This object makes it convenient to package up two dates; this is useful in describing date ranges. 3.3 Weather Day This object represents one day's historical weather data. It will have a full constructor and the typical get methods; you don't need to write set methods for it, however. In addition to remembering and supplying this data, it can also calculate the day's heat index based on the high temperature and the average humidity for the day. The formula for this can be found on these two sites: Wikipedia, NOAA. Use the first formula shown, with no adjustments or alternate calculations. 3.4 Weather Manager This object is the main way that client code will interact with the rest of the system. It will have a variety of useful methods that will let clients glean useful information about weather data and trends. While we could imagine many methods to write, we'll keep it to a small number for now. It will be able to read the data file and retrieve and find a Weather Day in its array. It will also be able to calculate the average high temperature for a specified month, and the average low temperature for a month. It will also calculate the rain total for a specified month. The more algorithmically challenging methods will calculate the rainiest month in a specified year (based on total precipitation for that month) and find the longest warming trend of the year (the longest range of days in the year where the temperature kept increasing day to day). 4 Objects Overview Here are UML Class Diagrams for the classes you are to create. Create exactly these methods, with exactly the parameters and return types shown. See the next page for other important notes. Date Date Range you figure out what goes here) start: Date -end : Date +Date(year: Integer, month: Integer day: Integer) +DateRange(start Date, end : Date) gerYear(): Integer getMonth(): Integer getDay) Integer +getstart(): Date +getEnd(): Date +setYeartyear Integer) +set Month month : Integer) +SeDay(day: Integer) setStart date : Date) + setEnd(date: Date) Weather Day Weather Manager (you figure out what goes here) (you figure out what goes here) +WeatherDay...all data...) Weather Manager(weatherFile:File) + getWeatherDayCount(): Integer +getWeather Day index: Integer) Weather Day +findWeather Daydate:Date): Integer getDate(): Date * getTempHigh(): Integer + getTempArg(): Double +getTempLow(): Integer +getHumidity Avg Double +getWindAng(): Double +getPrecipitation(): Double +calcAgHigh Templear: Integer, month: Integer): Double calcAnglowTemplyear: Integer, month: Integer): Double calcHeatindex(): Double +calcRainTotallyear: Integer month : Integer): Double +calcRainiestMonth year. Integer) Integer +calcLongestWarming Trend(year: Integer): DateRange 5 Object Details 5.1 Date Throw an illegalArgumentException if the year is negative, month is outside the range 1...12, or day is outside the range 1...31'. You aren't responsible for leap year checks or month-length checks, unless you want to do the extra work. In the toString method, render the date in the typical US format: MM/DD/YY 5.2 DateRange Throw an illegalArgumentException is either Date reference is null In the toString method, show the start and end of the date range. Don't duplicate code from the Date toString method; leverage it instead. 5.3 Weather Day Throw an IllegalArgumentException if the date reference is null In the toString method, display all weather data, one item per line, nicely labeled. 5.4 Weather Manager The constructor should create the array and read in the data from the specified file. Use a Scanner to read the text file; see the Hints section for more information. Think carefully about the private member data you choose to store; just because you can compute it doesn't mean you need to store it. Consider that later we might add, delete, or correct weather data; code so that won't be a problem. Algorithms should not traverse the array more than necessary. If you locate what you're looking for, you shouldn't continue to loop. For more complex algorithms, you should be able to locate the starting point, then move forward only as far as necessary. You should not go back over list items again, nor create side arrays in the process. Return "signal" data when appropriate, e.g., in findWeather Day, if there is no such day in the data, a return of -1 would be a good response. Prefer this to throwing exceptions. 5.5 General Write good loop conditions that make the loop exit condition clear. Don't use forbidden keywords break or continue; there is a place for those in the real world, but even there you should avoid them when simple, straightforward logic can be used. 5.6 Main Write some lines of code that demonstrate the capabilities of the code and display the results. You don't need to demonstrate everything, just some high-level stuff you're proud of. 6 Code Implementation Use exactly the method names shown, or instructor test code will fail, and you'll lose points. Look carefully at the parameter data types and the return data types; they give you clues. Follow our Course Style Guide found in Canvas. 7 Testing The testing required here is significant and shouldn't be an afterthought. It may take you almost as much time as writing your production" classes. Don't forget to test all constructors, accessors, mutators, and preconditions. To fully test the rainest month and warming trend methods, you'll need a variety of test files. Create various files with distinct "challenges to the algorithms, e.g., is the first month the rainiest, or the last? What about a single day recorded for a month, with the rainiest month on that single day? This is important because our algorithms often create off-by-one errors and other logic errors; these can only be found through careful testing. Place test files in your project folder. 8 Submitting Your Work . You'll be creating multiple java classes (java) files and test files (.txt). Blue) can create .jar files; be sure and specify "include source" when you use this method. If your test method relies on test files, be sure and include them in your submission. 9 Extra Credit Write a WeatherManager method calcAvg Monthly HighTemps. It should take one parameter, the year. It should return an array representing the high temperatures for each month within that year. To make it easy, use the month as an index, e.g., January's data goes in position 1 of the array, not position 0. Any months that aren't represented in the file should be represented by a value of -1.0 (since there may be more months in the calendar year than are represented in the file). While implementing this, consider that parallel arrays might make the algorithm more straightforward; they are allowed here though creating extra arrays is prohibited elsewhere in the project. 10 Hints I suggest building objects from the ground up, e.g., start with the Date class coding and testing, then move on to DateRange, then WeatherDay, then WeatherManager. Incrementally develop your solution, building small additions on the solid foundation you've already laid. Don't duplicate code; avoid this wherever possible. The algorithms for the Weather Manager's rainiest month and longest warming trend methods require some thought before coding. I highly recommend doing work on paper or a whiteboard to come with an algorithm, then writing pseudocode, then finally code. The text file is not a tokenized file; it has no traditional token separators. You'll need to read the whole record (one line of weather data), then break it up into fields (columns). For rainiest month and longest warming trend, if 2+ months/ranges are the same, return the first. Project 5: Seattle Weather 1 Objective Now that we've created and used basic objects, we're moving forward to deeper object interactions. We're adding in two new concepts as well: reading data from a file and storing objects in an array. This program has no user interaction. But it will certainly have test methods that ensure all objects are behaving as intended, plus a Main class to demonstrate the code's capability. 2 Seattle Weather File 2.1 File Contents The file "SeattleWeather.txt" is provided for you. It contains sample weather data, one day per line. The first line contains a count of weather rows. The second line, a header that lets you know the contents of each column. The third and subsequent lines are weather data. Expect the file to cover multiple years. Months will be complete until near the end of the file; there, the most recent month will have at least one day of weather but isn't guaranteed to have more than that. Here's an example of what the first three lines of the file might look like, with the header line truncated for the sake of space: 424 Year, Month, Day, TempMax, TempAvg, TempMin, DewPointMax, DewPointAvg, DewPointMin... 2018,1,1,43,36,32,32,30.1, 28, 89, 79.5,62,12,8.7,5,29.9,29.9, 29.8,0 2.2 Weather Data Each data row contains multiple columns of weather data. While all the data must be read, not all of it must be stored in the Weather Day object; we'll narrow it down to make life easier for you. Most columns contain integer data; some (especially averages) are floating-point numbers. All rows contain the same number of columns. Consider opening this in Excel (choose Delimited, Commas) for inspection. 3 Objects In order of increasing complexity, here are the objects you'll create. 3.1 Date While there are certainly more date capabilities built into Java, we won't use them here. To practice with objects, we'll create our own Date object that consists of a year, a month, and a day. We'll provide simple, standard set/get methods for these. 3.2 Date Range This object makes it convenient to package up two dates; this is useful in describing date ranges. 3.3 Weather Day This object represents one day's historical weather data. It will have a full constructor and the typical get methods; you don't need to write set methods for it, however. In addition to remembering and supplying this data, it can also calculate the day's heat index based on the high temperature and the average humidity for the day. The formula for this can be found on these two sites: Wikipedia, NOAA. Use the first formula shown, with no adjustments or alternate calculations. 3.4 Weather Manager This object is the main way that client code will interact with the rest of the system. It will have a variety of useful methods that will let clients glean useful information about weather data and trends. While we could imagine many methods to write, we'll keep it to a small number for now. It will be able to read the data file and retrieve and find a Weather Day in its array. It will also be able to calculate the average high temperature for a specified month, and the average low temperature for a month. It will also calculate the rain total for a specified month. The more algorithmically challenging methods will calculate the rainiest month in a specified year (based on total precipitation for that month) and find the longest warming trend of the year (the longest range of days in the year where the temperature kept increasing day to day). 4 Objects Overview Here are UML Class Diagrams for the classes you are to create. Create exactly these methods, with exactly the parameters and return types shown. See the next page for other important notes. Date Date Range you figure out what goes here) start: Date -end : Date +Date(year: Integer, month: Integer day: Integer) +DateRange(start Date, end : Date) gerYear(): Integer getMonth(): Integer getDay) Integer +getstart(): Date +getEnd(): Date +setYeartyear Integer) +set Month month : Integer) +SeDay(day: Integer) setStart date : Date) + setEnd(date: Date) Weather Day Weather Manager (you figure out what goes here) (you figure out what goes here) +WeatherDay...all data...) Weather Manager(weatherFile:File) + getWeatherDayCount(): Integer +getWeather Day index: Integer) Weather Day +findWeather Daydate:Date): Integer getDate(): Date * getTempHigh(): Integer + getTempArg(): Double +getTempLow(): Integer +getHumidity Avg Double +getWindAng(): Double +getPrecipitation(): Double +calcAgHigh Templear: Integer, month: Integer): Double calcAnglowTemplyear: Integer, month: Integer): Double calcHeatindex(): Double +calcRainTotallyear: Integer month : Integer): Double +calcRainiestMonth year. Integer) Integer +calcLongestWarming Trend(year: Integer): DateRange 5 Object Details 5.1 Date Throw an illegalArgumentException if the year is negative, month is outside the range 1...12, or day is outside the range 1...31'. You aren't responsible for leap year checks or month-length checks, unless you want to do the extra work. In the toString method, render the date in the typical US format: MM/DD/YY 5.2 DateRange Throw an illegalArgumentException is either Date reference is null In the toString method, show the start and end of the date range. Don't duplicate code from the Date toString method; leverage it instead. 5.3 Weather Day Throw an IllegalArgumentException if the date reference is null In the toString method, display all weather data, one item per line, nicely labeled. 5.4 Weather Manager The constructor should create the array and read in the data from the specified file. Use a Scanner to read the text file; see the Hints section for more information. Think carefully about the private member data you choose to store; just because you can compute it doesn't mean you need to store it. Consider that later we might add, delete, or correct weather data; code so that won't be a problem. Algorithms should not traverse the array more than necessary. If you locate what you're looking for, you shouldn't continue to loop. For more complex algorithms, you should be able to locate the starting point, then move forward only as far as necessary. You should not go back over list items again, nor create side arrays in the process. Return "signal" data when appropriate, e.g., in findWeather Day, if there is no such day in the data, a return of -1 would be a good response. Prefer this to throwing exceptions. 5.5 General Write good loop conditions that make the loop exit condition clear. Don't use forbidden keywords break or continue; there is a place for those in the real world, but even there you should avoid them when simple, straightforward logic can be used. 5.6 Main Write some lines of code that demonstrate the capabilities of the code and display the results. You don't need to demonstrate everything, just some high-level stuff you're proud of. 6 Code Implementation Use exactly the method names shown, or instructor test code will fail, and you'll lose points. Look carefully at the parameter data types and the return data types; they give you clues. Follow our Course Style Guide found in Canvas. 7 Testing The testing required here is significant and shouldn't be an afterthought. It may take you almost as much time as writing your production" classes. Don't forget to test all constructors, accessors, mutators, and preconditions. To fully test the rainest month and warming trend methods, you'll need a variety of test files. Create various files with distinct "challenges to the algorithms, e.g., is the first month the rainiest, or the last? What about a single day recorded for a month, with the rainiest month on that single day? This is important because our algorithms often create off-by-one errors and other logic errors; these can only be found through careful testing. Place test files in your project folder. 8 Submitting Your Work . You'll be creating multiple java classes (java) files and test files (.txt). Blue) can create .jar files; be sure and specify "include source" when you use this method. If your test method relies on test files, be sure and include them in your submission. 9 Extra Credit Write a WeatherManager method calcAvg Monthly HighTemps. It should take one parameter, the year. It should return an array representing the high temperatures for each month within that year. To make it easy, use the month as an index, e.g., January's data goes in position 1 of the array, not position 0. Any months that aren't represented in the file should be represented by a value of -1.0 (since there may be more months in the calendar year than are represented in the file). While implementing this, consider that parallel arrays might make the algorithm more straightforward; they are allowed here though creating extra arrays is prohibited elsewhere in the project. 10 Hints I suggest building objects from the ground up, e.g., start with the Date class coding and testing, then move on to DateRange, then WeatherDay, then WeatherManager. Incrementally develop your solution, building small additions on the solid foundation you've already laid. Don't duplicate code; avoid this wherever possible. The algorithms for the Weather Manager's rainiest month and longest warming trend methods require some thought before coding. I highly recommend doing work on paper or a whiteboard to come with an algorithm, then writing pseudocode, then finally code. The text file is not a tokenized file; it has no traditional token separators. You'll need to read the whole record (one line of weather data), then break it up into fields (columns). For rainiest month and longest warming trend, if 2+ months/ranges are the same, return the firstStep 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