public class DemographicDataWriter
extends Object
Constructor and Description |
---|
DemographicDataWriter() |
Modifier and Type | Method and Description |
---|---|
static void |
writeToHtml(String outfile,
Data data)
Writes out all the CollegeDemographics stored in Data to
an HTML file of a specified format.
|
static void |
writeToScreen(Data data)
For each college in
Data.getColleges() , loops through
and prints the CollegeDemographics.getTable() to the console. |
public static void writeToScreen(Data data)
Data.getColleges()
, loops through
and prints the CollegeDemographics.getTable()
to the console.
This method is mainly a copy from Data printStats, but uses
Data.getColleges()
Natural Sciences: Major Male Female Psychology 24.49% 75.51% Zoology 19.77% 80.23% Biological Science 29.86% 70.14% Computer Science 86.75% 13.25% Statistics 62.07% 37.93% Biochemistry 42.36% 57.64% Chemistry 47.88% 52.12% Mathematics 58.26% 41.74% Applied Computing Technology 81.51% 18.49% Physics 81.63% 18.37% Data Science 75.56% 24.44% Natural Sciences 50.00% 50.00% Engineering: Major Male Female Electrical Engineering 88.72% 11.28% Biomedical Engineering with EE 61.11% 38.89% Mechanical Engineering 86.78% 13.22% Biomedical Engineering with ME 55.16% 44.84% Civil Engineering 74.89% 25.11% Chemical & Biological Engineer 64.41% 35.59% Computer Engineering 92.41% 7.59% Engineering Open Option 80.30% 19.70% Biomedical Engineering with CB 43.13% 56.88% Environmental Engineering 48.60% 51.40% Engineering Science 78.38% 21.62% Engrg Sci and Intl Studies 28.57% 71.43% Biomedical Engineering with EL 100.00% 0.00%
data
- a object that contains CollegeDemographicspublic static void writeToHtml(String outfile, Data data)
For example (note:spacing is optional, but will help with debugging):
<html><head></head><body>
<h1>STEM Demographics Report</h1>
<h2>Spring 2021</h2>
<h3>Demographic data for Natural Sciences</h3>
<table><tr><th>Major</th><th>Male</th><th>Female</th></tr>
<tr><td>Psychology</td><td>23.70%</td><td>76.30%</td></tr>
<tr><td>Zoology</td><td>17.61%</td><td>82.39%</td></tr>
<tr><td>Data Science</td><td>70.27%</td><td>29.73%</td></tr>
<tr><td>Biological Science</td><td>27.71%</td><td>72.29%</td></tr>
<tr><td>Computer Science</td><td>83.61%</td><td>16.39%</td></tr>
<tr><td>Statistics</td><td>65.08%</td><td>34.92%</td></tr>
<tr><td>Chemistry</td><td>44.53%</td><td>55.47%</td></tr>
<tr><td>Biochemistry</td><td>40.07%</td><td>59.93%</td></tr>
<tr><td>Mathematics</td><td>54.67%</td><td>45.33%</td></tr>
<tr><td>Applied Computing Technology</td><td>85.07%</td><td>14.93%</td></tr>
<tr><td>Physics</td><td>80.56%</td><td>19.44%</td></tr>
<tr><td>Natural Sciences</td><td>41.67%</td><td>58.33%</td></tr>
</table>
<h3>Demographic data for Engineering</h3>
<table><tr><th>Major</th><th>Male</th><th>Female</th></tr>
<tr><td>Biomedical Engineering with ME</td><td>53.08%</td><td>46.92%</td></tr>
<tr><td>Biomedical Engineering with EE</td><td>66.67%</td><td>33.33%</td></tr>
<tr><td>Mechanical Engineering</td><td>87.55%</td><td>12.45%</td></tr>
<tr><td>Chemical & Biological Engineer</td><td>63.49%</td><td>36.51%</td></tr>
<tr><td>Electrical Engineering</td><td>88.89%</td><td>11.11%</td></tr>
<tr><td>Computer Engineering</td><td>91.53%</td><td>8.47%</td></tr>
<tr><td>Civil Engineering</td><td>75.98%</td><td>24.02%</td></tr>
<tr><td>Environmental Engineering</td><td>53.26%</td><td>46.74%</td></tr>
<tr><td>Biomedical Engineering with CB</td><td>42.47%</td><td>57.53%</td></tr>
<tr><td>Engrg Sci and Intl Studies</td><td>42.86%</td><td>57.14%</td></tr>
<tr><td>Engineering Science</td><td>71.43%</td><td>28.57%</td></tr>
<tr><td>Biomedical Engineering with EL</td><td>66.67%</td><td>33.33%</td></tr>
<tr><td>Engineering Open Option</td><td>100.00%</td><td>0.00%</td></tr>
</table>
</body></html>
Implementation hints:
try { PrintWriter writer = new PrintWriter(fileName); writer.println(Tag.htmlOpening()); // add file header info // start loop here writer.println(Tag.htmlClosing()); } catch (FileNotFoundException e) { System.err.println(e.getMessage()); System.exit(1); }Most importantly, take it in steps!!
outfile
- the file to write out to.data
- a Data object that contains college DemographicsData.getColleges()
,
Data.getTermFriendlyName()
,
Tag.h1(String)
,
Tag.h2(String)
,
Tag.h3(String)
,
Tag.htmlOpening()
,
Tag.htmlClosing()