/** * 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 citizens; private int numberOfCitizens; /** Creates an instance of a village. There is no cap to the # of villagers. */ public Village() { this(new ArrayList()); } /** * Creates an instance of a village with specific villagers. * * @param citizens the list of citizens in the village */ public Village(List 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())); } }