Question: neeed help adding 6 gui components in this program day.java: Tester.java: predictor.java: public int compareTo (Day rhs) // first test rainy versus not rainy //
neeed help adding 6 gui components in this program
day.java:



Tester.java:

predictor.java:




public int compareTo (Day rhs) // first test rainy versus not rainy // and test sunny versus not sunny as if (outlook.equals("rainy") && Irhs.getoutlook ().equals("rainy")) return-1; if (outlook.equals("sunny") && !rhs.getOutlook).equals("sunny")) return 1; // use temp as the next key attribute. use 80 degrees as a cut off if (temp-80 && rhs.getTemp)-85) return 1; if (humidity>-85 && rhs.getHumidity() myData; // data organized by Day's compareTo method incocportate yes, no and maybe fo private ArrayList orginalData; // original data with no changes to class value. set by file and adding private String fileName,; public Predictor) myDatanew TreeSet); orginalDatanew ArrayList); fileNamenull; public Predictor(String fn) { this); // call the default constructor to instantiate the TreeSet fileNamefn; readFile); public String predict (Day d) Day closestFloor-myData.floor(d); Day closestCeiling-myData.ceiling(d); if (closestFloor null && closestCelling null) return "yes" if (closestFloor-null && closestFloor.equals (d)) I7 found an exact match if (closestFloor.getPlayTennis().equals ("no")) return "no" else return "yes"//manages both yes and maybe if (closestCeiling null &&closestCeiling.equals(d)) found an exact match if (closestCeiling.getPlayTennis().equals("no")) return "no"; else return "yes"/manages both yes and maybe if (closestFloor !-null && closestCelling null) { if( closestFloor.getPlayTennis().equals ("no")) return "no"; else return "yes" closestCeiling could have been maybe 70 // if I get here both are not null // if both are no, predict no if (closestFloor.getPlayTennis().equals("no") && closestCeiling.getPlayTennis().equals("no")) return "no" 76 return "yes" 78 public void addDay (Day d) { 79 30 31 orginalData.add(new Day(d.getoutlook(),d.getTemp(),d.getHumidity),d.getwindy),d.getPlayTennis))); // maint // when adding a day, if a similar day exists by the compareTo definition modify the existing // day as follows // if they agree, keep the same // if existing is yes and new is no make maybe // if existing is maybe and new is no make no // if existing is maybe and new is yes make yes // if existing is no and new is yes make maybe 34 35 36 38 39 90 Day closestDay = myData.floor(d); if (closestDaynull closestDay.equals(d)) { myData.add(d); return; 92 93 if (closestDay.getPlayTennis().equals (d.getPlayTennis))) return; // they agree 95 96 if (closestDay.getPlayTennis().equals ("yes") && d.getPlayTennis().equals("no")) closestDay.setPlayTennis("maybe"); else if (closestDay.getPlayTennis().equals("maybe") && d.getPlayTennis).equals ("no")) else if (closestDay.getPlayTennis().equals("maybe") && d.getPlayTennis).equals ("yes")) else if (closestDay.getPlayTennis().equals("no") && d.getPlayTennis ().equals("yes")) 5 98 closestDay.setPlayTennis("no"); closestDay.setPlayTennis("yes"; closestDay.setPlayTennis("maybe"); 01 02 04 05 anothersol/projectl/data.txt 6 public double trainingError ) t 07 08 09 // test the predictive ability on all of the data int count 0; for (Day d:orginalData) String thisPrediction predict (d); if (thisPrediction.equals(d.getPlayTennisO)) 12 13 count++ return (double)count/orginalData.size); 15 16 public String toString)f 17 // returns a string representation of this Predictor String toReturn- for (Day d:myData) 19 20 21 toReturnd.toString)n" return toReturnt"training error: "+trainingError(; 23 24 private void readFile ( 25 26 27 28 // private method that reads the file and stores into TreeSet BufferedReader 1ineReader null; try 3e 31 32 //BufferedReader lineReader new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream(fileName))); FileReader fr new FileReader(fileName); lineReader-new BufferedReader(fr); String line-null; while ((linelineReader.readLine))l) String] tokens-line.split(,"); addDay (new Day (tokens[], Integer parseInt (tokens [1]), Integer.parseInt (tokens [2]),Boolean.parseBoolean (tokens [3].toLowerCase)),tokens [4])); orginalData.add(new Day (tokens[], Integer parseInt(tokens [1]), Integer-parseInt (tokens [2]), Boolean.parseBoolean (tokens [3].toLowerCase)),tokens [4])); 34 36 37 38 39 catch (Exception e) e.printStackTrace (); System.err.println("there was a problem with the file. either no such file or format error"); finally 41 if (lineReader!-null) 42 43 tr lineReader.close); catch (IOException e) i 45 46 System.err.println( "could not close BufferedReader"); 48// end of readFile methood 49 50 public void writeFile 52 53 54 // overloaded method: this calls dowrite with file used to read data // use this for saving data between runs doWrite(fileName); // end of writeFile method 56 public void writeFile(String altFileName) // overloaded method: this calls doWrite with different file name // use this for testing write doWrite(altFileName); 58 59 60 // end of writeFile method 61 62 private void doWrite(String fn) { 63 64 65 // this method writes all of the data in the persons array to a file try Filewriter fw- new FileWriter(fn); BufferedWriter myoutfilenew BufferedWriter(fw); 68 69 70 71 72 73 74 75 76 for (Day d:orginalData) f myOutfile.write(d.getoutlook ()+","+d.getTemp()+","+d.getHumidity()+","+d.getwindy ()+", "+d.getPlayTennis+"n"); myOutfile.flush ); myOutfile.close); catch (Exception e) e.printStackTrace); System.err.println("Didn't save to "+ fn); 78 79 public int compareTo (Day rhs) // first test rainy versus not rainy // and test sunny versus not sunny as if (outlook.equals("rainy") && Irhs.getoutlook ().equals("rainy")) return-1; if (outlook.equals("sunny") && !rhs.getOutlook).equals("sunny")) return 1; // use temp as the next key attribute. use 80 degrees as a cut off if (temp-80 && rhs.getTemp)-85) return 1; if (humidity>-85 && rhs.getHumidity() myData; // data organized by Day's compareTo method incocportate yes, no and maybe fo private ArrayList orginalData; // original data with no changes to class value. set by file and adding private String fileName,; public Predictor) myDatanew TreeSet); orginalDatanew ArrayList); fileNamenull; public Predictor(String fn) { this); // call the default constructor to instantiate the TreeSet fileNamefn; readFile); public String predict (Day d) Day closestFloor-myData.floor(d); Day closestCeiling-myData.ceiling(d); if (closestFloor null && closestCelling null) return "yes" if (closestFloor-null && closestFloor.equals (d)) I7 found an exact match if (closestFloor.getPlayTennis().equals ("no")) return "no" else return "yes"//manages both yes and maybe if (closestCeiling null &&closestCeiling.equals(d)) found an exact match if (closestCeiling.getPlayTennis().equals("no")) return "no"; else return "yes"/manages both yes and maybe if (closestFloor !-null && closestCelling null) { if( closestFloor.getPlayTennis().equals ("no")) return "no"; else return "yes" closestCeiling could have been maybe 70 // if I get here both are not null // if both are no, predict no if (closestFloor.getPlayTennis().equals("no") && closestCeiling.getPlayTennis().equals("no")) return "no" 76 return "yes" 78 public void addDay (Day d) { 79 30 31 orginalData.add(new Day(d.getoutlook(),d.getTemp(),d.getHumidity),d.getwindy),d.getPlayTennis))); // maint // when adding a day, if a similar day exists by the compareTo definition modify the existing // day as follows // if they agree, keep the same // if existing is yes and new is no make maybe // if existing is maybe and new is no make no // if existing is maybe and new is yes make yes // if existing is no and new is yes make maybe 34 35 36 38 39 90 Day closestDay = myData.floor(d); if (closestDaynull closestDay.equals(d)) { myData.add(d); return; 92 93 if (closestDay.getPlayTennis().equals (d.getPlayTennis))) return; // they agree 95 96 if (closestDay.getPlayTennis().equals ("yes") && d.getPlayTennis().equals("no")) closestDay.setPlayTennis("maybe"); else if (closestDay.getPlayTennis().equals("maybe") && d.getPlayTennis).equals ("no")) else if (closestDay.getPlayTennis().equals("maybe") && d.getPlayTennis).equals ("yes")) else if (closestDay.getPlayTennis().equals("no") && d.getPlayTennis ().equals("yes")) 5 98 closestDay.setPlayTennis("no"); closestDay.setPlayTennis("yes"; closestDay.setPlayTennis("maybe"); 01 02 04 05 anothersol/projectl/data.txt 6 public double trainingError ) t 07 08 09 // test the predictive ability on all of the data int count 0; for (Day d:orginalData) String thisPrediction predict (d); if (thisPrediction.equals(d.getPlayTennisO)) 12 13 count++ return (double)count/orginalData.size); 15 16 public String toString)f 17 // returns a string representation of this Predictor String toReturn- for (Day d:myData) 19 20 21 toReturnd.toString)n" return toReturnt"training error: "+trainingError(; 23 24 private void readFile ( 25 26 27 28 // private method that reads the file and stores into TreeSet BufferedReader 1ineReader null; try 3e 31 32 //BufferedReader lineReader new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream(fileName))); FileReader fr new FileReader(fileName); lineReader-new BufferedReader(fr); String line-null; while ((linelineReader.readLine))l) String] tokens-line.split(,"); addDay (new Day (tokens[], Integer parseInt (tokens [1]), Integer.parseInt (tokens [2]),Boolean.parseBoolean (tokens [3].toLowerCase)),tokens [4])); orginalData.add(new Day (tokens[], Integer parseInt(tokens [1]), Integer-parseInt (tokens [2]), Boolean.parseBoolean (tokens [3].toLowerCase)),tokens [4])); 34 36 37 38 39 catch (Exception e) e.printStackTrace (); System.err.println("there was a problem with the file. either no such file or format error"); finally 41 if (lineReader!-null) 42 43 tr lineReader.close); catch (IOException e) i 45 46 System.err.println( "could not close BufferedReader"); 48// end of readFile methood 49 50 public void writeFile 52 53 54 // overloaded method: this calls dowrite with file used to read data // use this for saving data between runs doWrite(fileName); // end of writeFile method 56 public void writeFile(String altFileName) // overloaded method: this calls doWrite with different file name // use this for testing write doWrite(altFileName); 58 59 60 // end of writeFile method 61 62 private void doWrite(String fn) { 63 64 65 // this method writes all of the data in the persons array to a file try Filewriter fw- new FileWriter(fn); BufferedWriter myoutfilenew BufferedWriter(fw); 68 69 70 71 72 73 74 75 76 for (Day d:orginalData) f myOutfile.write(d.getoutlook ()+","+d.getTemp()+","+d.getHumidity()+","+d.getwindy ()+", "+d.getPlayTennis+"n"); myOutfile.flush ); myOutfile.close); catch (Exception e) e.printStackTrace); System.err.println("Didn't save to "+ fn); 78 79