You will add features to a program that have written that works with weather data provided by the Climate Data Online service of the National Oceanic and Atmospheric Administration. The program in its current form will read data from any of the three files below and display the information in a GUI. However, it doesn't display all the information that is provided in the files for Berlin, Ohio and the Akron-Canton Airport. There are also several buttons that currently don't work. You are supposed to fill in the missing functionality.
Data files:
Berlin, Ohio Akron-Canton Airport (CAK) Chardon, Ohio Documentation on the format of the data can be read here. To test the program on these files, you should download each file to your computer; when you run the program and press the Read from file button, a dialog box will pop up and you can browse to find the file. Here is a task list to follow to help guide:
Add code to sort the objects in weatherRecordList by date; each click on the associated button should reverse the sort order from the previous time the data was sorted by date Add code to sort the objects in weatherRecordList by precipitation; each click on the associated button should reverse the sort order from the previous time the data was sorted by precipitation Add code to clear all the objects out of weatherRecordList (hint: just replace the current list with a new empty one)
Please try to keep it simple, and please explain how it works. Thank you
5 import javafx.application. Application; 6 import javafx.stage. Stage; 7 import javafx.scene. Scene; 8 import javafx.scene.control.Button; 9 import javafx.scene.layout.HBox; 10 import java.util.ArrayList; 11 import javafx.scene.control.TextArea; 12 import javafx.scene. e.layout. VBox; 13 import javafx.stage.FileChooser; 14 import java.io.File; 15 import java.io.PrintWriter; 16 import java.io.StringWriter; 17 import java.util.Scanner; 18 import weather_record_hierarchy. WeatherRecord; 19 import weather record hierarchy. Weather RecordReader; 20 21 public class DailyWeatherHistory extends Application 22 { 23 private ArrayList
weatherRecordList = new ArrayList(); 24 25 private final TextArea outputArea = new TextArea(); 26 27 // You may need to add some of your own instance variables here. 28 29 @Override public void start(Stage stage) throws Exception 31 { 32 // Set up horizontal control panel 33 Button readData = new Button("Read from file"); 34 Button sortByDate = new Button("Sort by date"); 35 Button sortByPrcp = new Button("Sort by precipitation"); 36 Button writeData = new Button("Write to file"); 37 Button clear = new Button("Clear"); 30 Nm in 26 27 // You may need to add some of your own instance variables here. 28 @Override public void start(Stage stage) throws Exception { // Set up horizontal control panel Button readData = new Button("Read from file"); Button sortByDate = new Button("Sort by date"); Button sortByPrcp = new Button("Sort by precipitation"); Button writeData new Button("Write to file"); Button clear = new Button("Clear"); HBox controlpanel = new HBox(readData, sortByDate, sortByPrcp, writeData, clear); 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 // "Wire" each button to some methods below. readData.setOnAction((e)->readTextFile()); sortByDate.setOnAction((e)->sortByDate()); sortByProp.setOnAction((e)->sortByProp()); writeData.setOnAction((e)->writeTextFile()); clear.setOnAction((e)->clearlist()); // Configure output area outputArea.setPrefRowCount(40); outputArea.setPrefColumnCount(100); outputArea.setStyle("-fx-font-family: monospace"); // Configure and show scene. // Control panel goes above the output area in the scene. stage.setTitle("Daily Weather History" ); stage.setScene(new Scene(new VBox(controlpanel, outputArea))); stage.show(); } // Display the data from weatherRecordList. 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 // Display the data from weatherRecordList. // Uses a PrintWriter wrapped around a StringWriter (instead of a // FileWriter) to speed up the process. // Code for each button should call this method when it is done // changing weatherRecordList. public void displayData() { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); for (WeatherRecord r: weatherRecordList) { pw.println(r.toString()); } outputArea.setText(sw.toString()); } 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 // The following are methods wired to buttons. public void readTextFile() { File file = new FileChooser().showOpenDialog(null); if (file != null) { try (Scanner inScan = new Scanner(file)) { Weather RecordReader.readList(inScan, weather RecordList); } catch (Exception e) { System.err.println("Error reading + file.getName()); } } displayData(); Main.java displayData(); } // The body of this method needs to be replaced with your own code. private void sortByDate() { outputArea.setText("Not supported yet."); } // The body of this method needs to be replaced with your own code. private void sortByProp() { outputArea.setText("Not supported yet."); } 91 92 93 94 95 96 97 98 99 100 101 102 - 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 } // The Last line of the body of this method needs to be replaced with your own code. private void writeTextFile() { File file = new FileChooser().showSaveDialog(null); outputArea.setText("Not supported yet."); } // The body of this method needs to be replaced with your own code. private void clearlist() { outputArea.setText("Not supported yet."); } public static void main(String[] args) { launch(args); } 5 import javafx.application. Application; 6 import javafx.stage. Stage; 7 import javafx.scene. Scene; 8 import javafx.scene.control.Button; 9 import javafx.scene.layout.HBox; 10 import java.util.ArrayList; 11 import javafx.scene.control.TextArea; 12 import javafx.scene. e.layout. VBox; 13 import javafx.stage.FileChooser; 14 import java.io.File; 15 import java.io.PrintWriter; 16 import java.io.StringWriter; 17 import java.util.Scanner; 18 import weather_record_hierarchy. WeatherRecord; 19 import weather record hierarchy. Weather RecordReader; 20 21 public class DailyWeatherHistory extends Application 22 { 23 private ArrayList weatherRecordList = new ArrayList(); 24 25 private final TextArea outputArea = new TextArea(); 26 27 // You may need to add some of your own instance variables here. 28 29 @Override public void start(Stage stage) throws Exception 31 { 32 // Set up horizontal control panel 33 Button readData = new Button("Read from file"); 34 Button sortByDate = new Button("Sort by date"); 35 Button sortByPrcp = new Button("Sort by precipitation"); 36 Button writeData = new Button("Write to file"); 37 Button clear = new Button("Clear"); 30 Nm in 26 27 // You may need to add some of your own instance variables here. 28 @Override public void start(Stage stage) throws Exception { // Set up horizontal control panel Button readData = new Button("Read from file"); Button sortByDate = new Button("Sort by date"); Button sortByPrcp = new Button("Sort by precipitation"); Button writeData new Button("Write to file"); Button clear = new Button("Clear"); HBox controlpanel = new HBox(readData, sortByDate, sortByPrcp, writeData, clear); 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 // "Wire" each button to some methods below. readData.setOnAction((e)->readTextFile()); sortByDate.setOnAction((e)->sortByDate()); sortByProp.setOnAction((e)->sortByProp()); writeData.setOnAction((e)->writeTextFile()); clear.setOnAction((e)->clearlist()); // Configure output area outputArea.setPrefRowCount(40); outputArea.setPrefColumnCount(100); outputArea.setStyle("-fx-font-family: monospace"); // Configure and show scene. // Control panel goes above the output area in the scene. stage.setTitle("Daily Weather History" ); stage.setScene(new Scene(new VBox(controlpanel, outputArea))); stage.show(); } // Display the data from weatherRecordList. 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 // Display the data from weatherRecordList. // Uses a PrintWriter wrapped around a StringWriter (instead of a // FileWriter) to speed up the process. // Code for each button should call this method when it is done // changing weatherRecordList. public void displayData() { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); for (WeatherRecord r: weatherRecordList) { pw.println(r.toString()); } outputArea.setText(sw.toString()); } 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 // The following are methods wired to buttons. public void readTextFile() { File file = new FileChooser().showOpenDialog(null); if (file != null) { try (Scanner inScan = new Scanner(file)) { Weather RecordReader.readList(inScan, weather RecordList); } catch (Exception e) { System.err.println("Error reading + file.getName()); } } displayData(); Main.java displayData(); } // The body of this method needs to be replaced with your own code. private void sortByDate() { outputArea.setText("Not supported yet."); } // The body of this method needs to be replaced with your own code. private void sortByProp() { outputArea.setText("Not supported yet."); } 91 92 93 94 95 96 97 98 99 100 101 102 - 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 } // The Last line of the body of this method needs to be replaced with your own code. private void writeTextFile() { File file = new FileChooser().showSaveDialog(null); outputArea.setText("Not supported yet."); } // The body of this method needs to be replaced with your own code. private void clearlist() { outputArea.setText("Not supported yet."); } public static void main(String[] args) { launch(args); }