master
1/**
2 * Assignment 2, COMP268 Class: Village.java
3 *
4 * @description A village is an aggregate of citizens.
5 * @author: mo khan Student ID: 3431709
6 * @date Jul 13, 2019
7 * @version 1.0
8 */
9package Q5;
10
11import java.io.*;
12import java.util.*;
13
14public class Village {
15 private List<Citizen> citizens;
16 private int numberOfCitizens;
17
18 /** Creates an instance of a village. There is no cap to the # of villagers. */
19 public Village() {
20 this(new ArrayList<Citizen>());
21 }
22
23 /**
24 * Creates an instance of a village with specific villagers.
25 *
26 * @param citizens the list of citizens in the village
27 */
28 public Village(List<Citizen> citizens) {
29 this.citizens = citizens;
30 }
31
32 /** @return the number of citizens in the village. */
33 public int getNumberOfCitizens() {
34 return this.citizens.size();
35 }
36
37 /**
38 * Adds a citizen to the village with a specific qualification.
39 *
40 * @param qualification the qualification for the citizen
41 */
42 public void addCitizen(int qualification) {
43 this.citizens.add(new Citizen(Citizen.generateId(), qualification));
44 }
45
46 /** Adds a citizen to the village with a random qualification. */
47 public void addCitizen() {
48 this.addCitizen(Citizen.generateEducationalQualification());
49 }
50
51 /** @return the array of citizens in the village. */
52 public Citizen[] getCitizens() {
53 return this.citizens.toArray(new Citizen[this.citizens.size()]);
54 }
55
56 /**
57 * The entry point to the console application.
58 *
59 * @param args the argument vector given to the program.
60 */
61 public static void main(String[] args) {
62 Scanner in = new Scanner(System.in);
63 Village village = new Village();
64 for (int i = 0; i < 100; i++) village.addCitizen();
65
66 ComputeIntellect intellect = new ComputeIntellect();
67 intellect.distributionOfQualification(village.getCitizens());
68
69 System.out.println("Welcome to the village");
70 System.out.println(String.format("The village has %d citizens", village.getNumberOfCitizens()));
71 System.out.println(String.format("%d citizens have a doctorate", intellect.getDoctorate()));
72 System.out.println(
73 String.format("%d citizens have a post graduate degree", intellect.getPostgraduate()));
74 System.out.println(
75 String.format("%d citizens have a under graduate degree", intellect.getUndergraduate()));
76 System.out.println(
77 String.format("%d citizens have a high school diploma", intellect.getHighschool()));
78 }
79}