diff options
Diffstat (limited to 'src/Q5/Village.java')
| -rw-r--r-- | src/Q5/Village.java | 36 |
1 files changed, 32 insertions, 4 deletions
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( |
