Commit e5aefc5
Changed files (4)
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;
}
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()) {
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:
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(