public class Data
extends Object
Modifier and Type | Field and Description |
---|---|
private static int |
COLLEGE
Sets the index of the COLLEGE CODE when reading from the file format (for ease of reading in the code).
|
private CollegeDemographics[] |
collegeDemographics
Created a default array of only two colleges for this assignment.
|
private static int |
GENDER
Index of the GENDER, set to 5
|
private static int |
PRIMARY_MAJOR_DESC
Index of PRIMARY_MAJOR_DESC, set to 3
|
private String |
term
Value of the term to load - set in the constructor
|
private static int |
TERM
Index of the TERM, set to 4
|
Constructor and Description |
---|
Data(String term)
Builds the Data object and ets the
term for the Data. |
Modifier and Type | Method and Description |
---|---|
CollegeDemographics[] |
getColleges()
Gets the colleges stored in
collegeDemographics . |
String |
getTermFriendlyName()
Takes the numeric name of a term, and returns the friendly name, which
includes the Fall/Spring/Summer and the year.
|
void |
loadData(String filename)
Loads the data into the array objects.
|
void |
printStats()
Deprecated.
This method was replaced by
DemographicDataWriter.writeToScreen(Data) |
private final CollegeDemographics[] collegeDemographics
private final CollegeDemographics[] collegeDemographics = { new CollegeDemographics("NS", "Natural Sciences"), new CollegeDemographics("EG", "Engineering") };
private static final int COLLEGE
private static final int PRIMARY_MAJOR_DESC
private static final int TERM
private static final int GENDER
private final String term
public CollegeDemographics[] getColleges()
collegeDemographics
.
NEW to implement in p4 - remember to add tests to your main for it.
Simply returns the values, so it can be used in other classes.collegeDemographics
public String getTermFriendlyName()
NEW to implement in p4 - remember to add tests to your main for it.
The first four characters are the year, and the 5th character determines the term. 1 == Spring, 6 == Summer, 9 == Fall
Implementation Hints: You can assume a consistent format, so String.substring and String.charAt will be useful. While not required, we used a switch statement, but you can also use an if/else if/elseterm
public void loadData(String filename)
A couple things to consider with implementation
CSVReader.hasNext()
, loop though all the information CSVReader.getNext()
has less than six values, skip.TERM
location in the array returned. Is the value
not equal to term
, then skip it. CollegeDemographics.addGenderDemographic(String, String)
filename
- the name of the file that contains gender demographicsCollegeDemographics.addGenderDemographic(String, String)
,
CSVReader.getNext()
,
CSVReader.hasNext()
public void printStats()
DemographicDataWriter.writeToScreen(Data)
collegeDemographics
, loops through
and prints the CollegeDemographics.getTable()
to the console.
For P4, this method is deprecated, which means it isn't meant to be used. It is common practice to mark methods as deprecated, but not remove them in case other code depends on them.Eventually, after a certain time frame, deprecated methods are removed. The replacement method is actually a near copy of this method, depending on how you wrote it the first time.