summaryrefslogtreecommitdiff
path: root/src/Q5/Village.java
blob: abe0d0cc2687beba1d86844e6a5feff342400b15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
 * 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.*;
import java.util.*;

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.
   *
   * @param citizens the list of citizens in the village
   */
  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.
   *
   * @param qualification the qualification for the citizen
   */
  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.
   *
   * @param args the argument vector given to the program.
   */
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    Village village = new Village();
    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(
        String.format("%d citizens have a post graduate degree", intellect.getPostgraduate()));
    System.out.println(
        String.format("%d citizens have a under graduate degree", intellect.getUndergraduate()));
    System.out.println(
        String.format("%d citizens have a high school diploma", intellect.getHighschool()));
  }
}