├── Main.java ├── Main.txt ├── Object_Candidate.java ├── Object_Voter.java ├── README.md ├── Voting.java ├── files ├── candidate.txt └── voterLogs.txt └── other ├── planDesign.drawio └── problem.txt /Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) throws Exception { 6 | 7 | Scanner in = new Scanner(System.in); 8 | Voting v = new Voting(); 9 | String input; 10 | 11 | while (true) { 12 | v.Menu(); 13 | input = in.nextLine(); 14 | 15 | if (input.equals("1")) 16 | v.PrintAllCandidates(); 17 | 18 | if (input.equals("2")) 19 | v.Vote(); 20 | 21 | if (input.equals("3")) { 22 | System.out.println("\nCandidacy Form"); 23 | 24 | } 25 | 26 | if (input.equals("4")) { 27 | System.out.println("\nVoting Logs"); 28 | } 29 | 30 | if (input.equals("5")) { 31 | System.out.println("\nFinal Result"); 32 | } 33 | 34 | if (input.equals("6")) 35 | v.LoadData(); 36 | 37 | if (input.equals("7")) 38 | v.ClearAll(); 39 | 40 | if (input.equals("8")) 41 | break; 42 | } 43 | v.CloseAll(); 44 | in.close(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Main.txt: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Collections; 3 | import java.util.Comparator; 4 | import java.util.Scanner; 5 | import java.io.File; 6 | 7 | public class Main { 8 | 9 | private ArrayList presList = new ArrayList<>(); 10 | private ArrayList vpList = new ArrayList<>(); 11 | private ArrayList senList = new ArrayList<>(); 12 | private ArrayList voter = new ArrayList<>(); 13 | private Scanner scan; 14 | private String firstName, lastName, initial = "", suffix = "", politicalParty, educationalBackground, 15 | chosenPosition, 16 | crimeRecord, votedPres, votedVp, votedSenate[] = new String[12]; 17 | private int input, age, dPres, dVp, dSen; 18 | 19 | void Menu() { 20 | scan = new Scanner(System.in); 21 | System.out.println("\nOOP Project 1 : Voting System\n"); 22 | System.out.println("1 - Show All Candidates"); 23 | System.out.println("2 - Vote Candidates"); 24 | System.out.println("3 - Fill a Candidacy"); 25 | System.out.println("4 - Show Voting Logs"); 26 | System.out.println("5 - Show Final Result"); 27 | System.out.println("6 - Load Existing Value"); 28 | System.out.println("7 - Clear Data"); 29 | System.out.println("8 - Exit"); 30 | System.out.print("\nOption: "); 31 | input = scan.nextInt(); 32 | // try 33 | } 34 | 35 | void Sort(ArrayList list) { 36 | if (list.size() == 0) 37 | return; 38 | Collections.sort(list, new Comparator() { 39 | public int compare(Object_Candidate c1, Object_Candidate c2) { 40 | return c1.getLastName().compareTo(c2.getLastName()); 41 | } 42 | }); 43 | } 44 | 45 | void LoadData() throws Exception { 46 | File file = new File("files/candidate.txt"); 47 | scan = new Scanner(file); 48 | while (scan.hasNextLine()) { 49 | scan.findInLine(": "); 50 | lastName = scan.nextLine(); 51 | 52 | scan.findInLine(": "); 53 | firstName = scan.nextLine(); 54 | 55 | scan.findInLine(": "); 56 | initial = scan.nextLine(); 57 | 58 | scan.findInLine(": "); 59 | suffix = scan.nextLine(); 60 | if (suffix.equalsIgnoreCase("Suffix:")) 61 | suffix = ""; 62 | 63 | scan.findInLine(": "); 64 | politicalParty = scan.nextLine(); 65 | 66 | scan.findInLine(": "); 67 | educationalBackground = scan.nextLine(); 68 | 69 | scan.findInLine(": "); 70 | chosenPosition = scan.nextLine(); 71 | 72 | scan.findInLine(": "); 73 | crimeRecord = scan.nextLine(); 74 | scan.nextLine(); 75 | 76 | if (chosenPosition.equalsIgnoreCase("President")) { 77 | presList.add(new Object_Candidate(firstName, lastName, initial, suffix, politicalParty, 78 | educationalBackground, chosenPosition, crimeRecord)); 79 | } 80 | if (chosenPosition.equalsIgnoreCase("Vice-President")) 81 | vpList.add(new Object_Candidate(firstName, lastName, initial, suffix, politicalParty, 82 | educationalBackground, chosenPosition, crimeRecord)); 83 | if (chosenPosition.equalsIgnoreCase("Senator")) 84 | senList.add(new Object_Candidate(firstName, lastName, initial, suffix, politicalParty, 85 | educationalBackground, chosenPosition, crimeRecord)); 86 | } 87 | Sort(presList); 88 | Sort(vpList); 89 | Sort(senList); 90 | System.out.println("Note: The Data is now Loaded, Ready for Voting."); 91 | } 92 | 93 | // Printing 94 | void GetFullName(Object_Candidate data) { 95 | System.out.println(data.getLastName() + ", " + data.getFirstName() + " " + data.getInitial() + " " 96 | + data.getSuffix()); 97 | } 98 | 99 | void GetFullNameQualified(Object_Candidate data) { 100 | 101 | if (!data.getCrimeRecord().equalsIgnoreCase("None")) 102 | return; 103 | 104 | System.out.println(data.getLastName() + ", " + data.getFirstName() + " " + data.getInitial() + " " 105 | + data.getSuffix()); 106 | 107 | } 108 | 109 | void GetFullNameUnqualified(Object_Candidate data) { 110 | 111 | if (data.getCrimeRecord().equalsIgnoreCase("None")) 112 | return; 113 | 114 | System.out.println(data.getLastName() + ", " + data.getFirstName() + " " + data.getInitial() + " " 115 | + data.getSuffix()); 116 | System.out.println("Cause of Disqualification: " + data.getCrimeRecord()); 117 | 118 | } 119 | 120 | void PrintAllCandidatePresident() { 121 | if (presList.size() == 0) { 122 | System.out.println("Note: No available candidate for President."); 123 | return; 124 | } 125 | System.out.println("\n*For President*"); 126 | for (Object_Candidate data : presList) 127 | GetFullName(data); 128 | } 129 | 130 | void PrintAllQualifiedPresident() { 131 | if (presList.size() == 0) { 132 | System.out.println("Note: No available candidate for President."); 133 | return; 134 | } 135 | System.out.println("\n*Qualified President*"); 136 | for (int i = 0; i < presList.size(); i++) { 137 | GetFullNameQualified(presList.get(i)); 138 | } 139 | } 140 | 141 | void PrintAllUnqualifiedPresident() { 142 | if (presList.size() == 0) { 143 | System.out.println("Note: No available candidate for President."); 144 | return; 145 | } 146 | System.out.println("\n*Disqualified President*"); 147 | for (int i = 0; i < presList.size(); i++) { 148 | GetFullNameUnqualified(presList.get(i)); 149 | } 150 | } 151 | 152 | void PrintAllCandidateVPresident() { 153 | if (vpList.size() == 0) { 154 | System.out.println("Note: No available candidate for Vice-President."); 155 | return; 156 | } 157 | System.out.println("\n*For Vice-President*"); 158 | for (Object_Candidate data : vpList) 159 | GetFullName(data); 160 | } 161 | 162 | void PrintAllCandidateSenator() { 163 | if (senList.size() == 0) { 164 | System.out.println("Note: No available candidate for Senator."); 165 | return; 166 | } 167 | System.out.println("\n*For Senator*"); 168 | for (Object_Candidate data : senList) 169 | GetFullName(data); 170 | } 171 | 172 | void PrintAllCandidates() { 173 | System.out.println("\nAll Candidate"); 174 | PrintAllCandidatePresident(); 175 | PrintAllCandidateVPresident(); 176 | PrintAllCandidateSenator(); 177 | } 178 | 179 | void PrintAllQualifiedCandidates() { 180 | System.out.println("\nAll Qualified Candidate"); 181 | PrintAllQualifiedPresident(); 182 | } 183 | 184 | void PrintAllUnqualifiedCandidates() { 185 | System.out.println("\nAll Unqualified Candidate"); 186 | PrintAllUnqualifiedPresident(); 187 | } 188 | 189 | void Main() throws Exception { 190 | 191 | scan = new Scanner(System.in); 192 | 193 | LoadData(); 194 | PrintAllCandidates(); 195 | PrintAllQualifiedCandidates(); 196 | PrintAllUnqualifiedCandidates(); 197 | 198 | scan.close(); 199 | // System.out.println("\n1- Disqualified Candidates | 2 - Qualified Candidates | 200 | // 3 - Main Menu"); 201 | /* 202 | * 203 | * ArrayList candidate = new ArrayList<>(); 204 | * ArrayList voter = new ArrayList<>(); 205 | * Scanner sc, in = new Scanner(System.in); 206 | * 207 | * String firstName, lastName, initial = "", suffix = "", politicalParty, 208 | * educationalBackground, chosenPosition, 209 | * crimeRecord, votedPres, votedVp, votedSenate[] = new String[12]; 210 | * int input, age; 211 | * 212 | * while (true) { 213 | * System.out.println("\nOOP Project 1 : Voting System\n"); 214 | * System.out.println("1 - Show All Candidates"); 215 | * System.out.println("2 - Vote Candidates"); 216 | * System.out.println("3 - Fill a Candidacy"); 217 | * System.out.println("4 - Show Voting Logs"); 218 | * System.out.println("5 - Show Final Result"); 219 | * System.out.println("6 - Load Existing Value"); 220 | * System.out.println("7 - Clear Data"); 221 | * System.out.println("8 - Exit"); 222 | * System.out.print("\nOption: "); 223 | * input = in.nextInt(); 224 | * 225 | * if (input == 1) { 226 | * if (candidate.size() == 0) { 227 | * System.out.println("Note: No data loaded."); 228 | * } else { 229 | * System.out.println("\nAll Candidate\n"); 230 | * System.out.println("=For President="); 231 | * for (Object_Candidate data : candidate) { 232 | * if (data.getChosenPosition().equalsIgnoreCase("President")) 233 | * System.out.println(data + "\n"); 234 | * } 235 | * System.out.println("=For Vice-President="); 236 | * for (Object_Candidate data : candidate) { 237 | * if (data.getChosenPosition().equalsIgnoreCase("Vice-President")) 238 | * System.out.println(data + "\n"); 239 | * } 240 | * System.out.println("=For Senator="); 241 | * for (Object_Candidate data : candidate) { 242 | * if (data.getChosenPosition().equalsIgnoreCase("Senator")) 243 | * System.out.println(data + "\n"); 244 | * } 245 | * } 246 | * } 247 | * 248 | * if (input == 2) { 249 | * if (candidate.size() == 0) { 250 | * System.out. 251 | * println("No Candidate to Vote, Please load or Fill a candidacy form."); 252 | * } else { 253 | * System.out.println("\nVote Candidates"); 254 | * 255 | * System.out.print("Enter Age: "); 256 | * age = in.nextInt(); 257 | * 258 | * if (age <= 17) { 259 | * System.out.println("Invalid"); 260 | * } else { 261 | * System.out.print("Enter First Name: "); 262 | * firstName = in.nextLine(); 263 | * System.out.print("Enter Last Name: "); 264 | * lastName = in.nextLine(); 265 | * System.out.print("Enter Initial (press enter if none): "); 266 | * initial = in.nextLine(); 267 | * System.out.print("Enter Suffix (press enter if none): "); 268 | * suffix = in.nextLine(); 269 | * 270 | * System.out.print("Enter President of Choice: "); 271 | * votedPres = in.nextLine(); 272 | * 273 | * System.out.print("Enter Vice President of Choice: "); 274 | * votedVp = in.nextLine(); 275 | * 276 | * votedSenate[0] = "Pres1"; 277 | * votedSenate[1] = "Pres2"; 278 | * votedSenate[2] = "Pres3"; 279 | * 280 | * voter.add(new Object_Voter(firstName, lastName, initial, suffix, age, 281 | * votedPres, votedVp, 282 | * votedSenate)); 283 | * 284 | * } 285 | * } 286 | * } 287 | * 288 | * if (input == 3) { 289 | * System.out.println("\nCandidacy Form"); 290 | * 291 | * } 292 | * 293 | * if (input == 4) { 294 | * System.out.println("\nVoting Logs"); 295 | * } 296 | * 297 | * if (input == 5) { 298 | * System.out.println("\nFinal Result"); 299 | * } 300 | * 301 | * if (input == 6) { 302 | * File file = new File("files/candidate.txt"); 303 | * sc = new Scanner(file); 304 | * while (sc.hasNextLine()) { 305 | * sc.findInLine(": "); 306 | * firstName = sc.nextLine(); 307 | * 308 | * sc.findInLine(": "); 309 | * lastName = sc.nextLine(); 310 | * 311 | * sc.findInLine(": "); 312 | * initial = sc.nextLine(); 313 | * 314 | * sc.findInLine(": "); 315 | * suffix = sc.nextLine(); 316 | * if (suffix.equalsIgnoreCase("Suffix:")) 317 | * suffix = ""; 318 | * 319 | * sc.findInLine(": "); 320 | * politicalParty = sc.nextLine(); 321 | * 322 | * sc.findInLine(": "); 323 | * educationalBackground = sc.nextLine(); 324 | * 325 | * sc.findInLine(": "); 326 | * chosenPosition = sc.nextLine(); 327 | * 328 | * sc.findInLine(": "); 329 | * crimeRecord = sc.nextLine(); 330 | * sc.nextLine(); 331 | * 332 | * candidate.add(new Object_Candidate(firstName, lastName, initial, suffix, 333 | * politicalParty, 334 | * educationalBackground, chosenPosition, crimeRecord)); 335 | * } 336 | * System.out.println("Note: The Data is now Loaded, Ready for Voting."); 337 | * } 338 | * 339 | * if (input == 7) { 340 | * candidate.clear(); 341 | * voter.clear(); 342 | * System.out.println("Note: Data is now Clear."); 343 | * } 344 | * 345 | * if (input == 8) { 346 | * System.out.println("\nThank you for using the program."); 347 | * break; 348 | * } 349 | * } 350 | * in.close(); 351 | */ 352 | } 353 | 354 | } -------------------------------------------------------------------------------- /Object_Candidate.java: -------------------------------------------------------------------------------- 1 | public class Object_Candidate { 2 | 3 | private String lastName, firstName, initial, suffix, politicalParty, educationalBackground, chosenPosition, 4 | crimeRecord, isQualified; 5 | 6 | public Object_Candidate(String lastName, String firstName, String initial, String suffix, String politicalParty, 7 | String educationalBackground, String chosenPosition, String crimeRecord, String isQualified) { 8 | this.setFirstName(firstName); 9 | this.setLastName(lastName); 10 | this.setInitial(initial); 11 | this.setSuffix(suffix); 12 | this.setPoliticalParty(politicalParty); 13 | this.setEducationalBackground(educationalBackground); 14 | this.setChosenPosition(chosenPosition); 15 | this.setCrimeRecord(crimeRecord); 16 | this.setIsQualified(isQualified); 17 | } 18 | 19 | public String getLastName() { 20 | return lastName; 21 | } 22 | 23 | private void setLastName(String lastName) { 24 | this.lastName = lastName; 25 | } 26 | 27 | public String getFirstName() { 28 | return firstName; 29 | } 30 | 31 | private void setFirstName(String firstName) { 32 | this.firstName = firstName; 33 | } 34 | 35 | public String getInitial() { 36 | return initial; 37 | } 38 | 39 | private void setInitial(String initial) { 40 | this.initial = initial; 41 | } 42 | 43 | public String getSuffix() { 44 | return suffix; 45 | } 46 | 47 | private void setSuffix(String suffix) { 48 | this.suffix = suffix; 49 | } 50 | 51 | public String getPoliticalParty() { 52 | return politicalParty; 53 | } 54 | 55 | private void setPoliticalParty(String politicalParty) { 56 | this.politicalParty = politicalParty; 57 | } 58 | 59 | public String getEducationalBackground() { 60 | return educationalBackground; 61 | } 62 | 63 | private void setEducationalBackground(String educationalBackground) { 64 | this.educationalBackground = educationalBackground; 65 | } 66 | 67 | public String getChosenPosition() { 68 | return chosenPosition; 69 | } 70 | 71 | private void setChosenPosition(String chosenPosition) { 72 | this.chosenPosition = chosenPosition; 73 | } 74 | 75 | public String getCrimeRecord() { 76 | return crimeRecord; 77 | } 78 | 79 | private void setCrimeRecord(String crimeRecord) { 80 | this.crimeRecord = crimeRecord; 81 | } 82 | 83 | public String getIsQualified() { 84 | return isQualified; 85 | } 86 | 87 | public void setIsQualified(String isQualified) { 88 | this.isQualified = isQualified; 89 | } 90 | 91 | @Override 92 | public String toString() { 93 | return String.format( 94 | "Full Name: %s, %s %s %s\nPolitical Party: %s\nEducational Background: %s\nRunning for: %s\nCriminal Record: %s", 95 | this.getLastName(), this.getFirstName(), this.getInitial(), 96 | this.getSuffix(), this.getPoliticalParty(), this.getEducationalBackground(), this.getChosenPosition(), 97 | this.getCrimeRecord()); 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /Object_Voter.java: -------------------------------------------------------------------------------- 1 | public class Object_Voter { 2 | 3 | private String lastName, firstName, initial, suffix, age, votedPres, votedVp, votedSenate[] = new String[12]; 4 | 5 | public Object_Voter(String lastName, String firstName, String initial, String suffix, String age, String votedPres, 6 | String votedVp, String[] votedSenate) { 7 | this.setLastName(lastName); 8 | this.setFirstName(firstName); 9 | this.setInitial(initial); 10 | this.setSuffix(suffix); 11 | this.setAge(age); 12 | this.setVotedPres(votedPres); 13 | this.setVotedVp(votedVp); 14 | this.setVotedSenate(votedSenate); 15 | } 16 | 17 | public String getLastName() { 18 | return lastName; 19 | } 20 | 21 | private void setLastName(String lastName) { 22 | this.lastName = lastName; 23 | } 24 | 25 | public String getFirstName() { 26 | return firstName; 27 | } 28 | 29 | private void setFirstName(String firstName) { 30 | this.firstName = firstName; 31 | } 32 | 33 | public String getInitial() { 34 | return initial; 35 | } 36 | 37 | private void setInitial(String initial) { 38 | this.initial = initial; 39 | } 40 | 41 | public String getSuffix() { 42 | return suffix; 43 | } 44 | 45 | private void setSuffix(String suffix) { 46 | this.suffix = suffix; 47 | } 48 | 49 | public String getAge() { 50 | return age; 51 | } 52 | 53 | private void setAge(String age) { 54 | this.age = age; 55 | } 56 | 57 | public String getVotedPres() { 58 | return votedPres; 59 | } 60 | 61 | private void setVotedPres(String votedPres) { 62 | if (votedPres != "") 63 | this.votedPres = votedPres; 64 | this.votedPres = "0"; 65 | } 66 | 67 | public String getVotedVp() { 68 | return votedVp; 69 | } 70 | 71 | private void setVotedVp(String votedVp) { 72 | if (votedVp != "") 73 | this.votedVp = votedVp; 74 | this.votedVp = "0"; 75 | } 76 | 77 | public String[] getVotedSenate() { 78 | return votedSenate; 79 | } 80 | 81 | public void setVotedSenate(String[] votedSenate) { 82 | this.votedSenate = votedSenate; 83 | } 84 | 85 | String senateList(String votedSenate[]) { 86 | String list = ""; 87 | for (String data : votedSenate) { 88 | if (data != null) 89 | list += "\n\t\t " + data; 90 | } 91 | return list; 92 | } 93 | 94 | @Override 95 | public String toString() { 96 | return String.format( 97 | "Full Name: %s, %s %s %s\nChosen President: %s\nChosen Vice-President: %s\nChosen Senators: %s", 98 | this.getLastName(), this.getFirstName(), this.getInitial(), 99 | this.getSuffix(), this.getVotedPres(), this.getVotedVp(), senateList(this.getVotedSenate())); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ⭐️ **My Template** ⭐️ 2 | 3 | Follow Up Text 4 | 5 |
6 | 7 | --- 8 | 9 |
10 | 11 | ![Logo](https://static.vecteezy.com/system/resources/previews/000/371/208/original/vector-welcome-hand-drawn-text.jpg) 12 | 13 | ## Contributors 14 | 15 | - [Joemar Cardiño](https://github.com/joemar25 "Joemar's Github") 👋🏻 16 | 17 | ## Tables of Contents 18 | 19 | 1. [The Program's Behaviour and Feature](#the-programs-behaviour-and-features) 20 | 2. [Actual Test Run](#test-run) 21 | 3. [Actual Output](#the-output) 22 | 4. [What are the Problems we encountered?](#problems-encuntered) 23 | 5. [How did we solve those problems?](#solving-problems) 24 | 6. [What do we use and the implementations](#the-program) 25 | 7. [Sorting Algorithms](#sorting-algorithms) 26 | 8. [Analysis](#analysis) 27 | 9. [References Used](#references) 28 | 29 |
30 | 31 | --- 32 | 33 |
34 | 35 | ## The Program's Behaviour and Features 36 | 37 | 1. User is asked for `N` values. 38 | 39 | 2. Generates `N` integers which are either Randomly and Sorted (in increasing order). 40 | 41 | 3. Sorts the values using different Algorithms. 42 | 43 | 4. Output a file containing the `T(n)` that spends on using the different algorithms for sorting and the generated 'N' integers (original and sorted). 44 | 45 | 5. The sorting algorithms are implemented on different functions. 46 | 47 | 6. Use `#include ` header to use `clock()` function on helping us to calculate the T(n). 48 | 49 | 7. Note: `#include ` for C, is the same as `#include ` in C++. 50 | 51 | 🤍 ~ `Extra` ~ 🤍 52 | 53 | 8. The user has the choice if he/she wants to use randomly generated values or the sorted increasing order at the start of the program - So there is no need for the user to modify the code to alter the results. 54 | 55 | 9. Input checker `if (num <= 0)`, prevent errors and checks if it exceeds the MAXIMUM VALUE. 56 | 57 | 10. Uses only the standard functions to work on multiple platforms. 58 | 59 | > Programming Language used: `C++`. 60 | 61 |
62 | 63 | --- 64 | 65 |
66 | 67 | ## Test Run 68 | 69 | Below is the test run (Restrictions) for inputs on selecting if the user wants to use array that are randomly initialized or sorted initialized. 70 | 71 | https://user-images.githubusercontent.com/80235976/163752931-ad70ead9-d20c-4cee-9f40-03089bde1c99.mp4 72 | 73 | Below is the test run for all values that are need to analyze if the array has random values. 74 | 75 | https://user-images.githubusercontent.com/80235976/163754897-e695b4e3-d93b-4b13-8c7e-02823d4eb5d5.mp4 76 | 77 | Below is the test run for all values that are need to analyze if the array has sorted values. 78 | 79 | https://user-images.githubusercontent.com/80235976/163755648-ab8ad641-82f3-48f7-af49-db33c375e6be.mp4 80 | 81 |
82 | 83 | > Note: Video file uploading size in README.md must be below 10mb. So, we apologize for the quality. 84 | 85 |
86 | 87 | --- 88 | 89 |
90 | 91 | ## The Output 92 | 93 | ##### _NEED TO OUTPUT_ 94 | 95 | - original and sorted values 96 | - computation time T(N) for sorting N integers (not the time spent by user inputing) 97 | 98 |
99 | 100 | Randomize Initialized Array Values 101 | 102 | > Using N = 100000 103 | 104 | ![RANDOMIZE](https://user-images.githubusercontent.com/80235976/163756226-42a76de3-d5e7-4dc5-91ff-05cddc2d5710.PNG) 105 | 106 |
107 | 108 | Sorted Initialized Array Values 109 | 110 | > Using N = 100000 and X = 7 111 | 112 | ![ALREADY SORTED](https://user-images.githubusercontent.com/80235976/163756230-ceeb10d5-1007-4a54-aeb1-6f93bde0afa8.PNG) 113 | 114 |
115 | 116 | Using the default text editor for Windows is a pain since it generates a lot of unnecessary characters - mainly Chinese keywords instead of numbers. This always happened in `[Sorted Generated Values]` when N is equals to 10000. As a group, we have solved this. At first, we use the typical `.txt` as output. But that does not change the old output for other Copmuters. We have tested `.out` and it works fine but still generated Chinese keywords for other Computers. While attempting to resolve the issue, we discovered that the output is fine when the value of x is greater. As a result, we conducted a trial and error to find the smallest value of X that will provide acceptable results. The value of X should be 41 and higher. 117 | 118 | `[Sorted Generated Values]` For Joemar, it was fine (both runtime and seeing the results) but for Paolo and Adrian after using the program (is ok) - but after cheking the result to a notepad viewer they observed a lot of generated Chinese Characters instead of the array value. 119 | 120 | `[Random Generated Values]` works properly as it had not generated a single problem for us. 121 | 122 | `In conclusion:` It is highly suggested to use other text viewers to view the results incase the generated arrays are unreadable or in Chinese Characters. (VS code, DevC++, MS Word...) 123 | 124 |
125 | 126 | --- 127 | 128 |
129 | 130 | ## Problems Encountered 131 | 132 | 1. Too many T(n) values yielded zeroes for set values of N when using the clock() when getting processor times. 133 | 2. Group member availability. 134 | 3. Sorted initializations, specifically with N values of 10000 would produce outputs that displayed Chinese characters when opened in Notepad. This behavior is only present with Notepad, other text viewers properly show the intended output of the program. 135 | 136 | ## Solving Problems 137 | 138 | - Making a function to lessen or remove the loop in our main function (_see: [The Program : String Function](#the-program)_). 139 | 140 | - Using constant (`const data_type var_name`) to make variable unchangable during the function call is a handy way to secure the data that we need to handle. 141 | 142 | - Using reference (`data_type &var_name`) instead of typical pass by value to a function, making sure that we only have one variable declaration instead of making another copy of that variable. 143 | 144 | - `Getting The sorted values` 145 | 146 | ``` 147 | (TEST) 148 | N = 3 149 | X = 6 150 | 151 | NOTE: N + (2)X = N + (2 * X) 152 | our program will use N + ((i + 1) * X) 153 | 154 | let i = 0 155 | array[0] = N+(1)X => 3+(i+1)6 => 3+( (0 + 1) * 6) => 3+( 1 * 6) = 9 156 | array[1] = N+(2)X => 3+(i+1)6 => 3+( (1 + 1) * 6) => 3+( 2 * 6) = 15 157 | array[2] = N+(3)X => 3+(i+1)6 => 3+( (2 + 1) * 6) => 3+( 3 * 6) = 21 158 | 159 | array values = 8, 13, 18 160 | ``` 161 | 162 |
163 | 164 | --- 165 | 166 |
167 | 168 | ## The Program 169 | 170 | The Array Used 171 | 172 | > As programmers, we need to efficiently manage and manipulate the computer's memory. 173 | 174 | > So we have to take advantage of dynamic memory allocation using C++. 175 | 176 | > “In dynamic memory allocation, memory is allocated during runtime. But, in this case, it is the responsibility of a programmer to deallocate the dynamically allocated memory when it’s no longer in use. Otherwise, it leads to memory leaks.” 177 | 178 | > In the given problem, we are tasked to ask the user to get input in which we need to adjust the size of the array. “We do not know in advance the amount of memory required to store some data.” So, Dynamic allocation is the solution for that. 179 | 180 | ```c++ 181 | int *array = NULL; 182 | array = new int[N]; 183 | ``` 184 | 185 |
186 | 187 | For the include files used by the program. 188 | 189 | ```c++ 190 | #include 191 | #include 192 | #include 193 | #include 194 | #include 195 | #include 196 | #define MAXRANGE 1000000 197 | ``` 198 | 199 | > ``helps us to use cout and cin (basically we need it, for us to input and output something.) 200 | 201 | > `` helps us to use several general-purpose functions that are defined in this header, including dynamic memory management, random number generation, communication with the environment, integer arithmetic, searching, sorting, and converting. 202 | 203 | > `` helps us to use string in our code 204 | 205 | > `` helps us to use sstream, which is an object that was declared to perform the input/output operations on strings _(we use this to convert the integer to a string for us to easily output them without using repeated loops in our main._ 206 | 207 | > `` helps us to use File, to output/write to files. 208 | 209 | > `` helps us to use 210 | 211 | > `MAXRANGE 1000000` is used as a default value for the maximum range 212 | 213 |
214 | 215 | For printing the array values without using a lot of for-loops in the main function, we have used the function below: 216 | 217 | ```c++ 218 | std::string GetArray(const int *ARRAY, const int &N) 219 | { 220 | std::stringstream stream; 221 | std::string stored_value = ""; 222 | std::string temp; 223 | 224 | for (int i = 0; i < N; i++) 225 | { 226 | stream << ARRAY[i]; 227 | stream >> temp; 228 | stored_value += " " + temp; 229 | stream.clear(); 230 | } 231 | return stored_value; 232 | } 233 | ``` 234 | 235 | > Above It uses both `sstream` and `cstring`. 236 | 237 | ```c++ 238 | #include 239 | #include 240 | ``` 241 | 242 | > The string stream associates a string object with a string. Using this we can read from string as if it were a stream like cin. As said, we use this to perform a convertion from integer to string. Why? we want to lessen the loop inside the main function. 243 | 244 |
245 | 246 | For Getting the input, we have again used the function. 247 | 248 | ```c++ 249 | void Input(int *num, const char var_initial) 250 | { 251 | int num_in = 0; 252 | while (!(num_in > 0 && num_in <= MAXRANGE)) 253 | { 254 | printf("Input value for %c: ", var_initial); 255 | std::cin >> num_in; 256 | if (num_in < 1 || num_in > MAXRANGE) 257 | printf("Invalid value for %c. Please Try Again.\n\n", var_initial); 258 | } 259 | *num = num_in; 260 | } 261 | ``` 262 | 263 | > First, we will needing the memory address of the number from the main function, and determmine whether it is for `N` or `X`. This is a good implementation for us since again, _We have a goal to lessen or remove all the loop inside our main function_. 264 | 265 | > This limits the users from entering wrong inputs. That is why we have included this in our program. 266 | 267 | > Why is it the var initial does not use `&var_initial`? it is because throught the program we will use this function 2 times. It is one of the rules of references to referece only one variable, so in respect for the rule, we only use constant - for the data to be unmodified. 268 | 269 |
270 | 271 | For Randomize Initialization of values for arrays. 272 | 273 | ```c++ 274 | void RandomizeInitialization(int *ARRAY, const int &N) 275 | { 276 | srand(time(NULL)); 277 | for (int i = 0; i < N; i++) 278 | ARRAY[i] = (rand() % MAXRANGE); 279 | } 280 | ``` 281 | 282 | > If random numbers are generated with rand() without first calling srand(), your program will create the same sequence of numbers each time it runs. 283 | 284 | > If statement does not contain srand set to time(0) or srand set to time(NULL), then running the program again and again will result to same random numbers. Else each execution of the program will have different random results that will be set as array values. 285 | 286 |
287 | 288 | For Sorted Initialization of values for arrays. 289 | 290 | ```c++ 291 | void SortedInitialization(int *ARRAY, const int &N, const int &X) 292 | { 293 | for (int i = 0; i < N; i++) 294 | ARRAY[i] = N + ((i + 1) * X); 295 | } 296 | ``` 297 | 298 | > (_see: [Solving the problem : Getting The sorted values](#solving-problems)_). 299 | 300 |
301 | 302 | For a convinient way to copy array to another array. 303 | 304 | ```c++ 305 | void Copy(int *ORIGINAL_COPY, int *HOLDER, const int &N, const int &option) 306 | { 307 | if (option != 1) 308 | return; 309 | for (int i = 0; i < N; i++) 310 | HOLDER[i] = ORIGINAL_COPY[i]; 311 | } 312 | ``` 313 | 314 | > The function gets two sets of array, and depending on the constant references option - the loop will copy the array to another or not. This keep the memory usage less and more effiencient than. Randoming again and again if the user chooses to have a randomize values for the array. 315 | 316 |
317 | 318 | --- 319 | 320 |
321 | 322 | ## Sorting Algorithms 323 | 324 | > Insertion Sort: 325 | 326 | It uses the functions below to use the sorting method for Insertion Sort. 327 | 328 | ```c++ 329 | void InsertionSort(int *ARRAY, const int &length) 330 | { 331 | for (int i = 1; i < length; i++) 332 | { 333 | int key = ARRAY[i], j = i; 334 | while (j > 0 && ARRAY[j - 1] > key) 335 | { 336 | ARRAY[j] = ARRAY[j - 1]; 337 | j--; 338 | } 339 | ARRAY[j] = key; 340 | } 341 | } 342 | ``` 343 | 344 | > Merge Sort: 345 | 346 | It uses the functions below to use the sorting method for Merge Sort. 347 | 348 | ```c++ 349 | void Merge(int *ARRAY, const int lower, const int middle, const int upper) 350 | { 351 | int i, j, k; 352 | int left[middle - lower + 1]; 353 | int right[upper - middle]; 354 | 355 | for (i = 0; i < middle - lower + 1; i++) 356 | left[i] = ARRAY[lower + i]; 357 | for (j = 0; j < upper - middle; j++) 358 | right[j] = ARRAY[middle + 1 + j]; 359 | 360 | i = 0; 361 | j = 0; 362 | k = lower; 363 | 364 | for (k = lower; i < middle - lower + 1 && j < upper - middle; k++) 365 | { 366 | if (left[i] <= right[j]) 367 | ARRAY[k] = left[i++]; 368 | else 369 | ARRAY[k] = right[j++]; 370 | } 371 | 372 | while (i < middle - lower + 1) 373 | ARRAY[k++] = left[i++]; 374 | while (j < upper - middle) 375 | ARRAY[k++] = right[j++]; 376 | } 377 | 378 | void MergeSort(int *ARRAY, const int lower, const int upper) 379 | { 380 | if (lower >= upper) 381 | return; 382 | MergeSort(ARRAY, lower, (lower + upper) / 2); 383 | MergeSort(ARRAY, ((lower + upper) / 2) + 1, upper); 384 | Merge(ARRAY, lower, (lower + upper) / 2, upper); 385 | } 386 | ``` 387 | 388 | > Both Quick and Heap sort uses this function for swapping. 389 | 390 | ```c++ 391 | void Swap(int *a, int *b) 392 | { 393 | int temp = *b; 394 | *b = *a; 395 | *a = temp; 396 | } 397 | ``` 398 | 399 | > Quick Sort: 400 | > It uses the functions below to use the sorting method for Quick Sort. 401 | 402 | ```c++ 403 | int Partition(int *ARRAY, const int low, const int high) 404 | { 405 | int index = low, pivot = high; 406 | for (int i = low; i < high; i++) 407 | { 408 | if (ARRAY[i] < ARRAY[pivot]) 409 | { 410 | Swap(&ARRAY[i], &ARRAY[index]); 411 | index++; 412 | } 413 | } 414 | Swap(&ARRAY[pivot], &ARRAY[index]); 415 | return index; 416 | } 417 | 418 | int RandomPivotPartition(int *ARRAY, const int low, const int high) 419 | { 420 | int pvt = low + rand() % (high - low + 1); 421 | Swap(&ARRAY[high], &ARRAY[pvt]); 422 | return Partition(ARRAY, low, high); 423 | } 424 | 425 | void QuickSort(int *ARRAY, const int low, const int high) 426 | { 427 | if (low < high) 428 | { 429 | int pivotIndex = RandomPivotPartition(ARRAY, low, high); 430 | QuickSort(ARRAY, low, pivotIndex - 1); 431 | QuickSort(ARRAY, pivotIndex + 1, high); 432 | } 433 | } 434 | ``` 435 | 436 | > Heap Sort: 437 | 438 | It uses the functions below to use the sorting method for Heap Sort. 439 | 440 | ```c++ 441 | void Heapify(int *ARRAY, const int length, const int index) 442 | { 443 | int largest = index; 444 | int left = 2 * index + 1; 445 | int right = 2 * index + 2; 446 | 447 | if (left < length && ARRAY[left] > ARRAY[largest]) 448 | largest = left; 449 | if (right < length && ARRAY[right] > ARRAY[largest]) 450 | largest = right; 451 | if (largest != index) 452 | { 453 | Swap(&ARRAY[index], &ARRAY[largest]); 454 | Heapify(ARRAY, length, largest); 455 | } 456 | } 457 | 458 | void HeapSort(int *ARRAY, int length) 459 | { 460 | int i; 461 | for (i = length / 2 - 1; i >= 0; i--) 462 | Heapify(ARRAY, length, i); 463 | for (i = length - 1; i >= 0; i--) 464 | { 465 | Swap(&ARRAY[0], &ARRAY[i]); 466 | Heapify(ARRAY, i, 0); 467 | } 468 | } 469 | ``` 470 | 471 |
472 | 473 | --- 474 | 475 |
476 | 477 | ## Analysis 478 | 479 | When array is Sorted: 480 | 481 | | N | Insertion sort | Mergesort | Quicksort | Heapsort | 482 | | -----: | :------------- | :-------- | :-------- | :------- | 483 | | 10 | 0 | 0 | 0 | 0 | 484 | | 100 | 0 | 0 | 0 | 0 | 485 | | 1000 | 0 | 0 | 0 | 0.0004 | 486 | | 10000 | 0 | 0.0008 | 0.0008 | 0.0012 | 487 | | 100000 | 0 | 0.0134 | 0.0266 | 0.0374 | 488 | 489 | When array is Random: 490 | 491 | | N | Insertion sort | Mergesort | Quicksort | Heapsort | 492 | | -----: | :------------- | :-------- | :-------- | :------- | 493 | | 10 | 0 | 0 | 0 | 0 | 494 | | 100 | 0 | 0 | 0 | 0 | 495 | | 1000 | 0.0026 | 0 | 0 | 0 | 496 | | 10000 | 0.036 | 0.0012 | 0.001 | 0.0012 | 497 | | 100000 | 3.5818 | 0.014 | 0.0114 | 0.0172 | 498 | 499 | The tables above are the average processor time for each sorting algorithm for a set value of N. 500 | 501 |
502 | 503 | --- 504 | 505 |
506 | 507 | ## References 508 | 509 |
510 | Dynamic Memory Allocation in C++ 511 | 512 | - https://techvidvan.com/tutorials/cpp-dynamic-memory-allocation/ 513 | 514 | Generating Random Numbers 515 | 516 | - https://www.geeksforgeeks.org/rand-and-srand-in-ccpp/ 517 | 518 | Insertion Sort 519 | 520 | - https://www.tutorialspoint.com/design_and_analysis_of_algorithms/design_and_analysis_of_algorithms_insertion_sort.htm 521 | 522 | Time for C/C++ 523 | 524 | - http://www.gnu.org/software/libc/manual/html_node/CPU-Time.html 525 | 526 | -https://www.tutorialspoint.com/how-to-use-clock-function-in-cplusplus 527 | 528 | Standard Library 529 | 530 | - https://www.programiz.com/cpp-programming/library-function/cstdlib 531 | 532 | File Handling 533 | 534 | - https://www.guru99.com/cpp-file-read-write-open.html 535 | 536 | Quick Sort Problem 537 | 538 | - https://stackoverflow.com/questions/63686324/quicksort-to-already-sorted-array 539 | 540 | String Stream 541 | 542 | - https://www.tutorialspoint.com/stringstream-in-cplusplus 543 | 544 | - https://sonnevision.wordpress.com/2012/01/11/how-to-clear-a-stringstream/ 545 | 546 |
547 | 548 | --- 549 | 550 |
551 | 552 | Group note: 553 | 554 | The program is challenging and at the same time `fun`. It is a group effort and we are happy to present what we have learned and what are the stugles that we encounter by doing the project. 555 | Even we have a lot of problems enountered, but the group is there to understand each other's concern and make a new schedule for a meeting incase we have something to clarify about the project. 556 | We used different strategies mainly data structures in the problems to experement but failed. But that failure help us to understand what are small mistakes that we made and make things better. We hope that everyone is understandable. 557 | 558 |
559 | 560 | --- 561 | 562 |
563 | 564 | # `Thank You For Reading This File` 565 | # MarOOPproject1 566 | -------------------------------------------------------------------------------- /Voting.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Collections; 3 | import java.util.Comparator; 4 | import java.util.Scanner; 5 | import java.io.File; 6 | 7 | public class Voting { 8 | 9 | private Scanner scan, in = new Scanner(System.in); 10 | private ArrayList candidates = new ArrayList<>(); 11 | private ArrayList voter = new ArrayList<>(); 12 | private String firstName, lastName, initial, suffix, age, politicalParty, educationalBackground, chosenPosition, 13 | crimeRecord, isQualified, votedPres, votedVp, votedSenate, votedSenList[] = new String[12]; 14 | private int sizeCount[] = new int[6], counter; 15 | 16 | void Menu() { 17 | System.out.println("\nOOP Project 1 : Voting System\n"); 18 | System.out.println("1 - Show All Candidates"); 19 | System.out.println("2 - Vote Candidates"); 20 | System.out.println("3 - Fill a Candidacy"); 21 | System.out.println("4 - Show Voting Logs"); 22 | System.out.println("5 - Show Final Result"); 23 | System.out.println("6 - Load Existing Value"); 24 | System.out.println("7 - Clear Data"); 25 | System.out.println("8 - Exit"); 26 | System.out.print("\nOption: "); 27 | } 28 | 29 | void Sort(ArrayList list) { 30 | if (list.size() == 0) 31 | return; 32 | Collections.sort(list, new Comparator() { 33 | public int compare(Object_Candidate c1, Object_Candidate c2) { 34 | return c1.getLastName().compareTo(c2.getLastName()); 35 | } 36 | }); 37 | } 38 | 39 | void IncrementPosSize(String pos, String qualification) { 40 | if (pos.equalsIgnoreCase("President") && qualification.equalsIgnoreCase("Qualified")) 41 | sizeCount[0]++; 42 | if (pos.equalsIgnoreCase("Vice-President") && qualification.equalsIgnoreCase("Qualified")) 43 | sizeCount[1]++; 44 | if (pos.equalsIgnoreCase("Senator") && qualification.equalsIgnoreCase("Qualified")) 45 | sizeCount[2]++; 46 | if (pos.equalsIgnoreCase("President") && qualification.equalsIgnoreCase("Unqualified")) 47 | sizeCount[3]++; 48 | if (pos.equalsIgnoreCase("Vice-President") && qualification.equalsIgnoreCase("Unqualified")) 49 | sizeCount[4]++; 50 | if (pos.equalsIgnoreCase("Senator") && qualification.equalsIgnoreCase("Unqualified")) 51 | sizeCount[5]++; 52 | } 53 | 54 | void DecrementPosSize(String pos, String qualification) { 55 | if (pos.equalsIgnoreCase("President") && qualification.equalsIgnoreCase("Qualified") && sizeCount[0] != 0) 56 | sizeCount[0]--; 57 | if (pos.equalsIgnoreCase("Vice-President") && qualification.equalsIgnoreCase("Qualified") && sizeCount[1] != 0) 58 | sizeCount[1]--; 59 | if (pos.equalsIgnoreCase("Senator") && qualification.equalsIgnoreCase("Qualified") && sizeCount[2] != 0) 60 | sizeCount[2]--; 61 | if (pos.equalsIgnoreCase("President") && qualification.equalsIgnoreCase("Unqualified") && sizeCount[3] != 0) 62 | sizeCount[3]--; 63 | if (pos.equalsIgnoreCase("Vice-President") && qualification.equalsIgnoreCase("Unqualified") 64 | && sizeCount[4] != 0) 65 | sizeCount[4]--; 66 | if (pos.equalsIgnoreCase("Senator") && qualification.equalsIgnoreCase("Unqualified") && sizeCount[5] != 0) 67 | sizeCount[5]--; 68 | } 69 | 70 | void LoadData() throws Exception { 71 | File file = new File("files/candidate.txt"); 72 | scan = new Scanner(file); 73 | while (scan.hasNextLine()) { 74 | scan.findInLine(": "); 75 | lastName = scan.nextLine(); 76 | 77 | scan.findInLine(": "); 78 | firstName = scan.nextLine(); 79 | 80 | scan.findInLine(": "); 81 | initial = scan.nextLine(); 82 | if (initial.equalsIgnoreCase("Initial:")) 83 | initial = ""; 84 | 85 | scan.findInLine(": "); 86 | suffix = scan.nextLine(); 87 | if (suffix.equalsIgnoreCase("Suffix:")) 88 | suffix = ""; 89 | 90 | scan.findInLine(": "); 91 | politicalParty = scan.nextLine(); 92 | 93 | scan.findInLine(": "); 94 | educationalBackground = scan.nextLine(); 95 | 96 | scan.findInLine(": "); 97 | chosenPosition = scan.nextLine(); 98 | 99 | scan.findInLine(": "); 100 | crimeRecord = scan.nextLine(); 101 | scan.nextLine(); 102 | 103 | if (crimeRecord.equalsIgnoreCase("none")) 104 | isQualified = "Qualified"; 105 | else 106 | isQualified = "Unqualified"; 107 | 108 | IncrementPosSize(chosenPosition, isQualified); 109 | candidates.add(new Object_Candidate(lastName, firstName, initial, suffix, politicalParty, 110 | educationalBackground, chosenPosition, crimeRecord, isQualified)); 111 | } 112 | Sort(candidates); 113 | System.out.println("Note: The Data is now Loaded, Ready for Voting."); 114 | scan.close(); 115 | } 116 | 117 | void QueryName(Object_Candidate data, String pos, String qualification) { 118 | if (data.getChosenPosition().equalsIgnoreCase(pos) && data.getIsQualified().equalsIgnoreCase(qualification)) 119 | System.out.println(data.getLastName() + ", " + data.getFirstName() + " " + data.getInitial() + " " 120 | + data.getSuffix()); 121 | } 122 | 123 | void Option() { 124 | System.out.print("1 - Show All Valid Candidates | 2 - Show All Disqualified Candidates | 3 - Menu\nOption: "); 125 | String input = in.nextLine(); 126 | if (input.equals("1")) 127 | PrintAllValidCandidates(); 128 | if (input.equals("2")) 129 | PrintAllInvalidCandidates(); 130 | } 131 | 132 | void PrintAllCandidates() { 133 | if (candidates.size() == 0) { 134 | System.out.println("Note: No Available Candidates. Please Load or fill a candidacy."); 135 | return; 136 | } 137 | System.out.println("\nAll Candidate for President"); 138 | for (Object_Candidate data : candidates) 139 | QueryName(data, "President", data.getIsQualified()); 140 | System.out.println("\nAll Candidate for Vice-President"); 141 | for (Object_Candidate data : candidates) 142 | QueryName(data, "Vice-President", data.getIsQualified()); 143 | System.out.println("\nAll Candidate for Senator"); 144 | for (Object_Candidate data : candidates) 145 | QueryName(data, "Senator", data.getIsQualified()); 146 | Option(); 147 | } 148 | 149 | void ValidPresCandidates() { 150 | if (sizeCount[0] == 0) { 151 | System.out.println("Note: No Valid Candidate For President."); 152 | return; 153 | } 154 | System.out.println("\nAll Valid Candidate for President"); 155 | for (Object_Candidate data : candidates) 156 | QueryName(data, "President", "Qualified"); 157 | } 158 | 159 | void ValidVPresCandidates() { 160 | if (sizeCount[1] == 0) { 161 | System.out.println("Note: No Valid Candidate For Vice-President."); 162 | return; 163 | } 164 | System.out.println("\nAll Valid Candidate for Vice-President"); 165 | for (Object_Candidate data : candidates) 166 | QueryName(data, "Vice-President", "Qualified"); 167 | } 168 | 169 | void ValidSenCandidates() { 170 | if (sizeCount[2] == 0) { 171 | System.out.println("Note: No Valid Candidate For Senator."); 172 | return; 173 | } 174 | System.out.println("\nAll Valid Candidate for Senator"); 175 | for (Object_Candidate data : candidates) 176 | QueryName(data, "Senator", "Qualified"); 177 | } 178 | 179 | void InvalidPresCandidates() { 180 | if (sizeCount[3] == 0) { 181 | System.out.println("Note: No Disqualified Candidate For President."); 182 | return; 183 | } 184 | System.out.println("\nAll Disqualified Candidate for President"); 185 | for (Object_Candidate data : candidates) 186 | QueryName(data, "President", "Unqualified"); 187 | } 188 | 189 | void InvalidVPresCandidates() { 190 | if (sizeCount[4] == 0) { 191 | System.out.println("Note: No Disqualified Candidate For Vice-President."); 192 | return; 193 | } 194 | System.out.println("\nAll Disqualified Candidate for Vice-President"); 195 | for (Object_Candidate data : candidates) 196 | QueryName(data, "Vice-President", "Unqualified"); 197 | } 198 | 199 | void InvalidSenCandidates() { 200 | if (sizeCount[5] == 0) { 201 | System.out.println("Note: No Disqualified Candidate For Senator."); 202 | return; 203 | } 204 | System.out.println("\nAll Disqualified Candidate for Senator"); 205 | for (Object_Candidate data : candidates) 206 | QueryName(data, "Senator", "Unqualified"); 207 | } 208 | 209 | void PrintAllValidCandidates() { 210 | ValidPresCandidates(); 211 | ValidVPresCandidates(); 212 | ValidSenCandidates(); 213 | } 214 | 215 | void PrintAllInvalidCandidates() { 216 | InvalidPresCandidates(); 217 | InvalidVPresCandidates(); 218 | InvalidSenCandidates(); 219 | } 220 | 221 | void Vote() { 222 | 223 | if (sizeCount[0] < 2 || sizeCount[1] < 3 || sizeCount[2] < 14) { 224 | System.out.println("Check IF : Candidate for President is at least 2."); 225 | System.out.println("Check IF : Candidate for Vice-President is at least 3."); 226 | System.out.println("Check IF : Candidate for Senator is at least 14."); 227 | return; 228 | } 229 | 230 | System.out.print("Enter Age: "); 231 | age = in.nextLine(); 232 | 233 | if (!age.matches("[0-9]+")) 234 | return; 235 | if (Integer.parseInt(age) < 18 || Integer.parseInt(age) > 100) 236 | return; 237 | 238 | System.out.print("Last Name: "); 239 | lastName = in.nextLine(); 240 | 241 | System.out.print("First Name: "); 242 | firstName = in.nextLine(); 243 | 244 | System.out.print("Initial (skip if none): "); 245 | initial = in.nextLine(); 246 | 247 | System.out.print("Suffix (skip if none): "); 248 | suffix = in.nextLine(); 249 | 250 | ValidPresCandidates(); 251 | System.out.print("President (enter 0 if none): "); 252 | votedPres = in.nextLine(); 253 | 254 | ValidVPresCandidates(); 255 | System.out.print("Vice-President (enter 0 if none): "); 256 | votedVp = in.nextLine(); 257 | 258 | ValidSenCandidates(); 259 | counter = 0; 260 | while (counter < 12) { 261 | 262 | System.out.println("Senator Vote Remaning is " + (12 - counter)); 263 | System.out.print("Senator (enter 0 if none): "); 264 | votedSenate = in.nextLine(); 265 | 266 | if (votedSenate.equalsIgnoreCase("0")) 267 | break; 268 | 269 | if (true) { 270 | votedSenList[counter] = votedSenate; 271 | counter++; 272 | } 273 | } 274 | // to-do: checker if voted senate exist.. 275 | // to-do: checker if voted senate exist already on the list for voting.. 276 | voter.add(new Object_Voter(lastName, firstName, initial, suffix, age, votedPres, votedVp, votedSenList)); 277 | } 278 | 279 | void isSenateVoteDuplicated(String senList[], String values[]) { 280 | for (Object_Candidate data : candidates) { 281 | if (data.getChosenPosition().equalsIgnoreCase("Senator") 282 | && data.getIsQualified().equalsIgnoreCase("Qualified")) { 283 | 284 | } 285 | } 286 | } 287 | 288 | // end 289 | void ClearAll() { 290 | if (candidates.size() == 0 && voter.size() == 0) { 291 | System.out.println("Note: Nothing To Clear. Try Again."); 292 | return; 293 | } 294 | candidates.clear(); 295 | voter.clear(); 296 | System.out.println("Note: All Data Is Now Clear."); 297 | } 298 | 299 | void CloseAll() { 300 | candidates.clear(); 301 | voter.clear(); 302 | in.close(); 303 | System.out.println("\nThank you for using the program."); 304 | } 305 | 306 | } -------------------------------------------------------------------------------- /files/candidate.txt: -------------------------------------------------------------------------------- 1 | Last Name: Cardiño 2 | First Name: Joemar 3 | Initial: J. 4 | Suffix: 5 | Political Party: Independent 6 | Educational Background: Doctorate 7 | Running for: President 8 | Criminal Record: none 9 | 10 | Last Name: Echague 11 | First Name: Shaira 12 | Initial: D. 13 | Suffix: 14 | Political Party: Independent 15 | Educational Background: Masteral 16 | Running for: Vice-President 17 | Criminal Record: none 18 | 19 | Last Name: Jane 20 | First Name: Mik 21 | Initial: A. 22 | Suffix: Mik 23 | Political Party: Independent 24 | Educational Background: Doctorate 25 | Running for: President 26 | Criminal Record: none 27 | 28 | Last Name: Trump 29 | First Name: Donald 30 | Initial: J. 31 | Suffix: Jr. 32 | Political Party: Glory 33 | Educational Background: Doctorate 34 | Running for: Vice-President 35 | Criminal Record: extortion 36 | 37 | Last Name: Speed 38 | First Name: Bary 39 | Initial: K. 40 | Suffix: Sr. 41 | Political Party: Independent 42 | Educational Background: Doctorate 43 | Running for: Senator 44 | Criminal Record: none 45 | 46 | -------------------------------------------------------------------------------- /files/voterLogs.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joemar25/Object-Oriented-Programming-Voting-System-/c407dd348af77d67885be56bfccf6a12f21e7a0b/files/voterLogs.txt -------------------------------------------------------------------------------- /other/planDesign.drawio: -------------------------------------------------------------------------------- 1 | 7R3bcpvI8lvOg2qfrBqG+2N8S3Y3OeVdV/k4+7KFBZZIEMiAbClff4abBDOtASuIAZFUpSxGo4Hpe/d0NxP5arn5GFqrxZfAdrwJRvZmIl9PMJYkZJA/ycg2G1ExygbmoWvnk/YD9+4PJx8spq1d24kqE+Mg8GJ3VR2cBb7vzOLKmBWGwVt12nPgVe+6suYOM3A/szx29H+uHS+yUQPr+/FPjjtfFHeWNDP7ZmkVk/OdRAvLDt5KQ/LNRL4KgyDOPi03V46XAK+AS/a72wPf7h4sdPy4yQ+UF2Qaa+sVmfjHxzvn4o/Hl08XspYt82p563zH+dPG2wIEjk0gkl8GYbwI5oFveTf70cswWPu2k9wHkav9nM9BsCKDEhn85sTxNkevtY4DMrSIl17+rbNx48fk51M1v/pa+uZ6k6+cXmxLF3dO6C6d2AnzMRYmOZiiYB3O8v38+816UW/vbDN8xdLj2pMf1tuLgrascO7EPICp2cQEKKU75CD/6ATkccItmRA6nhW7r1UysnJqnO/m7RFGPuQ4g/HHe+wS+iKyhZjBYRSHwfcdBeMq9AllrpJ5y808YeLpsxe8zRZkmWm62L/JnLeFGzv3KysF4huZxoP2qxPGzoYLnvxbVZ8i2Sz9yxbYVoXA257zJJSPLUpcp6ETgVfvBXccT9UKS9XgPK1XRK0wULfdaOVZyRMEq9gN/Igl8JyGCZQsz3O8gJDyksBuVZIQle9KogMk7hL8n92NU6imlF8YZmqBExQuJ+xIvMwK+ESsAAo+PHBW0BoKeEkUK4BPY5wnkPVeAVlBIqBMgBtuHwtjJrn4ureAksu92ZNele2ex9Ln0q8O2kqNMAqzfVOUtm8YpT/9EIap3C8mrALXj6PSynfJwF6MFiZDYUFoGmUV181HFDllD7Anrt1OjtdvrM3tRjvVRj6kY4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AHXPiQ6+hUHPKpQz3Rb/B3CYVSvDBx1vhjWxuokWQQDuutA1sXMWjFKefUU5ytEJHc1L9V3l3veNhtjKOHHfPA5dT6CMP/0xft+a8TL9WZTeG+capZ7SLbqwGqzvKgZQIEgRA0p4xENaQLJRYueM7pNAiSXMcSotXlPaSpAIMAfiPNCeRduORVQxGOi3lZryoX2nk1BGd0yHx04UB0jkIWIH7CzGw+IyEU0RpwV4juGCOT4vr8PqGIobOxamsWDYvoPWAca65nYMNeozzijP5u4M/ukiXhKpV2ch1J58w2hOz8S08zLyW6lzS7CHF2nsKRsJ8wasu8R4yg/TLdOT/1BrU4l6oUa7lqFAENhUUcdjjESoaZGKEqCl6KTIxbjBHLKTseobS7m9sSkev9bbrCPzA3upLnBmYJlwSUrvsnB3ABmDdzICeeO4dXAOldLVKOiO7pCDAsKEFPgBI4zn+m48tMzxmDRMUgpTnjWmflKAq10TbcvXbAc1OFH7G0HDIKm2kEbQs1Rnh5VtqZlnElGmRxeahHHIhrfbbM9+a6bNbWUOkIyBPaR9cUbKxWCSVJfI0pD1IKuJB+R4wsqzz1SeWCPR0+TM10tugOcpaSUsQ+TAAeQI70dUBVf8AIJQYSKwh8L+tJOIuu962S4x3SxwTmqbzPj6cTo66SJ/65OzFO2DMCaVif9wmWfTifgVPeOJ5UoZ9CuW4crlHOwoI1ToID9jzeXR0fAc5uU5wlUv3qWjQBNOaaJeCgxw/37mwJrOXlToJedsp8a8ibOzPsEQYLDRDz74uxlNZHMYB+SM/UixkFQRTjK8AO8K6eSMa6ULua1z2f2Ws4lgjobFpoVJfK2uk5ogspqRMgAegmPeIPyY+keWfzGIeZoDtFvrBtIstfjEXPYODtTe2T5yiUyuOst3IkdUk/8aiUyyFkLYzSHiGH7437VJrX/IbEufgE= -------------------------------------------------------------------------------- /other/problem.txt: -------------------------------------------------------------------------------- 1 | Using Object-oriented programming approach, create a program that can do the following tasks: 2 | 3 | FILING OF CANDIDACY: 4 | Data needed: 5 | - Full name 6 | - Political Party 7 | - Educational background 8 | - Position to Run (President, VP, Senator) 9 | - Does the candidate has existing criminal records? If yes, input the criminal case. 10 | 11 | VALIDATION OF CANDIDATES: 12 | Display the data of qualified and disqualified list candidates. 13 | For disqualified candidates, display the reason(s) of disqualification. 14 | Group them by their selected position to run. 15 | 16 | Qualifications: 17 | Only candidates with NO criminal records and Master Degree holder can run for the position of Senator. 18 | Only candidates with NO criminal records and Doctorate Degree holder can run for the position of President and Vice-president. 19 | Minimum number of qualified candidates for senator is 12. 20 | 21 | VOTING: 22 | The program must ask the following data from the voter: 23 | - Full name 24 | - Age 25 | 26 | After validating the candidates, display the names and data of QUALIFIED candidates and the user must proceed to voting. 27 | Minimum number of voters will be 25. 28 | 29 | - The slot for candidacy for president is 10, 15 for vice president and 30 for senators. 30 | - Only 18 years old and above can vote. 31 | - The voter can only vote ONE President, ONE Vice-president and 12 Senators (Maximum). 32 | - The voter can decide to cast 0 vote to any position. 33 | 34 | After voting, display the final tally of votes. 35 | Display the respective winners on each position. 36 | 37 | my NOTE: 38 | 39 | [a-zA-Z]+ for checking if character contains a to z and A to Z characters 40 | --------------------------------------------------------------------------------