Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello please I need help with just question 2 of this problem I included the methods given to me to help with the code. If

image text in transcribed
image text in transcribedHello please I need help with just question 2 of this problem I included the methods given to me to help with the code. If possible please explain in details the steps. Thankyou
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
1 Temperature 15 marks Complete the provided Temperature class. Add any attributes and helper methods as needed but keep in mind that testing will involve only the methods you are asked to write/complete. You must complete the constructors and methods in the provided class (without changing any signatures, return types, or modifiers). In this problem you will need to be able to convert temperatures between Celsius, Fahrenheit and Kelvin. For help, see https://en.wikipedia.org/wiki/Conversion_of_units_of_temperature A temperature object holds a single temperature and displays it in one of the three scales. Once a scale has been set, it will display the temperature in that scale until changed. The default scale is Celsius if not specified. For one of the methods, setTemp (double temp, String scale), the specification is a bit open ended. In this method, you will try to allow any scale input string that resembles the intended input. At the very least, it must work correctly for the three input strings "CELSIUS "FAHRENHEIT" and "KELVIN". In order to receive full marks for this method it must be able to process more strings correctly. For example, see in the examples below. (Don't worry about processing typos of the names. Case and shortened versions should be handled.) Some examples of using a Temperature object: Temperature t new Temperature (10.1); System.out.println(t); COMP1406- Winter 2019 yst.out.pristlas.getscaloo)kotpets theca // outputs 10.1C Assignment #2 Due Friday, February 8 at 5:30 pm t.setScale (Scale.FAHRENHEIT) System.out.println(t); System.out.println(t.getScale)); // outputs the char 'F' t.setTemp (12.25, "Kel"); System.out println(t); // outputs 50. 18F // outputs 12.25K When you set a temperature (without explicitly stating the scale), it is assumed that the input temperature is in whatever scale the object is currently using. Note: You should have no static attributes or methods in your class (unless they were supplied in the starter code) 2 Weather [30 marks) This will be your first problem where you need to deal with several cl larger problem to solve and it can be overwhelming if you try to sit dow one go. Before starting to code, be sure to read through all the provided classes that you will This is your first and solve the it in use (and not make). Read through the BuildDatabase program to understand how to use these other provided classes. Do ONE thing at a time You will implement a simple weather database. The database will store several weather stations and allow for basic queries about the data. Each weather station keeps some records of the weather at the location of the station). A weather record consists of the temperature at a given time. 2 Weather 30 marks This will be your first problem where you need to deal with several classes. This is your first larger problem to solve and it can be overwhelming if you try to sit down and solve the it in one go. Before starting to code, be sure to read through all the provided classes that you will use (and not make). Read through the BuildDatabase program to understand how to use these other provided cl Do ONE thing at a time You will implement a simple weather database. The database will store several weather stations and allow for basic queries about the datai Each weather station keeps some records of the weather (at the location of the station). A weather record consists of the temperature at a given time. You are provided with some classes that you must NOT change: Compare, Scale, TimeStamp and WeatherReport You will need to use your Temererature class from the previous problem in this problem. You must complete the methods in the WeatherDatabase and WeatherStation classes. The API is specified as javadoc comments in the java files. You must decide how to store the state needed for the objects of these classes. Add any attributes and helper methods that you need. Keep in mind that we will only test your code by calling the methods that you are asked to complete. You are NOT allowed to use any external classes unless they are in java. lang or comp1406a2. There is a BuildDatabase program also included in the comp1406a2 package. This program will build a small database consisting of three weather stations that each hold some number of weather reports. Read through this code to see the classes/objects in use. You can use this class as a starting point for testing your classes. Submission Recap youl toue by calling the mthods that you are asked to complete. You are NOT allowed to use any external classes unless they are in java. 1ang or comp1406a2 There is a BuildDatabase program also included in the comp1406a2 package. This program will build a small database consisting of three weather stations that each hold some number of weather reports. Read through this code to see the classes/objects in use. You can use this class as a starting point for testing your classes. Submission Recap A complete assignment will consist of a single file (assignment2.zip) that has a single folder/directory called comp1406a2. The comp1406a2 folder will have the following three files included: Temperature.java WeatherStation.java WeatherDatabase.java All files must have the package comp1406a2; directive as the first line. Your code will NOT compile if it does not have this and you will receive zero correctness marks if your code does not compile. will use our own copy of these files and any changes you make will be lost. COMP1406 - Winter 2019 Do NOT modify Scale.java, Compare. java, TimeStamp. java, or WeatherReport.java. We 1 package comp1486a2; 3 / Builds a sample database that you can use to help 4 with your own coding/debugging public class BuildDatabaset 8Build a small database of weather stations * @param args is not used in this program s/ 10 11 public static void main(tringt) args)t 12 13 WeatherDatabase db - new WeatherDatabase): 14 15 16 // sample database // some WeatherStations WeatherStationI] stationsnew WeatherStation [31; 17 stations te] 18 19 20 21 new WeatherStation("YOW-Airport", 1); new Weatherstation ("Downtown", 2); stations [1] stations (21 - new WeatherStation("Fallowfield-Railway-Station", 3): 22 int[] days (1,2,2,2,4,7,11,20,30,32); 23 doublell temps (10.0, 11, 12, 10, 9.2, 28.1, 10.5, 20, 23, 24 // populate YOw with some weather reports out.println("Building YOW WeatherStation); 29 30 31 Temperature t new Temperature(temps [i]): TimeStamp time new TineStamp(days[11,7, 15+1) WeatherReport wr new WeatherReport(t, time, stations (e) System.out.println("wr.toString) stations [e].addReport (wr); 34 35 // populate Down town weather station 36 days new int(141,2,4,7 37 temps new double[1(12.1, 12.3, 15.2, 16., 17.0h System.out.println("Building Downtown WeatherStation); for(int i-0; iedays, length; ts1)( 38 40 Temperature t # new Temperature(temps[1]); MacBook Pro System.out.print In""wr.tostring) i stations (e].addReport(wr): // populate Down town weather station days new int [ ] {1,2,4,7); temps new doublel1 (12.1, 12.3, 15.2, 16.0, 17.0); 8 System.out.println("Building Downtown WeatherStation"); 9 for( int i=0; iedays, length; tel){ 0 Temperature t new Temperature(temps[i]); TimeStamp time ne imeStamp(days fi],8, i); WeatherReport wr new WeatherReport(t, time, stations (1): System.out.print un( " " + wr.toString() ); stations [1].addReport(wr); 4 16 // populate Fallowfield 8 days new int [141,1,1,2,2,2,3,3,3,4,4,4,5,5,6,6,6,6,7,7,7,8,8,8H temps new double[] (45, -1, -1,-1,-1, -1, -1,-1,-1,-1,-1, -1,-1,-1, 10,10,10,10,20,20,20,25,25,25: System.out.print ln("Building Fallowfield WeatherStation"): for(int i-0; iedays length; tal){ Temperature t = new Temperature(temps[1]); TineStamp tine new TineStamp(days[i], 12, 30+1); therReport wrnew WeatherReport(t, time, stations [21); system. out.println( " " + wr. toString() ); stations [2].addReport(wr) 8 // add stations to database 1 for(int i-0; i t2. 7public static int compare(Temperature t1, Temperature t2) I/ first make sure that they are in the same scale t1.setScale(Scale.CELSIUS); double titemp- t1.getTemp0; t2. setScale(Scale. CELSIUS); double t2temp t2.getTemp); f(, Math.abs( titemp t2temp ) , public WeatherStationl] getWeatherStations)t return null; 39 k Returns the number of weather stations in the database 40 41 @return the number of weather stations in this database 42 43 public int numberOfWeatherStations() 44 return -1; 45 46 47 48 adds a weather station to this database 49 eparam station is the weather station to add. It will always be non-null. 50 * @return this weather station. 52 public WeatherDatabase addweatherStation(WeatherStation station) return this; /1 do NOT change the return statement 57 58 removes weather station with given id from this database * @param id is the ID number of the weather station to remove. *@return true if the specified weather station is successfully removed, returns false otherwise (i.e., if there was no weather station with the specified ID number in this database to begin with). 62 63 public boolean removeWeatherStation(int id) 64 return true; 68 s returns the highest temperature ever recorded by any weather station 70 71 public Temperature getMaxTemperature) * in the data base return nll. MacBook Pro doWeatherRe returns the highest temperature ever recorded by any weather station *in the data base 1 public Temperature getMaxTemperature) 72 73 74 75 76 returns the highest temperature on a specified day return null; * that is recorded in a report in the weather stations in this database. 78 79 80 81 82 83 84 85 86 * @param day is the day to find the max temperature on. Note that this might be the special max temperature day that a weather station records. @return the temperature object with the highest recorded Temperature in the data base on the specified day public Temperature getMaxTemperature(int day)t return null; 89Computes the average temperature (over all weather stations) for the 90 91* time period starting at startDay and ending at endDay (inclusive) 92 eparam startDay is the starting day 93 @param endDay is the ending endDay 94 @return the average temperature of all temperature reports for the time 95 96* 97 98 99 public double averageTemperature(int startDay, int endDay) period startDay to endDay (inclusive) taken from al1 weather stations in this weather database. The average temperature should be returned in the CELSUIS scale. 101 102 103 104 105 106 107 MacBook Pro Scale java TimeStamp.java WeatherDatabas.... WeatherReport ja... Weather package comp1486a2; / A weather report stores the temperature at a given date/time (TimeStamp) */ public class WeatherReportt protected Temperature temperature protected TimeStamp times protected WeatherStation station /* Creates a weather report / public WeatherReport(Temperature temperature, Tinestamp tine, WeatherStation station) this.temperature temperature this.time time; this.station station; /** Getter for the temperature / public Temperature getTemperature)f return this.temperature; ) 9 /* Getter for the date/time / e public TimeStamp getTime() return this.tinei ) * Returns which weather station created the report / public WeatherStation getStation()f return this.station;) 25 / this will let us print a weather report nicely / 26 override 27 public String toString)t 28 29 30 31 32 this.temperature.setscale(Scale.CELSIUS); String out this.temperature.tostring)on"this.tine.tostring) out " at " + this.station.getName(); return out; 34 35 MacBook Pro BuildDatabase.java Compare.java 1 package comp1486a2; 3 **A weather station keeps a collection of weather reports. 4The actual weather station it models will make temperature observations which provides the data for the reports. 7A weather station only needs to remember the last 10 8 reports added to it (in the order that they are added), 9 in addition to the report with the highest temperature that 10 has ever been and recorded/added to this weather station. 11 That is, it only needs to store 11 weather reports in total. 12 13 Notes: The highest ever temperature record might be one of the 14* 15 16* 17 18 19 public class WeatherStationt 20 21 /* 22 /s last 10 added reports but it also might not. You must store the last 18 reports in an array. The higherst ever temperature report does not need to be sotred in this array (unless it was one of the last 1e). 25 BEGINdo NOT change anything until the end of 26 /* 27 /* 28 /* 29 /* 30 this block of attributes, constructor and / and methods s/ 31 The name of this weather station / 32 protected final String name 34 * The id number of this weather station. Should be unique. / 35 protected final int id; 36 37 Initializes this weather station's name and id / 38 public WeatherStation(String nameorStation, int idofstation) 39 40 this.name nameOfStation; this.id-idofStation; MacBook Pro public WeatherStation(String nameotStation, int idorstation)t this.name- nameofStation; this.id idofStation; /* Getter for this weather station's name *@return the name of this weather station public String getName()f return this.name; h 8 1Getter for this weather station's id number 9 @return the ID of this weather station 1 public int getID)t return this.id; h 3 Creates a weather report 4 @param temperature is a valid temperature object correspinding to an obervation at this weather station. 6 @param time is the time that the temoerature was recorded. * @return a weather report for this weather station recording the temperature and time of when the obervation was made. 60 public WeatherReport makeReport(Temperature temperature, TimeStamp time)f 61 62 63 64 / A nice String representation of a weather station object */ 65 @Override 66 public string toString) 67 return this.name+"[id:" +this.id +"]" 68 69 /* 70 /* 71 /* END complete the methods below these comments 72* 73 /* 74 /* 75/* return new WeatherReport(temperature, time, this); 76 MacBook Pro e public WeatherReport makeReport (Temperature temperature, TimeStamp time)t return new WeatherReport(temperature, time, this): 62 63 64 /A nice String representation of a weather station object*/ 65 Override 66 public String toString)t 67 return this.name +[id:" +this.id+"]" 68 69 /* 70/* 71 / END-complete the methods below these comments 72 /* 73 /* 74 /* 75 /* 76 78 Adds a report to the station * eparam report is a WeatherReport to be added to this WeatherStation * ereturn this WeatherStation. (Do NOT alter the return statement of this 81 82 83 84 85 method.) 86 public WeatherStation addReport (WeatherReport report) return this; // do NOT alter the return statement 87 89 98 91 s* Returns the most recently added report. 92 93 94 95 96 * ereturn the most recently added WeatherReport to this weatherstation. If no reports have ever been added then returns nutt. public WeatherReport getMostRecentReport) 98 return null; MacBook Pro @return this WeatherStation. (Do NOT alter the return statement of this method.) public WeatherStation addReport (WeatherReport report)t return this; // do NOT alter the return statement /* Returns the most recently added report. * ereturn the most recently added WeatherReport to this weatherstation. If no reports have ever been added then returns ndit. public WeatherReport getMostRecentReport()t return null; /** Returns the last 10 weather getReports added to this weather station * If there haven't been 1e reports added then return as many as has been added. * ereturn an array of the last 1e added WeatherReports (in the order that they were added). The most recently added report is the first element in the array. If there has been less than 10 reports added to this weatherstation, then returns as many reports as there is. The returned array must be the same size as the number of reports returned. 2 13 14 public WeatherReport!l getReports o 15 16 17 118 119 * Returns a weather report with highest recorded temperature 120 of any report ever added to this WeatherStation. If there have been 121multiple reports with the same highest temperature, the most recentl return nutl; MacBook Pro 100 101 102k Returns the last 10 weather getReports added to this weather station. 103 p> 104 105 * If there haven't been 18 reports added then return as many as has been added. 106 ereturn an array of the last 10 added WeatherReports (in the order 107 108 109 110 that they were added). The most recently added report is the first element in the array If there has been less than 10 reports added to this weatherstation, then returns as many reports as there is. The returned array must be the same size as the number of reports returned. 112* public WeatherReport[) getReports)f 114 115 116 return null; 118 119 /ss Returns a weather report with highest recorded temperature s of any report ever added to this WeatherStation. If there have been tipte reports with the same highest temperature, the most recently * added report is returned,. 123 124 * ereturn a WeatherReport that has the highest recorded temperature of any report ever added to this WeatherStation. Returns null if no report has ever been added to this weatherstation. 126 127 / 129 return nuti; 130 128 public WeatherReport getReportwithMaxTempt) 133 134 135 136 137 138 MacBook Pro 04 F8 F9 1 Temperature 15 marks Complete the provided Temperature class. Add any attributes and helper methods as needed but keep in mind that testing will involve only the methods you are asked to write/complete. You must complete the constructors and methods in the provided class (without changing any signatures, return types, or modifiers). In this problem you will need to be able to convert temperatures between Celsius, Fahrenheit and Kelvin. For help, see https://en.wikipedia.org/wiki/Conversion_of_units_of_temperature A temperature object holds a single temperature and displays it in one of the three scales. Once a scale has been set, it will display the temperature in that scale until changed. The default scale is Celsius if not specified. For one of the methods, setTemp (double temp, String scale), the specification is a bit open ended. In this method, you will try to allow any scale input string that resembles the intended input. At the very least, it must work correctly for the three input strings "CELSIUS "FAHRENHEIT" and "KELVIN". In order to receive full marks for this method it must be able to process more strings correctly. For example, see in the examples below. (Don't worry about processing typos of the names. Case and shortened versions should be handled.) Some examples of using a Temperature object: Temperature t new Temperature (10.1); System.out.println(t); COMP1406- Winter 2019 yst.out.pristlas.getscaloo)kotpets theca // outputs 10.1C Assignment #2 Due Friday, February 8 at 5:30 pm t.setScale (Scale.FAHRENHEIT) System.out.println(t); System.out.println(t.getScale)); // outputs the char 'F' t.setTemp (12.25, "Kel"); System.out println(t); // outputs 50. 18F // outputs 12.25K When you set a temperature (without explicitly stating the scale), it is assumed that the input temperature is in whatever scale the object is currently using. Note: You should have no static attributes or methods in your class (unless they were supplied in the starter code) 2 Weather [30 marks) This will be your first problem where you need to deal with several cl larger problem to solve and it can be overwhelming if you try to sit dow one go. Before starting to code, be sure to read through all the provided classes that you will This is your first and solve the it in use (and not make). Read through the BuildDatabase program to understand how to use these other provided classes. Do ONE thing at a time You will implement a simple weather database. The database will store several weather stations and allow for basic queries about the data. Each weather station keeps some records of the weather at the location of the station). A weather record consists of the temperature at a given time. 2 Weather 30 marks This will be your first problem where you need to deal with several classes. This is your first larger problem to solve and it can be overwhelming if you try to sit down and solve the it in one go. Before starting to code, be sure to read through all the provided classes that you will use (and not make). Read through the BuildDatabase program to understand how to use these other provided cl Do ONE thing at a time You will implement a simple weather database. The database will store several weather stations and allow for basic queries about the datai Each weather station keeps some records of the weather (at the location of the station). A weather record consists of the temperature at a given time. You are provided with some classes that you must NOT change: Compare, Scale, TimeStamp and WeatherReport You will need to use your Temererature class from the previous problem in this problem. You must complete the methods in the WeatherDatabase and WeatherStation classes. The API is specified as javadoc comments in the java files. You must decide how to store the state needed for the objects of these classes. Add any attributes and helper methods that you need. Keep in mind that we will only test your code by calling the methods that you are asked to complete. You are NOT allowed to use any external classes unless they are in java. lang or comp1406a2. There is a BuildDatabase program also included in the comp1406a2 package. This program will build a small database consisting of three weather stations that each hold some number of weather reports. Read through this code to see the classes/objects in use. You can use this class as a starting point for testing your classes. Submission Recap youl toue by calling the mthods that you are asked to complete. You are NOT allowed to use any external classes unless they are in java. 1ang or comp1406a2 There is a BuildDatabase program also included in the comp1406a2 package. This program will build a small database consisting of three weather stations that each hold some number of weather reports. Read through this code to see the classes/objects in use. You can use this class as a starting point for testing your classes. Submission Recap A complete assignment will consist of a single file (assignment2.zip) that has a single folder/directory called comp1406a2. The comp1406a2 folder will have the following three files included: Temperature.java WeatherStation.java WeatherDatabase.java All files must have the package comp1406a2; directive as the first line. Your code will NOT compile if it does not have this and you will receive zero correctness marks if your code does not compile. will use our own copy of these files and any changes you make will be lost. COMP1406 - Winter 2019 Do NOT modify Scale.java, Compare. java, TimeStamp. java, or WeatherReport.java. We 1 package comp1486a2; 3 / Builds a sample database that you can use to help 4 with your own coding/debugging public class BuildDatabaset 8Build a small database of weather stations * @param args is not used in this program s/ 10 11 public static void main(tringt) args)t 12 13 WeatherDatabase db - new WeatherDatabase): 14 15 16 // sample database // some WeatherStations WeatherStationI] stationsnew WeatherStation [31; 17 stations te] 18 19 20 21 new WeatherStation("YOW-Airport", 1); new Weatherstation ("Downtown", 2); stations [1] stations (21 - new WeatherStation("Fallowfield-Railway-Station", 3): 22 int[] days (1,2,2,2,4,7,11,20,30,32); 23 doublell temps (10.0, 11, 12, 10, 9.2, 28.1, 10.5, 20, 23, 24 // populate YOw with some weather reports out.println("Building YOW WeatherStation); 29 30 31 Temperature t new Temperature(temps [i]): TimeStamp time new TineStamp(days[11,7, 15+1) WeatherReport wr new WeatherReport(t, time, stations (e) System.out.println("wr.toString) stations [e].addReport (wr); 34 35 // populate Down town weather station 36 days new int(141,2,4,7 37 temps new double[1(12.1, 12.3, 15.2, 16., 17.0h System.out.println("Building Downtown WeatherStation); for(int i-0; iedays, length; ts1)( 38 40 Temperature t # new Temperature(temps[1]); MacBook Pro System.out.print In""wr.tostring) i stations (e].addReport(wr): // populate Down town weather station days new int [ ] {1,2,4,7); temps new doublel1 (12.1, 12.3, 15.2, 16.0, 17.0); 8 System.out.println("Building Downtown WeatherStation"); 9 for( int i=0; iedays, length; tel){ 0 Temperature t new Temperature(temps[i]); TimeStamp time ne imeStamp(days fi],8, i); WeatherReport wr new WeatherReport(t, time, stations (1): System.out.print un( " " + wr.toString() ); stations [1].addReport(wr); 4 16 // populate Fallowfield 8 days new int [141,1,1,2,2,2,3,3,3,4,4,4,5,5,6,6,6,6,7,7,7,8,8,8H temps new double[] (45, -1, -1,-1,-1, -1, -1,-1,-1,-1,-1, -1,-1,-1, 10,10,10,10,20,20,20,25,25,25: System.out.print ln("Building Fallowfield WeatherStation"): for(int i-0; iedays length; tal){ Temperature t = new Temperature(temps[1]); TineStamp tine new TineStamp(days[i], 12, 30+1); therReport wrnew WeatherReport(t, time, stations [21); system. out.println( " " + wr. toString() ); stations [2].addReport(wr) 8 // add stations to database 1 for(int i-0; i t2. 7public static int compare(Temperature t1, Temperature t2) I/ first make sure that they are in the same scale t1.setScale(Scale.CELSIUS); double titemp- t1.getTemp0; t2. setScale(Scale. CELSIUS); double t2temp t2.getTemp); f(, Math.abs( titemp t2temp ) , public WeatherStationl] getWeatherStations)t return null; 39 k Returns the number of weather stations in the database 40 41 @return the number of weather stations in this database 42 43 public int numberOfWeatherStations() 44 return -1; 45 46 47 48 adds a weather station to this database 49 eparam station is the weather station to add. It will always be non-null. 50 * @return this weather station. 52 public WeatherDatabase addweatherStation(WeatherStation station) return this; /1 do NOT change the return statement 57 58 removes weather station with given id from this database * @param id is the ID number of the weather station to remove. *@return true if the specified weather station is successfully removed, returns false otherwise (i.e., if there was no weather station with the specified ID number in this database to begin with). 62 63 public boolean removeWeatherStation(int id) 64 return true; 68 s returns the highest temperature ever recorded by any weather station 70 71 public Temperature getMaxTemperature) * in the data base return nll. MacBook Pro doWeatherRe returns the highest temperature ever recorded by any weather station *in the data base 1 public Temperature getMaxTemperature) 72 73 74 75 76 returns the highest temperature on a specified day return null; * that is recorded in a report in the weather stations in this database. 78 79 80 81 82 83 84 85 86 * @param day is the day to find the max temperature on. Note that this might be the special max temperature day that a weather station records. @return the temperature object with the highest recorded Temperature in the data base on the specified day public Temperature getMaxTemperature(int day)t return null; 89Computes the average temperature (over all weather stations) for the 90 91* time period starting at startDay and ending at endDay (inclusive) 92 eparam startDay is the starting day 93 @param endDay is the ending endDay 94 @return the average temperature of all temperature reports for the time 95 96* 97 98 99 public double averageTemperature(int startDay, int endDay) period startDay to endDay (inclusive) taken from al1 weather stations in this weather database. The average temperature should be returned in the CELSUIS scale. 101 102 103 104 105 106 107 MacBook Pro Scale java TimeStamp.java WeatherDatabas.... WeatherReport ja... Weather package comp1486a2; / A weather report stores the temperature at a given date/time (TimeStamp) */ public class WeatherReportt protected Temperature temperature protected TimeStamp times protected WeatherStation station /* Creates a weather report / public WeatherReport(Temperature temperature, Tinestamp tine, WeatherStation station) this.temperature temperature this.time time; this.station station; /** Getter for the temperature / public Temperature getTemperature)f return this.temperature; ) 9 /* Getter for the date/time / e public TimeStamp getTime() return this.tinei ) * Returns which weather station created the report / public WeatherStation getStation()f return this.station;) 25 / this will let us print a weather report nicely / 26 override 27 public String toString)t 28 29 30 31 32 this.temperature.setscale(Scale.CELSIUS); String out this.temperature.tostring)on"this.tine.tostring) out " at " + this.station.getName(); return out; 34 35 MacBook Pro BuildDatabase.java Compare.java 1 package comp1486a2; 3 **A weather station keeps a collection of weather reports. 4The actual weather station it models will make temperature observations which provides the data for the reports. 7A weather station only needs to remember the last 10 8 reports added to it (in the order that they are added), 9 in addition to the report with the highest temperature that 10 has ever been and recorded/added to this weather station. 11 That is, it only needs to store 11 weather reports in total. 12 13 Notes: The highest ever temperature record might be one of the 14* 15 16* 17 18 19 public class WeatherStationt 20 21 /* 22 /s last 10 added reports but it also might not. You must store the last 18 reports in an array. The higherst ever temperature report does not need to be sotred in this array (unless it was one of the last 1e). 25 BEGINdo NOT change anything until the end of 26 /* 27 /* 28 /* 29 /* 30 this block of attributes, constructor and / and methods s/ 31 The name of this weather station / 32 protected final String name 34 * The id number of this weather station. Should be unique. / 35 protected final int id; 36 37 Initializes this weather station's name and id / 38 public WeatherStation(String nameorStation, int idofstation) 39 40 this.name nameOfStation; this.id-idofStation; MacBook Pro public WeatherStation(String nameotStation, int idorstation)t this.name- nameofStation; this.id idofStation; /* Getter for this weather station's name *@return the name of this weather station public String getName()f return this.name; h 8 1Getter for this weather station's id number 9 @return the ID of this weather station 1 public int getID)t return this.id; h 3 Creates a weather report 4 @param temperature is a valid temperature object correspinding to an obervation at this weather station. 6 @param time is the time that the temoerature was recorded. * @return a weather report for this weather station recording the temperature and time of when the obervation was made. 60 public WeatherReport makeReport(Temperature temperature, TimeStamp time)f 61 62 63 64 / A nice String representation of a weather station object */ 65 @Override 66 public string toString) 67 return this.name+"[id:" +this.id +"]" 68 69 /* 70 /* 71 /* END complete the methods below these comments 72* 73 /* 74 /* 75/* return new WeatherReport(temperature, time, this); 76 MacBook Pro e public WeatherReport makeReport (Temperature temperature, TimeStamp time)t return new WeatherReport(temperature, time, this): 62 63 64 /A nice String representation of a weather station object*/ 65 Override 66 public String toString)t 67 return this.name +[id:" +this.id+"]" 68 69 /* 70/* 71 / END-complete the methods below these comments 72 /* 73 /* 74 /* 75 /* 76 78 Adds a report to the station * eparam report is a WeatherReport to be added to this WeatherStation * ereturn this WeatherStation. (Do NOT alter the return statement of this 81 82 83 84 85 method.) 86 public WeatherStation addReport (WeatherReport report) return this; // do NOT alter the return statement 87 89 98 91 s* Returns the most recently added report. 92 93 94 95 96 * ereturn the most recently added WeatherReport to this weatherstation. If no reports have ever been added then returns nutt. public WeatherReport getMostRecentReport) 98 return null; MacBook Pro @return this WeatherStation. (Do NOT alter the return statement of this method.) public WeatherStation addReport (WeatherReport report)t return this; // do NOT alter the return statement /* Returns the most recently added report. * ereturn the most recently added WeatherReport to this weatherstation. If no reports have ever been added then returns ndit. public WeatherReport getMostRecentReport()t return null; /** Returns the last 10 weather getReports added to this weather station * If there haven't been 1e reports added then return as many as has been added. * ereturn an array of the last 1e added WeatherReports (in the order that they were added). The most recently added report is the first element in the array. If there has been less than 10 reports added to this weatherstation, then returns as many reports as there is. The returned array must be the same size as the number of reports returned. 2 13 14 public WeatherReport!l getReports o 15 16 17 118 119 * Returns a weather report with highest recorded temperature 120 of any report ever added to this WeatherStation. If there have been 121multiple reports with the same highest temperature, the most recentl return nutl; MacBook Pro 100 101 102k Returns the last 10 weather getReports added to this weather station. 103 p> 104 105 * If there haven't been 18 reports added then return as many as has been added. 106 ereturn an array of the last 10 added WeatherReports (in the order 107 108 109 110 that they were added). The most recently added report is the first element in the array If there has been less than 10 reports added to this weatherstation, then returns as many reports as there is. The returned array must be the same size as the number of reports returned. 112* public WeatherReport[) getReports)f 114 115 116 return null; 118 119 /ss Returns a weather report with highest recorded temperature s of any report ever added to this WeatherStation. If there have been tipte reports with the same highest temperature, the most recently * added report is returned,. 123 124 * ereturn a WeatherReport that has the highest recorded temperature of any report ever added to this WeatherStation. Returns null if no report has ever been added to this weatherstation. 126 127 / 129 return nuti; 130 128 public WeatherReport getReportwithMaxTempt) 133 134 135 136 137 138 MacBook Pro 04 F8 F9

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

2. What efforts are countries making to reverse the brain drain?

Answered: 1 week ago