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.
|
private int femaleCount
private int maleCount
private final String name
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 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