Created
September 6, 2026 20:37
-
-
Save thinkphp/c42436f40b1a810e3650b4e8c353de10 to your computer and use it in GitHub Desktop.
main.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.ArrayList; | |
| import java.util.List; | |
| import java.util.Date; | |
| import java.util.Iterator; | |
| import java.util.NoSuchElementException; | |
| import java.util.Random; | |
| import java.util.HashSet; | |
| import java.util.Set; | |
| // ===================== Student ID Generator ===================== | |
| // Utility class responsible for generating unique student IDs. | |
| // | |
| // A static counter keeps track of the number of students for whom | |
| // an ID has been generated. A random number between 0 and 9999 | |
| // is also included to make the generated ID more distinctive. | |
| // | |
| // Each generated ID follows the format: | |
| // S<counter>S<randomNumber> | |
| // Example: S1S4827, S2S913, S3S7645. | |
| // | |
| // The generateID() method is static because no object of this class | |
| // is required to generate an ID. | |
| class StudentIdGenerator { | |
| private static int contor = 0; | |
| public static String genereazaID() { | |
| contor++; | |
| Random random = new Random(); | |
| int randomNumber = random.nextInt(10000); // 0 - 9999 | |
| return "S" + contor + "S" + randomNumber; | |
| } | |
| } | |
| // ===================== Judge ID Generator ===================== | |
| // Utility class responsible for generating judge IDs. | |
| // | |
| // A static counter is used to keep track of the number of generated | |
| // judge IDs. Each ID also contains a randomly generated number | |
| // between 0 and 9999 to make the identifier more distinctive. | |
| // | |
| // The generated ID follows the format: | |
| // J<counter><randomNumber> | |
| // Examples: J14827, J2913, J37645. | |
| // | |
| // The generateID() method is static because an object of this class | |
| // is not required to generate a judge ID. | |
| class JudgeIdGenerator { | |
| private static int contor = 0; | |
| public static String genereazaID() { | |
| Random random = new Random(); | |
| int randomNumber = random.nextInt(10000); // 0 - 9999 | |
| contor++; | |
| return "J" + contor + randomNumber; | |
| } | |
| } | |
| /* ===================== Email Validator ===================== | |
| // Utility class responsible for validating email addresses. | |
| // | |
| // The validation is performed using a regular expression (REGEX). | |
| // The expression checks that the email contains: | |
| // - a valid username before the '@' character; | |
| // - a domain name; | |
| // - a dot followed by at least two letters as the domain extension. | |
| // | |
| // The isValid() method also checks that the email is not null. | |
| // It returns true if the email matches the required format | |
| // and false otherwise. | |
| // | |
| // Example of valid emails: | |
| // student@mail.com | |
| // name.surname@example.co.uk | |
| // | |
| // Example of invalid emails: | |
| // student@mail | |
| // @mail.com | |
| // student@.com | |
| */ | |
| class EmailValidator { | |
| //Rules: test[,,,]@ test[...].com.co,,,etc | |
| private static final String REGEXP = "^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$"; | |
| public static boolean isValid(String email) { | |
| return email != null && email.matches( REGEXP ); | |
| } | |
| } | |
| /* | |
| // ===================== Name Validator ===================== | |
| // Utility class responsible for validating person names. | |
| // | |
| // The validation is performed using a regular expression (REGEX). | |
| // The expression allows: | |
| // - uppercase and lowercase Latin letters; | |
| // - Romanian diacritics such as Ă, Â, Î, Ș and Ț; | |
| // - spaces and hyphens between name parts. | |
| // | |
| // The name must contain at least one letter and cannot start or end | |
| // with a space or hyphen. | |
| // | |
| // The isValid() method also checks that the name is not null. | |
| // It returns true if the name matches the required format | |
| // and false otherwise. | |
| */ | |
| class NameValidator { | |
| private static final String REGEXP = "^[A-Za-zĂÂÎȘȚăâîșț]+(?:[ -][A-Za-zĂÂÎȘȚăâîșț]+)*$"; | |
| public static boolean isValid(String nume) { | |
| return nume != null && nume.matches( REGEXP ); | |
| } | |
| } | |
| /* | |
| // ===================== Email Duplicate Exception ===================== | |
| // Custom unchecked exception thrown when a student attempts to register | |
| // using an email address that has already been registered. | |
| // | |
| // The exception extends RuntimeException, so it does not need to be | |
| // explicitly declared or caught by the calling method. | |
| // | |
| // The constructor receives the duplicated email address and includes it | |
| // in the error message to clearly identify the cause of the exception. | |
| */ | |
| class EmailDuplicateException extends RuntimeException { | |
| public EmailDuplicateException( String email ) { | |
| super("Email declined. This email address cannot be used: " + email); | |
| } | |
| } | |
| // ===================== Title Duplicate Exception ===================== | |
| // Custom unchecked exception thrown when a research project is submitted | |
| // with a title that has already been registered. | |
| // | |
| // The exception extends RuntimeException, therefore it does not need | |
| // to be explicitly declared or caught by the calling method. | |
| // | |
| // The constructor receives the duplicated project title and includes it | |
| // in the error message to clearly indicate the reason for rejection. | |
| class TitleDuplicateException extends RuntimeException { | |
| public TitleDuplicateException( String title ) { | |
| super("Title declined. This title project cannot be used: " + title); | |
| } | |
| } | |
| //CUSTOM QUEUE by me | |
| class Queue<anyType> implements Iterable<anyType> { | |
| private static class Nod<anyType> { | |
| anyType data; | |
| Nod<anyType> next; | |
| Nod(anyType data) { this.data = data; } | |
| } | |
| private Nod<anyType> first; // HEAD queue (where is it removed from) | |
| private Nod<anyType> last; // HEAD queue (where is it added from) | |
| private int queueSIZE; | |
| // add to the end of the Queue | |
| public void enqueue(anyType item) { | |
| Nod<anyType> nod = new Nod<>(item); | |
| if (last == null) { | |
| first = nod; | |
| last = nod; | |
| } else { | |
| last.next = nod; | |
| last = nod; | |
| } | |
| queueSIZE++; | |
| } | |
| // take out | |
| public anyType dequeue() { | |
| if (isEmpty()) { | |
| //throw new NoSuchElementException("Coada este goala, nu se poate face dequeue()."); | |
| throw new NoSuchElementException("The Queue is empty, can't dequeue()."); | |
| } | |
| anyType data = first.data; | |
| first = first.next; | |
| if (first == null) { | |
| last = null; | |
| } | |
| queueSIZE--; | |
| return data; | |
| } | |
| // Return from the front of the Queue, not removed | |
| public anyType peek() { | |
| if (isEmpty()) { | |
| throw new NoSuchElementException("The queue is empty, there is no peek() element."); | |
| } | |
| return first.data; | |
| } | |
| public boolean isEmpty() { | |
| return queueSIZE == 0; | |
| } | |
| public int size() { | |
| return queueSIZE; | |
| } | |
| // take out an element from Queue | |
| public boolean remove(anyType item) { | |
| Nod<anyType> current = first; | |
| Nod<anyType> previous = null; | |
| while (current != null) { | |
| if (current.data == item) { | |
| if (previous == null) { | |
| first = current.next; | |
| } else { | |
| previous.next = current.next; | |
| } | |
| if (current == last) { | |
| last = previous; | |
| } | |
| queueSIZE--; | |
| return true; | |
| } | |
| previous = current; | |
| current = current.next; | |
| } | |
| return false; | |
| } | |
| @Override | |
| public Iterator<anyType> iterator() { | |
| return new Iterator<anyType>() { | |
| private Nod<anyType> curent = first; | |
| @Override | |
| public boolean hasNext() { | |
| return curent != null; | |
| } | |
| @Override | |
| public anyType next() { | |
| if (!hasNext()) throw new NoSuchElementException(); | |
| anyType data = curent.data; | |
| curent = curent.next; | |
| return data; | |
| } | |
| }; | |
| } | |
| } | |
| // ===================== Person (abstract CLASS) ===================== | |
| abstract class Person { | |
| private String id; | |
| private String name; | |
| private String email; | |
| public Person(String id, String name, String email) { | |
| if (!EmailValidator.isValid(email)) { | |
| throw new IllegalArgumentException("Invalid email: " + email); | |
| } | |
| if (!NameValidator.isValid(name)) { | |
| throw new IllegalArgumentException("Invalid name: " + name); | |
| } | |
| this.id = id; | |
| this.name = name; | |
| this.email = email; | |
| } | |
| //getters | |
| public String getId() { return id; } | |
| public String getName() { return name; } | |
| public String getEmail() { return email; } | |
| //setters | |
| public void setId(String id) { this.id = id; } | |
| public void setName(String name) { this.name = name; } | |
| public void setEmail(String email) { | |
| if (email == null || !email.contains("@")) { | |
| System.out.println("Invalid email for " + name + ": " + email); | |
| this.email = null; | |
| } else { | |
| this.email = email; | |
| } | |
| } | |
| public void displayDetails() { | |
| System.out.println("ID: " + id + " | Name: " + name + " | Email: " + email); | |
| } | |
| public abstract String getRole(); // abstract | |
| @Override | |
| public String toString() { | |
| return "Person{id=" + id + ", name=" + name + ", email=" + email + "}"; | |
| } | |
| } | |
| // ===================== Validatable (interfata) ===================== | |
| interface Validatable { | |
| boolean validate(); | |
| } | |
| // ===================== Award ===================== | |
| // Extended: retains ranking position, certificate type and monetary amount | |
| class Award { | |
| private int position; // 1, 2, 3 sau 0 for "only participation" | |
| private String certificatType; // Gold / Silver / Bronze / Participation | |
| private int sumaMoney; // in pounds (0 for empty places) | |
| public Award(int position, String certificat, int sumaMoney) { | |
| this.position = position; | |
| this.certificatType = certificat; | |
| this.sumaMoney = sumaMoney; | |
| } | |
| public int getPosition() { return position; } | |
| public String getCertificat() { return certificatType; } | |
| public int getSumaMoney() { return sumaMoney; } | |
| @Override | |
| public String toString() { | |
| String prizeMoney = sumaMoney > 0 ? " and £" + sumaMoney + " Cash Prize" : ""; | |
| return certificatType + prizeMoney; | |
| } | |
| } | |
| // ===================== Student Class ===================== | |
| class Student extends Person { | |
| private String titleProposal; | |
| private Date dateSubmitted; | |
| private boolean isFINALIST; | |
| private ResearchProject proiect; // proiectul depus de acest student | |
| private Award award; // 0..1 -> poate fi null | |
| private double scorFinal; // media evaluarilor primite | |
| private static int maximum = 0; | |
| public Student(String id, String nume, String email) { | |
| super(id, nume, email); | |
| if(maximum >= 10) { | |
| throw new IllegalStateException("Registration unsuccessful. Research Project maximum capacity reached!"); | |
| } maximum++; | |
| this.isFINALIST = false; | |
| this.award = null; | |
| this.scorFinal = 0.0; | |
| } | |
| public void submitProiect(ResearchProject p) { | |
| this.proiect = p; | |
| this.titleProposal = p.getProjectTitle(); | |
| this.dateSubmitted = new Date(); | |
| System.out.println(getName() + " submitted the project: " + p.getProjectTitle()); | |
| } | |
| public ResearchProject getProiect() { return proiect; } | |
| public boolean isFinalist() { return isFINALIST; } | |
| public void setFinalist(boolean isFinalist) { this.isFINALIST = isFinalist; } | |
| public double getScorFinal() { return scorFinal; } | |
| public void setScorFinal(double scorFinal) { this.scorFinal = scorFinal; } | |
| public void receiveAward(Award award) { | |
| System.out.println(); | |
| this.award = award; | |
| System.out.println(getName() + " receives " + award); | |
| } | |
| public Award getAward() { return award; } | |
| @Override | |
| public void displayDetails() { | |
| super.displayDetails(); | |
| System.out.println(" Title Proposal: " + titleProposal | |
| + " | Final Score: " + scorFinal | |
| + " | Finalist STATUS (shortlisted): " + isFINALIST); | |
| } | |
| @Override | |
| public String getRole() { | |
| return "Student"; | |
| } | |
| } | |
| // ===================== Judge ===================== | |
| class Judge extends Person { | |
| private String idJudge; | |
| public Judge(String id, String nume, String email, String idJudge) { | |
| super(id, nume, email); | |
| this.idJudge = idJudge; | |
| } | |
| public String getIdJudge() { return idJudge; } | |
| public Evaluation evalueaza( ResearchProject proiect, int[] scoruri ) { | |
| Evaluation evaluare = new Evaluation( this, proiect, scoruri ); | |
| System.out.println( "Judge " + getName() + " has evaluated \"" + proiect.getProjectTitle() | |
| + "\" Project. Average score allocated: " + String.format("%.2f",evaluare.calculeazaMedie())); | |
| return evaluare; | |
| } | |
| @Override | |
| public String getRole() { | |
| return "Judge"; | |
| } | |
| } | |
| // ===================== ResearchProject (implements Validatable) ========================== | |
| //Contains the 5 mandatory sections required in the brief: Project Title, Abstract, | |
| // Research Methodology, Potential Outcomes, Research Novelty. | |
| // The word count is NO longer given manually ===>>> | |
| // ====>>>> it is calculated from the actual content of the sections. | |
| class ResearchProject implements Validatable { | |
| private String projectTitle; // Project Title | |
| private String abstractPro; // Abstract | |
| private String methodology; // Research Methodology | |
| private String potentialOutcomes; // Potential Outcomes | |
| private String novelty; // Research Novelty | |
| private int cntWords; //number of words | |
| private static final int MINIM_WORDS = 5000; // requirement din brief | |
| private static final String FINAL_SUBMISSION_DEADLINE = "November-2026"; // deadline | |
| private static final String START_DATE = "September-2026"; //startDate | |
| public ResearchProject(String title, String abstractPro, String methodology, String potentialOutcomes, String novelty) { | |
| this.projectTitle = title; | |
| this.abstractPro = abstractPro; | |
| this.methodology = methodology; | |
| this.potentialOutcomes = potentialOutcomes; | |
| this.novelty = novelty; | |
| } | |
| public String getProjectTitle() { return projectTitle; } | |
| public String getAbstractPro() { return abstractPro; } | |
| public String getMethodology() { return methodology; } | |
| public String getPotentialOutcomes() { return potentialOutcomes; } | |
| public String getNovelty() { return novelty; } | |
| //calculate the number of words | |
| public int getNumWords() { | |
| return countWords( abstractPro ) + countWords( methodology ) | |
| + countWords( potentialOutcomes ) + countWords( novelty ); | |
| } | |
| private int countWords( String text ) { | |
| if (text == null || text.isBlank()) return 0; | |
| return text.trim().split("\\s+").length; | |
| } | |
| @Override | |
| public boolean validate() { | |
| return esteValid(); | |
| } | |
| //check if the project is VALID | |
| /* | |
| - diff null or title empty | |
| - >= minimum WORDS | |
| */ | |
| public boolean esteValid() { | |
| return projectTitle != null && !projectTitle.isEmpty() && getNumWords() >= MINIM_WORDS && FINAL_SUBMISSION_DEADLINE == "November-2026" && START_DATE == "September-2026"; | |
| } | |
| // Display all information about Research Project. | |
| public void displayDetails() { | |
| System.out.println(" Project Title: " + projectTitle); | |
| System.out.println(" Abstract: " + previzualizare(abstractPro)); | |
| System.out.println(" Research Methodology: " + previzualizare(methodology)); | |
| System.out.println(" Potential Outcomes: " + previzualizare(potentialOutcomes)); | |
| System.out.println(" Research Novelty: " + previzualizare(novelty)); | |
| System.out.println(" Total Num Words: " + getNumWords()); | |
| } | |
| private String previzualizare(String text) { | |
| if (text == null || text.isBlank()) return "(gol)"; | |
| String[] words = text.trim().split("\\s+"); | |
| int limita = Math.min(12, words.length); | |
| StringBuilder sb = new StringBuilder(); | |
| for (int i = 0; i < limita; i++) sb.append(words[i]).append(" "); | |
| return sb.toString().trim() + " (...)"; | |
| } | |
| public int getCntWords() {return cntWords;} | |
| } | |
| // ===================== TextGenerator ===================== | |
| // Utility used ONLY in main(), to generate sufficiently long test content | |
| // for the project sections, without manually writing thousands of words in code. | |
| class TextGenerator { | |
| private static final String[] WORDS = { | |
| "research", "proposal", "analyse", "impact", "technology", "over", | |
| "domain", "studied", "through", "methods", "quantitative", "and", "quality", | |
| "for", "a", "identify", "patterns", "relevant", "in", "data", "colected", | |
| "rezults", "got", "confirm", "hypothesis", "initial", "again", "conclusions", | |
| "contribute", "meaningful", "at", "literature", "existence", "this", "algorithms", | |
| "of", "study", "applied", "context", "academic", "practice","","qualitative","section", | |
| "important","component","The", "CMS","discovery", "reach" | |
| }; | |
| private static final Random random = new Random(); | |
| public static String generate( int nrWordsNeeded) { | |
| StringBuilder sb = new StringBuilder(); | |
| for (int i = 0; i < nrWordsNeeded; i++) { | |
| sb.append( WORDS[ random.nextInt(WORDS.length) ] ).append(" "); | |
| } | |
| return sb.toString().trim(); | |
| } | |
| } | |
| // ===================== Evaluation (assoc Judge si ResearchProject) ===================== | |
| class Evaluation { | |
| //Attributes | |
| private Judge judge; | |
| private ResearchProject proiect; | |
| private int[] scoruri; // 3 criterii | |
| private int originality; | |
| private int technicalQuality; | |
| private int presentation; | |
| //constructor of the class | |
| public Evaluation( Judge judge, ResearchProject project, int[] scoruri ) { | |
| this.originality = scoruri[ 0 ]; | |
| this.technicalQuality = scoruri[ 1 ]; | |
| this.presentation = scoruri[ 2 ]; | |
| this.judge = judge; | |
| this.proiect = project; | |
| this.scoruri = scoruri; | |
| } | |
| //utility method | |
| public double calculeazaMedie() { | |
| int suma = 0; | |
| for (int s : scoruri) suma += s; | |
| //return Math.round(suma / (double) scoruri.length * 100.00 ) / 100.00 ; | |
| return suma / (double) scoruri.length; | |
| } | |
| //GETTERS | |
| public Judge getJudge() { return judge; } | |
| public ResearchProject getProiect() { return proiect; } | |
| public int getOriginality() { return originality; } | |
| public int getTechnicalQuality() { return technicalQuality; } | |
| public int getPresentation() { return presentation; } | |
| } | |
| // ===================== ResearchChampionshipSystem Class ===================== | |
| class ResearchChampionshipSystem { | |
| private Queue<Student> admissionList = new Queue<>(); | |
| private Queue<Student> waitingList = new Queue<>(); | |
| private List<Judge> judgeList = new ArrayList<>(); | |
| private List<ResearchProject> listaProiecte = new ArrayList<>(); | |
| private List<Evaluation> listaEvaluari = new ArrayList<>(); | |
| // NEW task Vrem sa tinem evidenta email-urilor si titlurilor deja folosite<<<<< | |
| private Set<String> emailsUsed = new HashSet<>(); | |
| private Set<String> titleUsed = new HashSet<>(); | |
| private static final int CAPACITATE_MAXIMA = 5; // doar 5 finalisti; restul (pana la 10 inscrisi) intra in asteptare | |
| //ResearchChampionshipSystem() {} | |
| ////Explicit Constructor | |
| //ResearchChampionshipSystem(int maxCapacity) {} | |
| ///////// UNIQUEs /////////// | |
| private boolean isEmailUnique(String email) { | |
| return email != null && !emailsUsed.contains(email.toLowerCase()); | |
| } | |
| private boolean isTitleUnique(String title) { | |
| return title != null && !titleUsed.contains( title.trim().toLowerCase() ); | |
| } | |
| public void registerStudent(Student s) { | |
| if(!isEmailUnique(s.getEmail())) { | |
| throw new EmailDuplicateException(s.getEmail()); | |
| } | |
| emailsUsed.add(s.getEmail().toLowerCase()); | |
| if (admissionList.size() < CAPACITATE_MAXIMA) { | |
| admissionList.enqueue(s); | |
| System.out.println(s.getName() + " was registered in Research Project Championship"); | |
| } else { | |
| if(waitingList.size() == 0) System.out.println(); | |
| waitingList.enqueue(s); | |
| System.out.println(s.getName() + " was added to Waiting List for Research Project."); | |
| } | |
| } | |
| public void addJudge(Judge j) { | |
| judgeList.add( j ); | |
| } | |
| /* | |
| public void addProiect(ResearchProject p) { | |
| if ( p.esteValid() ) { | |
| listaProiecte.add( p ); | |
| } else { | |
| System.out.println("Invalid Project, not added: " + p.getProjectTitle()); | |
| } | |
| } | |
| */ | |
| private void registerProject(ResearchProject p) { | |
| listaProiecte.add( p ); | |
| titleUsed.add( p.getProjectTitle().trim().toLowerCase() ); | |
| } | |
| // A finalist submits their complete project | |
| // If the project is VALID ---> it enters the list of accepted projects | |
| // If the project is INVALID ---> the finalist is automatically disqualified, and the NEXT from waiting list | |
| // An ELIGIBLE student from the Waiting List TAKES his PLACE (returned, so that he can also be asked for a project) | |
| public Student submitProiectFinalist(Student s, ResearchProject p) { | |
| //CHECK if duplicate | |
| if(!isTitleUnique(p.getProjectTitle())) { | |
| throw new TitleDuplicateException(p.getProjectTitle()); | |
| } | |
| s.submitProiect( p ); | |
| if ( p.esteValid() ) { | |
| registerProject( p ); | |
| System.out.println("The project has been submitted for " + s.getName() + ": " + p.getProjectTitle()); | |
| System.out.println("The title is UNIQUE. Number of words > 5000 is correct. Project successfully submitted before Deadline."); | |
| System.out.println(); | |
| return null; // nobody was promoted, Everything Is OK!!! | |
| } else { | |
| System.out.println("The project was rejected for " + s.getName() + " (validare esuata): " + p.getProjectTitle()); | |
| return desqualifiedAndPromote(s); | |
| } | |
| } | |
| // Remove the desqualified student from the list of finalists and promote the next student from Waiting List | |
| private Student desqualifiedAndPromote(Student descalificat) { | |
| admissionList.remove( descalificat ); | |
| descalificat.setFinalist( false ); | |
| System.out.println( descalificat.getName() + " has been disqualified from the Final."); | |
| System.out.println(); | |
| return promoteFromWaitingList(); | |
| } | |
| // efectueaza o evaluare si o retine central, ca sa poata fi folosita la calculul scorului final | |
| public void carriedOutEval(Judge j, ResearchProject p, int[] scoruri) { | |
| Evaluation e = j.evalueaza(p, scoruri); | |
| listaEvaluari.add(e); | |
| } | |
| public Student promoteFromWaitingList() { | |
| if (!waitingList.isEmpty() && admissionList.size() < CAPACITATE_MAXIMA) { | |
| Student promovat = waitingList.dequeue(); | |
| promovat.setFinalist( true ); | |
| admissionList.enqueue(promovat); | |
| System.out.println(promovat.getName() + " has been promoted from Waiting List, and is now a finalist\n"); | |
| return promovat; | |
| } | |
| return null; | |
| } | |
| public void selecteazaFinalisti() { | |
| for (Student s : admissionList) { | |
| s.setFinalist(true); | |
| } | |
| } | |
| // calculates the average of all the evaluations received by a student's project | |
| private double calculeazaScorFinal(Student s) { | |
| double suma = 0; | |
| int count = 0; | |
| for (Evaluation e : listaEvaluari) { | |
| if (e.getProiect() == s.getProiect()) { | |
| suma += e.calculeazaMedie(); | |
| count++; | |
| } | |
| } | |
| return count == 0 ? 0.0 : suma / count; | |
| } | |
| // ===== Ranking + acordare automata de premii (Competition Results) ===== | |
| public void assignPrizes() { | |
| System.out.println("\n\n========================Finalists Summary================\n"); | |
| List<Student> finalisti = new ArrayList<>(); | |
| for (Student s : admissionList) { | |
| if (s.isFinalist()) { | |
| s.setScorFinal(calculeazaScorFinal(s)); | |
| finalisti.add(s); | |
| } | |
| } | |
| // sortare descrescatoare dupa scorul final | |
| finalisti.sort((a, b) -> Double.compare(b.getScorFinal(), a.getScorFinal())); | |
| for (int i = 0; i < finalisti.size(); i++) { | |
| Student s = finalisti.get(i); | |
| Award award; | |
| switch (i) { | |
| case 0 -> award = new Award(1, "Research Champion, Gold Certificate", 500); | |
| case 1 -> award = new Award(2, "Silver Certificate", 300); | |
| case 2 -> award = new Award(3, "Bronze Certificate", 100); | |
| default -> award = new Award(0, "Certificate of Participation", 0); | |
| } | |
| s.receiveAward(award); | |
| } | |
| displayStanding( finalisti ); | |
| } | |
| private void displayStanding(List<Student> finalisti) { | |
| System.out.println("\n===== Competition Results =====\n"); | |
| System.out.printf("%-6s %-15s %-8s %-45s%n", "Poz.", "Student", "Scor", "Award"); | |
| System.out.println("________________________________________________________________________________________"); | |
| for (int i = 0; i < finalisti.size(); i++) { | |
| Student s = finalisti.get(i); | |
| String pozitie = switch (i) { | |
| case 0 -> "1st"; | |
| case 1 -> "2nd"; | |
| case 2 -> "3rd"; | |
| default -> (i + 1) + "th"; | |
| }; | |
| System.out.printf("%-6s %-15s %-8.2f %-45s%n", | |
| pozitie, s.getName(), s.getScorFinal(), s.getAward().toString()); | |
| } | |
| } | |
| public List<Judge> getJudgeList() { return judgeList; } | |
| public List<ResearchProject> getListaProiecte() { return listaProiecte; } | |
| } | |
| // ===================== Main ===================== | |
| public class Main { | |
| public static void main(String[] args) { | |
| // ===== Exemplu simplu de folosire a clasei Queue proprii ===== | |
| System.out.println("===== Demo Queue proprie =====\n"); | |
| Queue<String> queueDemo = new Queue<>(); | |
| queueDemo.enqueue("Ion"); | |
| queueDemo.enqueue("Maria"); | |
| queueDemo.enqueue("Andrei"); | |
| System.out.println("SIZE Queue: " + queueDemo.size()); | |
| System.out.println("First from Queue (peek): " + queueDemo.peek()); | |
| System.out.println("Traversal with for-each (without removing elements):"); | |
| for (String nume : queueDemo) { | |
| System.out.println(" - " + nume); | |
| } | |
| System.out.println("We take out the elements one by one with dequeue():"); | |
| while (!queueDemo.isEmpty()) { | |
| System.out.println(" dequeue -> " + queueDemo.dequeue()); | |
| } | |
| System.out.println("Empty Queue? " + queueDemo.isEmpty()); | |
| System.out.println(); | |
| // ===== Competition system =============================================== | |
| ResearchChampionshipSystem sistem = new ResearchChampionshipSystem(); | |
| System.out.println("===== Register (10 students, capacity finalists = 5) =====\n"); | |
| Student s1 = new Student(StudentIdGenerator.genereazaID(), "Ion", "Ion@mail.com"); | |
| Student s2 = new Student(StudentIdGenerator.genereazaID(), "Maria", "maria@mail.com"); | |
| Student s3 = new Student(StudentIdGenerator.genereazaID(), "Andrei", "andrei@mail.com"); | |
| Student s4 = new Student(StudentIdGenerator.genereazaID(), "Elena", "elena@mail.com"); | |
| Student s5 = new Student(StudentIdGenerator.genereazaID(), "Vlad", "Vlad@mail.com"); | |
| //starts Waiting List=============================================== | |
| Student s6 = new Student(StudentIdGenerator.genereazaID(), "Ana", "ana@mail.com"); | |
| Student s7 = new Student(StudentIdGenerator.genereazaID(), "Radu", "Radu@mail.com"); | |
| Student s8 = new Student(StudentIdGenerator.genereazaID(), "Cristina", "Cristina@mail.com"); | |
| Student s9 = new Student(StudentIdGenerator.genereazaID(), "Dan", "Dan@mail.com"); | |
| Student s10 = new Student(StudentIdGenerator.genereazaID(), "Ioana", "Ioana@mail.com"); | |
| //In this code we test with the eleventh student to catch the exception because we have a restriction ten student allowed only | |
| /* | |
| "Assignment instructions!!!!:A maximum of ten computing students mayregister by submitting an initial research proposal." | |
| */ | |
| /* | |
| try { | |
| Student s11 = new Student( | |
| StudentIdGenerator.genereazaID(), | |
| "NEWSTUDENT", | |
| "newstudent@mail.com" | |
| ); | |
| } catch (IllegalStateException e) { | |
| System.out.println("EXCEPTION CAUGHT: " + e.getMessage()); | |
| } | |
| */ | |
| //the first 5 (FIFO) become finalists, the other 5 enter the waiting list | |
| sistem.registerStudent(s1); | |
| sistem.registerStudent(s2); | |
| sistem.registerStudent(s3); | |
| sistem.registerStudent(s4); | |
| sistem.registerStudent(s5); | |
| sistem.registerStudent(s6); | |
| sistem.registerStudent(s7); | |
| sistem.registerStudent(s8); | |
| sistem.registerStudent(s9); | |
| sistem.registerStudent(s10); | |
| //marks the first 5 (s1...s5) as finalists | |
| sistem.selecteazaFinalisti(); | |
| System.out.println(); | |
| // ----- 2. Creare judecatori ----- | |
| Judge j1 = new Judge(JudgeIdGenerator.genereazaID(), "Popescu", "popescu@mail.com", "JUD-001"); | |
| Judge j2 = new Judge(JudgeIdGenerator.genereazaID(), "Ionescu", "ionescu@mail.com", "JUD-002"); | |
| Judge j3 = new Judge(JudgeIdGenerator.genereazaID(), "Dorel", "dorel@mail.com", "JUD-003"); | |
| Judge j4 = new Judge(JudgeIdGenerator.genereazaID(), "Mitica", "mitica@mail.com", "JUD-004"); | |
| Judge j5 = new Judge(JudgeIdGenerator.genereazaID(), "Lucanu", "lucanu@mail.com", "JUD-005"); | |
| sistem.addJudge( j1 ); | |
| sistem.addJudge( j2 ); | |
| sistem.addJudge( j3 ); | |
| sistem.addJudge( j4 ); | |
| sistem.addJudge( j5 ); | |
| // ===== Example of polymorphism: same method, called by parent type reference ===== | |
| /* | |
| A List<Person> is used to store objects of different subclasses. | |
| Both Student and Judge inherit from the abstract Person class, | |
| therefore their objects can be referenced using the Person type. | |
| This demonstrates upcasting: Student and Judge objects are treated | |
| as Person objects when they are added to the list. | |
| The afiseazaDetalii() method is called through the Person reference. | |
| Java uses dynamic method dispatch to execute the overridden method | |
| belonging to the actual object (Student or Judge). | |
| This allows different types of Person objects to be processed | |
| using the same loop and the same method call. | |
| */ | |
| System.out.println("===== Polymorphism Principle (List<Person>) List of persons and judges =====\n"); | |
| List<Person> persoane = new ArrayList<>(); | |
| persoane.add(s1); // Student object, but retained as Person | |
| persoane.add(s2); // Student object, but retained as Person | |
| persoane.add(s3); // Student object, but retained as Person | |
| persoane.add(s4); // Student object, but retained as Person | |
| persoane.add(s5); // Student object, but retained as Person | |
| persoane.add(s6); // Student object, but retained as Person | |
| persoane.add(s7); // Student object, but retained as Person | |
| persoane.add(s8); // Student object, but retained as Person | |
| persoane.add(s9); // Student object, but retained as Person | |
| persoane.add(s10); // Student object, but retained as Person | |
| persoane.add(j1); // obiect Judge, but retained as Person | |
| persoane.add(j2); // obiect Judge, but retained as Person | |
| persoane.add(j3); //obiect Judge, but retained as Person | |
| persoane.add(j4); //obiect Judge, but retained as Person | |
| persoane.add(j5); //obiect Judge, but retained as Person | |
| /* | |
| for (Person persoana : persoane) { | |
| persoana.displayDetails(); | |
| } | |
| System.out.println(); | |
| */ | |
| // Studentii | |
| System.out.println("===== List of students admitted =====\n"); | |
| for (int i = 0; i < 10; i++) { | |
| persoane.get(i).displayDetails(); | |
| } | |
| // Judecatorii | |
| System.out.println("\n===== List of judges for Research Project =====\n"); | |
| for (int i = 10; i < persoane.size(); i++) { | |
| persoane.get(i).displayDetails(); | |
| } | |
| System.out.println(); | |
| // ----- 3. Project submission: 4 valid, 1 invalid (s3) ----- | |
| // Each valid project has 4 content sections totaling > 5000 words. | |
| // The invalid project (p3invalid) has very short sections, below the minimum threshold. | |
| System.out.println("===== Submission And Validation =====\n"); | |
| ResearchProject p1 = new ResearchProject( | |
| "Artificial Intelligence in Education", | |
| TextGenerator.generate(1300), // Abstract | |
| TextGenerator.generate(1300), // Research Methodology | |
| TextGenerator.generate(1300), // Potential Outcomes | |
| TextGenerator.generate(1300)); // Research Novelty | |
| ResearchProject p2 = new ResearchProject( | |
| "Renewable Energy Storage Systems", | |
| TextGenerator.generate(1300), | |
| TextGenerator.generate(1300), | |
| TextGenerator.generate(1300), | |
| TextGenerator.generate(1300)); | |
| ResearchProject p3invalid = new ResearchProject( | |
| "Project Incomplete", | |
| TextGenerator.generate(100), | |
| TextGenerator.generate(100), | |
| TextGenerator.generate(100), | |
| TextGenerator.generate(100)); // total 400 words -> invalid | |
| ResearchProject p4 = new ResearchProject( | |
| "Analysis of Big Data in HealthCare", | |
| TextGenerator.generate(1300), | |
| TextGenerator.generate(1300), | |
| TextGenerator.generate(1300), | |
| TextGenerator.generate(1300)); | |
| ResearchProject p5 = new ResearchProject( | |
| "System Navigation Optimization", | |
| TextGenerator.generate(1300), | |
| TextGenerator.generate(1300), | |
| TextGenerator.generate(1300), | |
| TextGenerator.generate(1300)); | |
| sistem.submitProiectFinalist(s1, p1); | |
| sistem.submitProiectFinalist(s2, p2); | |
| // s3 Failed | |
| Student promovat = sistem.submitProiectFinalist(s3, p3invalid); | |
| sistem.submitProiectFinalist(s4, p4); | |
| sistem.submitProiectFinalist(s5, p5); | |
| //the promoted student must to enter a project | |
| if (promovat != null) { | |
| ResearchProject pReplacer = new ResearchProject( | |
| "Neural Network optimization", | |
| TextGenerator.generate(1300), | |
| TextGenerator.generate(1300), | |
| TextGenerator.generate(1300), | |
| TextGenerator.generate(1300)); | |
| sistem.submitProiectFinalist(promovat, pReplacer); | |
| } | |
| System.out.println("\n===== PROJECTS OF THE 5 FINALISTS =====\n"); | |
| List<ResearchProject> projects = sistem.getListaProiecte(); | |
| for (int i = 0; i < projects.size(); i++) { | |
| System.out.println("----- Project " + (i + 1) + " -----"); | |
| projects.get(i).displayDetails(); | |
| System.out.println(); | |
| } | |
| System.out.println(); | |
| // -----> Evaluation: each ACCEPTED project is evaluated by both judges ----- | |
| // Input: different scores per project, to get a real ranking (not all equal) | |
| // Order of accepted projects: Ion, Maria, Elena, Vlad, Ana(promoted) | |
| List<Student> finalisti = new ArrayList<>(); | |
| finalisti.add(s1); // Ion | |
| finalisti.add(s2); // Maria | |
| finalisti.add(s4); // Elena | |
| finalisti.add(s5); // Vlad | |
| finalisti.add(promovat); // Ana | |
| System.out.println("===== Evaluation of Accepted Projects =====\n"); | |
| int[][] scoruriJudecator1 = { | |
| {10, 9, 10}, // Ion -> media 9.67 | |
| { 9, 8, 9}, // Maria -> media 8.67 | |
| { 7, 7, 7}, // Elena -> media 7.00 | |
| { 6, 6, 7}, // Vlad -> media 6.33 | |
| { 8, 8, 8} // Ana -> media 8.00 | |
| }; | |
| displayTresor("Judge1",scoruriJudecator1, finalisti); | |
| int[][] scoruriJudecator2 = { | |
| { 9, 10, 9}, // Ion -> media 9.33 | |
| { 8, 9, 8}, // Maria -> media 8.33 | |
| { 7, 6, 7}, // Elena -> media 6.67 | |
| { 6, 7, 6}, // Vlad -> media 6.33 | |
| { 8, 7, 8} // Ana -> media 7.67 | |
| }; | |
| System.out.println(); | |
| displayTresor("Judge2", scoruriJudecator2, finalisti); | |
| int[][] scoruriJudecator3 = { | |
| {10, 9, 10}, // | |
| { 9, 8, 9}, // | |
| { 7, 7, 7}, // | |
| { 6, 6, 7}, // | |
| { 8, 8, 8} // | |
| }; | |
| System.out.println(); | |
| displayTresor("Judge3", scoruriJudecator3, finalisti); | |
| int[][] scoruriJudecator4 = { | |
| {10, 9, 10}, | |
| { 9, 8, 9}, | |
| { 7, 7, 7}, | |
| { 6, 6, 7}, | |
| { 8, 8, 8} | |
| }; | |
| displayTresor("Judge4",scoruriJudecator4, finalisti); | |
| int[][] scoruriJudecator5 = { | |
| {8, 9, 9}, | |
| { 5, 6, 9}, | |
| { 7, 5, 7}, | |
| { 6, 9, 5}, | |
| { 5, 8, 10} | |
| }; | |
| displayTresor("Judge5",scoruriJudecator5, finalisti); | |
| List<ResearchProject> acceptedProjects = sistem.getListaProiecte(); | |
| for (int i = 0; i < acceptedProjects.size(); i++) { | |
| ResearchProject acceptedProject = acceptedProjects.get(i); | |
| sistem.carriedOutEval(j1, acceptedProject, scoruriJudecator1[i]); | |
| sistem.carriedOutEval(j2, acceptedProject, scoruriJudecator2[i]); | |
| sistem.carriedOutEval(j3, acceptedProject, scoruriJudecator3[i]); | |
| sistem.carriedOutEval(j4, acceptedProject, scoruriJudecator4[i]); | |
| sistem.carriedOutEval(j5, acceptedProject, scoruriJudecator5[i]); | |
| System.out.println("______________________________________________________________________________________________"); | |
| } | |
| sistem.assignPrizes(); | |
| } | |
| /* | |
| ///column StudentID | |
| public static void displayTresor(String numeJudecator, | |
| int[][] scoruri) { | |
| System.out.println( | |
| numeJudecator + "" | |
| ); | |
| System.out.printf("%-10s %-10s %-15s %-20s %-15s%n", | |
| "StudentID", | |
| "Project", | |
| "Originality", | |
| "Technical Quality", | |
| "Presentation"); | |
| for (int i = 0; i < scoruri.length; i++) { | |
| System.out.printf("%-10d %-10d %-15d %-20d %-15d%n", | |
| i, | |
| i + 1, | |
| scoruri[i][0], | |
| scoruri[i][1], | |
| scoruri[i][2]); | |
| } | |
| System.out.println(); | |
| } | |
| */ | |
| public static void displayTresor(String numeJudecator, | |
| int[][] scoruri, | |
| List<Student> finalisti) { | |
| System.out.println(numeJudecator); | |
| System.out.printf("%-15s %-10s %-15s %-20s %-15s%n", | |
| "StudentID", | |
| "Project", | |
| "Originality", | |
| "Technical Quality", | |
| "Presentation"); | |
| for (int i = 0; i < scoruri.length; i++) { | |
| Student student = finalisti.get(i); | |
| System.out.printf("%-15s %-10d %-15d %-20d %-15d%n", | |
| student.getId(), // ID-ul ORIGINAL | |
| i + 1, // numarul proiectului | |
| scoruri[i][0], | |
| scoruri[i][1], | |
| scoruri[i][2]); | |
| } | |
| System.out.println(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment