diff options
| author | mo <mo.khan@gmail.com> | 2019-07-13 13:55:21 -0600 |
|---|---|---|
| committer | mo <mo.khan@gmail.com> | 2019-07-13 13:55:21 -0600 |
| commit | a76b31a8639190c6e98fefc0e62e42b937501f94 (patch) | |
| tree | 12bd163a8f80cc0cdaa472430a9fb902c08fe411 /src/Q5 | |
| parent | e5aefc5e25159ad6f8ce2a08e754b8ed2f5c546f (diff) | |
add description of the code
Diffstat (limited to 'src/Q5')
| -rw-r--r-- | src/Q5/Citizen.java | 4 | ||||
| -rw-r--r-- | src/Q5/ComputeIntellect.java | 7 | ||||
| -rw-r--r-- | src/Q5/README.md | 5 | ||||
| -rw-r--r-- | src/Q5/Village.java | 29 |
4 files changed, 15 insertions, 30 deletions
diff --git a/src/Q5/Citizen.java b/src/Q5/Citizen.java index ab13859..92b836f 100644 --- a/src/Q5/Citizen.java +++ b/src/Q5/Citizen.java @@ -76,9 +76,7 @@ public class Citizen { return String.valueOf(i); } - /** - * Resets the internal id counter to zero. - */ + /** Resets the internal id counter to zero. */ public static void resetId() { id = 0; } diff --git a/src/Q5/ComputeIntellect.java b/src/Q5/ComputeIntellect.java index 0ebf614..68db941 100644 --- a/src/Q5/ComputeIntellect.java +++ b/src/Q5/ComputeIntellect.java @@ -53,11 +53,9 @@ public class ComputeIntellect { return this.undergraduate; } - /** - * Tallys the # of citizens with different educational qualifications. - */ + /** Tallys the # of citizens with different educational qualifications. */ public void distributionOfQualification(Citizen[] citizens) { - for (Citizen citizen : citizens) { + for (Citizen citizen : citizens) switch (citizen.getEducationalQualification()) { case Citizen.DOCTORATE: this.doctorate++; @@ -72,6 +70,5 @@ public class ComputeIntellect { this.highschool++; break; } - } } } diff --git a/src/Q5/README.md b/src/Q5/README.md index e0eb9eb..4d4fac9 100644 --- a/src/Q5/README.md +++ b/src/Q5/README.md @@ -29,6 +29,11 @@ the number of citizens corresponding to each of the four educational qualificati ``` 1. Description of the Code: + +The code has 3 classes. The entry point into the console application is +in the `Village` class. I chose to store the citizens of the village in +a generic `ArrayList<T>`. + 1. Errors and Warnings: 1. Sample Input and Output: diff --git a/src/Q5/Village.java b/src/Q5/Village.java index 09fc9a9..47c6891 100644 --- a/src/Q5/Village.java +++ b/src/Q5/Village.java @@ -15,52 +15,37 @@ public class Village { private List<Citizen> citizens; private int numberOfCitizens; - /** - * Creates an instance of a village. - * There is no cap to the # of villagers. - */ + /** Creates an instance of a village. There is no cap to the # of villagers. */ public Village() { this(new ArrayList<Citizen>()); } - /** - * Creates an instance of a village with specific villagers. - */ + /** Creates an instance of a village with specific villagers. */ public Village(List<Citizen> citizens) { this.citizens = citizens; } - /** - * @return the number of citizens in the village. - */ + /** @return the number of citizens in the village. */ public int getNumberOfCitizens() { return this.citizens.size(); } - /** - * Adds a citizen to the village with a specific qualification. - */ + /** Adds a citizen to the village with a specific qualification. */ public void addCitizen(int qualification) { this.citizens.add(new Citizen(Citizen.generateId(), qualification)); } - /** - * Adds a citizen to the village with a random qualification. - */ + /** Adds a citizen to the village with a random qualification. */ public void addCitizen() { this.addCitizen(Citizen.generateEducationalQualification()); } - /** - * @return the array of citizens in the village. - */ + /** @return the array of citizens in the village. */ public Citizen[] getCitizens() { return this.citizens.toArray(new Citizen[this.citizens.size()]); } - /** - * The entry point to the console application. - */ + /** The entry point to the console application. */ public static void main(String[] args) { Scanner in = new Scanner(System.in); Village village = new Village(); |
