public class MajorDemographics
extends Object
Modifier and Type | Field and Description |
---|---|
private int |
femaleCount
Counter for the number of female identifying students in a major.
|
private int |
maleCount
Counter for the number of male identifying students in a major.
|
private String |
name
Name of the major.
|
private int |
nonBinaryCount
Counter for the number of non-binary identifying students in a major.
|
Constructor and Description |
---|
MajorDemographics(String name)
Creates a new MajorDemographics object, setting the
name to name. |
Modifier and Type | Method and Description |
---|---|
void |
addGenderDemographic(String gender)
Increases the various gender demographic counts.
|
String |
getName()
Accessor for the
name for the major |
double[] |
getPercents()
Returns an array of decimal values (less than 1) of the various
major counts.
|
static void |
main(String[] args)
Testing is important, and arguably, as MajorDemographics can be a self contained class
it is very important to test for correctness.
|
String |
toHtmlRow()
Converts the college demographics to an html row (tr) element.
|
private final String name
private int maleCount
private int femaleCount
private int nonBinaryCount
public MajorDemographics(String name)
name
to name.name
- the name of the majorpublic void addGenderDemographic(String gender)
maleCount
is incremented by one.femaleCount
is incremented by one.nonBinaryCount
is incremented by one.gender
- M/F/N as options for being passed into the methodpublic double[] getPercents()
Watch out for accidentally returning all 0s due to integer division. Hint make total a double.
public String toHtmlRow()
NEW to implement in p4 - remember to add tests to your main for it.
This method takes the percents and converts it to the string of format
<tr><td>MALE_PERCENT</td><td>FEMALE_PERCENT</td></tr>
Implementation suggestions
%.2f%%
for the format string getPercents()
was used to get them, to keep the code DRYTag.tr(String)
,
Tag.td(String)
,
getPercents()
public static void main(String[] args)
MajorDemographics major = new MajorDemographics("Basket Weaving"); major.addGenderDemographic("M"); major.addGenderDemographic("F"); major.addGenderDemographic("N"); major.addGenderDemographic(""); System.out.println("TEST: " + Arrays.toString(major.getPercents()));
args
- unused, but included for completeness