diff options
| author | mo <mo.khan@gmail.com> | 2019-07-13 13:51:47 -0600 |
|---|---|---|
| committer | mo <mo.khan@gmail.com> | 2019-07-13 13:51:47 -0600 |
| commit | e5aefc5e25159ad6f8ce2a08e754b8ed2f5c546f (patch) | |
| tree | 225d72655b75143a6b41f4710dde8d13fa946f3a | |
| parent | e397927ab6cad22c94baff80486dfa98d4f5ddfe (diff) | |
add documentation
| -rw-r--r-- | src/Q5/Citizen.java | 42 | ||||
| -rw-r--r-- | src/Q5/ComputeIntellect.java | 31 | ||||
| -rw-r--r-- | src/Q5/README.md | 12 | ||||
| -rw-r--r-- | src/Q5/Village.java | 36 |
4 files changed, 117 insertions, 4 deletions
diff --git a/src/Q5/Citizen.java b/src/Q5/Citizen.java index 748a848..ab13859 100644 --- a/src/Q5/Citizen.java +++ b/src/Q5/Citizen.java @@ -1,3 +1,11 @@ +/** + * Assignment 2, COMP268 Class: Citizen.java + * + * @description A citizen with an id and educational qualifiation. + * @author: mo khan Student ID: 3431709 + * @date Jul 13, 2019 + * @version 1.0 + */ package Q5; import java.util.*; @@ -11,32 +19,66 @@ public class Citizen { public static final int UNDERGRADUATE = 2; private static int id = 0; + /** + * Creates an instance of a citizen with a specific id. + * + * @param citizenId the identifier for the citizen + */ public Citizen(int citizenId) { this(citizenId, Citizen.generateEducationalQualification()); } + /** + * Creates an instance of a citizen with a specific id and qualification. + * + * @param citizenId the identifier for the citizen + * @param qualification the educational qualification of the citizen + */ public Citizen(int citizenId, int qualification) { this.citizenId = citizenId; this.educationalQualification = qualification; } + /** + * Returns the educational qualification + * + * @return the educational qualfication represented as an integer value. + */ public int getEducationalQualification() { return this.educationalQualification; } + /** + * Generates a random educational qualification. + * + * @return educational qualification. + */ public static int generateEducationalQualification() { return new Random().nextInt(4) + 1; } + /** + * Generates a unique id for a citizen. + * + * @return a new id for a citizen. + */ public static int generateId() { id++; return id; } + /** + * Converts an integer to a string. + * + * @return the converted integer as a string. + */ public static String convert(int i) { return String.valueOf(i); } + /** + * 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 d8a7ee7..0ebf614 100644 --- a/src/Q5/ComputeIntellect.java +++ b/src/Q5/ComputeIntellect.java @@ -1,3 +1,11 @@ +/** + * Assignment 2, COMP268 Class: ComputeIntellect.java + * + * @description A class that can be used to tally the intellect of citizens + * @author: mo khan Student ID: 3431709 + * @date Jul 13, 2019 + * @version 1.0 + */ package Q5; import java.io.*; @@ -9,22 +17,45 @@ public class ComputeIntellect { private int postgraduate = 0; private int undergraduate = 0; + /** + * Returns the total # of citizens with a doctorate. + * + * @return # of citizens with a doctorate + */ public int getDoctorate() { return this.doctorate; } + /** + * Returns the total # of citizens with a high school diploma. + * + * @return # of citizens with a high school diploma. + */ public int getHighschool() { return this.highschool; } + /** + * Returns the total # of citizens with a post graduate degree. + * + * @return # of citizens with a post graduate degree. + */ public int getPostgraduate() { return this.postgraduate; } + /** + * Returns the total # of citizens with an under graduate degree. + * + * @return # of citizens with an under graduate degree. + */ public int getUndergraduate() { return this.undergraduate; } + /** + * Tallys the # of citizens with different educational qualifications. + */ public void distributionOfQualification(Citizen[] citizens) { for (Citizen citizen : citizens) { switch (citizen.getEducationalQualification()) { diff --git a/src/Q5/README.md b/src/Q5/README.md index 2994e5a..e0eb9eb 100644 --- a/src/Q5/README.md +++ b/src/Q5/README.md @@ -31,4 +31,16 @@ the number of citizens corresponding to each of the four educational qualificati 1. Description of the Code: 1. Errors and Warnings: 1. Sample Input and Output: + +```bash +Choose exercise: (1-10) +5 +Welcome to the village +The village has 100 citizens +29 citizens have a doctorate +24 citizens have a post graduate degree +21 citizens have a under graduate degree +26 citizens have a high school diploma +``` + 1. Discussion: diff --git a/src/Q5/Village.java b/src/Q5/Village.java index 4d82c8b..09fc9a9 100644 --- a/src/Q5/Village.java +++ b/src/Q5/Village.java @@ -1,3 +1,11 @@ +/** + * Assignment 2, COMP268 Class: Village.java + * + * @description A village is an aggregate of citizens. + * @author: mo khan Student ID: 3431709 + * @date Jul 13, 2019 + * @version 1.0 + */ package Q5; import java.io.*; @@ -7,41 +15,61 @@ public class Village { private List<Citizen> citizens; private int numberOfCitizens; + /** + * 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. + */ public Village(List<Citizen> citizens) { this.citizens = citizens; } + /** + * @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. + */ public void addCitizen(int qualification) { this.citizens.add(new Citizen(Citizen.generateId(), 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. + */ public Citizen[] getCitizens() { return this.citizens.toArray(new Citizen[this.citizens.size()]); } + /** + * The entry point to the console application. + */ public static void main(String[] args) { Scanner in = new Scanner(System.in); - System.out.println("Welcome to the village"); Village village = new Village(); - for (int i = 0; i < 100; i++) { - village.addCitizen(); - } + for (int i = 0; i < 100; i++) village.addCitizen(); ComputeIntellect intellect = new ComputeIntellect(); intellect.distributionOfQualification(village.getCitizens()); + System.out.println("Welcome to the village"); System.out.println(String.format("The village has %d citizens", village.getNumberOfCitizens())); System.out.println(String.format("%d citizens have a doctorate", intellect.getDoctorate())); System.out.println( |
