diff --git a/lib/tp04-res.jar b/lib/tp04-res.jar new file mode 100755 index 0000000000000000000000000000000000000000..4088fda2baee4ed5f221ddd3c9999890d7f2637f Binary files /dev/null and b/lib/tp04-res.jar differ diff --git a/src/tp1/Book.java b/src/tp1/Book.java new file mode 100755 index 0000000000000000000000000000000000000000..228db32c7380ec90d9fada31a666587589bf7489 --- /dev/null +++ b/src/tp1/Book.java @@ -0,0 +1,38 @@ +package tp1; + +class Book { + // class attributes + String author; + String title; + int year; + // constructor + Book(String author, String title, int year) { + this.author = author; + this.title = title; + this.year = year; + } + // methods + String getAuthor() { + return this.author; + } + String getTitle() { + return this.title; + } + String print() { + return author + "\t" + title + "\t" + year; + } +} + +class UseBook{ + public static void main(String[] args){ + Book[] biblio = { + new Book("Edwin A. Abbott", "Flatland", 1884), + new Book("Edwin A. Abbott", "Flatland", 1885), + new Book("Edwin A. Abbott", "Flatland", 1886) + }; + + for (int i = 0; i < biblio.length; i = i + 1) { + System.out.println(biblio[i].print()); + } + } +} \ No newline at end of file diff --git a/src/tp1/Irregular.java b/src/tp1/Irregular.java new file mode 100755 index 0000000000000000000000000000000000000000..93cbf3c1663108415e56e82d42baf5bc43fc7865 --- /dev/null +++ b/src/tp1/Irregular.java @@ -0,0 +1,41 @@ +package tp1; + +class Irregular{ + + int[][] irregular; + int[] lineSizeTab; + + Irregular(int[] lineSize){ + irregular = new int[lineSize.length][3]; + lineSizeTab = lineSize; + randomFilling(); + } + + void randomFilling(){ + for (int i = 0; i < irregular.length; i = i + 1) { + for(int id = 0; id < lineSizeTab[i]; id++){ + irregular[i][id] = (int)(Math.random() * 10); + } + } + } + + String display(){ + String res = ""; + for (int i = 0; i < irregular.length; i = i + 1) { + for(int id = 0; id < lineSizeTab[i]; id++){ + res = res + String.valueOf(irregular[i][id]); + } + res = res + "\n"; + } + + return res; + } + +} + +class UseIrregular{ + public static void main(String[] args){ + Irregular irr = new Irregular(new int[]{3, 2, 3}); + System.out.println(irr.display()); + } +} \ No newline at end of file diff --git a/src/tp1/Parameter.java b/src/tp1/Parameter.java new file mode 100755 index 0000000000000000000000000000000000000000..81f18ff7d94c4a9c7a66f520b0ab949a089913d6 --- /dev/null +++ b/src/tp1/Parameter.java @@ -0,0 +1,12 @@ +package tp1; + +class Parameter { + public static void main(String[] args) { + if(args.length==0) { + System.out.println("No parameter"); + } + for(int i=0; i<args.length; i++) { + System.out.println("(" + (i+1) + ") " + args[i]); + } + } +} diff --git a/src/tp2/Competitor.java b/src/tp2/Competitor.java new file mode 100755 index 0000000000000000000000000000000000000000..de1ebcabd1827862d20e62464021a22e15cfb87b --- /dev/null +++ b/src/tp2/Competitor.java @@ -0,0 +1,39 @@ +class Competitor{ + int numberSign; + int score; + int min; + int sec; + + Competitor(int numberSign, int score, int min, int sec){ + if(numberSign > 100 || numberSign < 1){ + numberSign = -1; + } + if(score > 60 || score < 0){ + score = -1; + } + this.numberSign = numberSign; + this.score = score; + this.min = min; + this.sec = sec; + } + + String display(){ + return "[No"+String.valueOf(numberSign)+","+String.valueOf(score)+"points,"+(sec+min*60)+" s]"; + } +} + +class Main{ + public static void main(String[] args){ + + Competitor[] competitorTab = new Competitor[100]; + competitorTab[0] = new Competitor(1,45,15,20); + competitorTab[1] = new Competitor(2,32,12,45); + competitorTab[2] = new Competitor(5,12,13,59); + competitorTab[3] = new Competitor(12,12,15,70); + competitorTab[4] = new Competitor(32,75,15,20); + + System.out.println(competitorTab[0].display()); + System.out.println(competitorTab[1].display()); + System.out.println(competitorTab[2].display()); + } +} \ No newline at end of file diff --git a/src/tp2/Dice.java b/src/tp2/Dice.java new file mode 100755 index 0000000000000000000000000000000000000000..9b5b8db8e6b87a7cbcbb2a353944df7abe3b12f5 --- /dev/null +++ b/src/tp2/Dice.java @@ -0,0 +1,155 @@ +class Dice{ + int numberSides; + double rand = 0; + int value = 1; + + Dice(int numberSides) { + this.numberSides = numberSides; + + if(this.numberSides <= 0) { + this.numberSides = 1; + } + } + + void roll(){ + this.rand = Math.random() * numberSides; + this.value = (int)this.rand; + } + + String display(){ + return "Dice(" + numberSides+ "faces, " + rand+ " rand, "+this.value+" choisi)"; + } + + int getValue(){ + return this.value; + } +} + +class DicePlayer{ + String name; + int totalValue = 0; + int nbDiceRolls = 0; + + DicePlayer(String name){ + this.name = name; + } + + + void play(Dice dice6){ + dice6.roll(); + this.totalValue = this.totalValue + dice6.getValue(); + this.nbDiceRolls++; + } + + int getTotalValue(){ + return this.totalValue; + } + + int getNbDiceRolls(){ + return this.nbDiceRolls; + } + + + String displayPlayer(){ + return this.name+": "+this.totalValue+" points en "+this.nbDiceRolls+" coups."; + } +} + + +class OneDicePlayerGame{ + public static void main(String[] args){ + NDicePlayerGame game = new NDicePlayerGame(10); + /* + DicePlayer dicePlayer = new DicePlayer("Cyprien"); + while(dicePlayer.getTotalValue() < 20){ + Dice dice = new Dice(6); + + dicePlayer.play(dice); + System.out.println(dice.display()); + + } + System.out.println(dicePlayer.displayPlayer()); + + DicePlayer dicePlayer2 = new DicePlayer("Gabin"); + while(dicePlayer2.getTotalValue() < 20){ + Dice dice = new Dice(6); + + dicePlayer2.play(dice); + System.out.println(dice.display()); + + } + System.out.println(dicePlayer2.displayPlayer()); + + TwoDicePlayerGame twoDicePlayerGame = new TwoDicePlayerGame(dicePlayer, dicePlayer2); + System.out.println(twoDicePlayerGame.winner().displayPlayer()+" winner"); + */ + } +} + +class TwoDicePlayerGame{ + DicePlayer dicePlayer1; + DicePlayer dicePlayer2; + + TwoDicePlayerGame(DicePlayer dicePlayer1, DicePlayer dicePlayer2){ + this.dicePlayer1 = dicePlayer1; + this.dicePlayer2 = dicePlayer2; + } + + DicePlayer winner(){ + if(dicePlayer1.getTotalValue() > 20 && dicePlayer2.getTotalValue() > 20){ + if(dicePlayer1.getNbDiceRolls() < dicePlayer2.getNbDiceRolls()){ + return dicePlayer1; + }else if(dicePlayer1.getNbDiceRolls() > dicePlayer2.getNbDiceRolls()){ + return dicePlayer2; + }else{ + if(dicePlayer1.getTotalValue() > dicePlayer2.getTotalValue()){ + return dicePlayer1; + }else if(dicePlayer1.getTotalValue() > dicePlayer2.getTotalValue()){ + return dicePlayer2; + }else{ + return null; + } + } + }else{ + if(dicePlayer1.getTotalValue() > dicePlayer2.getTotalValue()){ + return dicePlayer1; + }else if(dicePlayer1.getTotalValue() > dicePlayer2.getTotalValue()){ + return dicePlayer2; + }else{ + return null; + } + } + } +} + +class NDicePlayerGame{ + DicePlayer[] players; + + NDicePlayerGame(int nbPlayer){ + players = new DicePlayer[nbPlayer]; + int i = 0; + while(i < players.length){ + players[i] = new DicePlayer(String.valueOf(i)); + while(players[i].getTotalValue() < 20){ + Dice dice = new Dice(6); + + players[i].play(dice); + System.out.println(dice.display()); + } + System.out.println(players[i].displayPlayer()); + i++; + } + /* + + DicePlayer[] winners = winners(); + + for (int place = 0; place < 3; i++){ + System.out.println(place+"- "+winners[place].displayPlayer()); + }*/ + + } +/* + DicePlayer[] winner(){ + return Arrays.sort(players.displayPlayer()); + }*/ +} \ No newline at end of file diff --git a/src/tp3/Card.java b/src/tp3/Card.java new file mode 100755 index 0000000000000000000000000000000000000000..7635c6bdafa8c369501d8741c4dd678b605507fa --- /dev/null +++ b/src/tp3/Card.java @@ -0,0 +1,65 @@ +package tp3; +import tp3.Rank; +import tp3.Color; +import java.util.Arrays; + +public class Card { + private Color color; + private Rank rank; + + public Color getColor() { + return color; + } + + public Rank getRank() { + return rank; + } + + public String toString() { + return this.color+" "+this.rank; + } + + public Card(Color color, Rank rank){ + this.rank=rank; + this.color=color; + } + + public Card(String color, String rank){ + this.rank=Rank.valueOf(rank); + this.color=Color.valueOf(color); + } + + + public boolean equals(Card carte){ + if (this.rank==carte.rank && this.color==carte.color){ + return true; + } + return false; + } + + public boolean isBefore(Card carte){ + if (this.rank.ordinal()<carte.rank.ordinal()){ + return true; + } + return false; + } + + public int compareRank(Card carte){ + if (this.rank.ordinal()<carte.rank.ordinal()){ + return -1; + }else if (this.rank.ordinal()==carte.rank.ordinal()){ + return 0; + } + return 1; + } + + public int compareColor(Card carte){ + if (this.color.ordinal()<carte.color.ordinal()){ + return -1; + }else if (this.color.ordinal()==carte.color.ordinal()){ + return 0; + } + return 1; + } + +} diff --git a/src/tp3/Color.java b/src/tp3/Color.java new file mode 100755 index 0000000000000000000000000000000000000000..113a4003c4574c9587ee7cf544b1081f078a5f3a --- /dev/null +++ b/src/tp3/Color.java @@ -0,0 +1,5 @@ +package tp3; + +public enum Color { + CLUB, DIAMOND, HEART, SPADE; +} \ No newline at end of file diff --git a/src/tp3/Rank.java b/src/tp3/Rank.java new file mode 100755 index 0000000000000000000000000000000000000000..99afc174eea2dd7792d00777e7c082d6e9892ec7 --- /dev/null +++ b/src/tp3/Rank.java @@ -0,0 +1,5 @@ +package tp3; + +public enum Rank { + SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE; +} diff --git a/src/tp3/Task.java b/src/tp3/Task.java new file mode 100755 index 0000000000000000000000000000000000000000..84c8e85ae2ef2b674bb02fc6e5209e152de3e7e3 --- /dev/null +++ b/src/tp3/Task.java @@ -0,0 +1,86 @@ +package tp3; +import tp3.TaskStatus; +import java.time.LocalDate; +import java.time.Period; + +public class Task { + private String idTask; + private LocalDate creationDate; + private LocalDate deadline; + private TaskStatus state; + private String description; + private int duration; + + private static int counter = 0; + + public void Task(String description, int duration){ + this.description=description; + this.duration=duration; + this.creationDate=LocalDate.now(); + this.state=TaskStatus.TODO; + this.deadline=creationDate.plusDays(duration); + counter++; + this.idTask= String.valueOf(LocalDate.now().getYear()).substring(String.valueOf(LocalDate.now().getYear()).length() - 2, String.valueOf(LocalDate.now().getYear()).length()) + +String.valueOf(LocalDate.now().getMonth()) + String.valueOf(counter); + } + + public void Task(String description, LocalDate creation, LocalDate deadline, int duration){ + this.description=description; + this.creationDate=creation; + this.deadline=deadline; + this.duration=duration; + this.state=TaskStatus.TODO; + counter++; + this.idTask= String.valueOf(LocalDate.now().getYear()).substring(String.valueOf(LocalDate.now().getYear()).length() - 2, String.valueOf(LocalDate.now().getYear()).length()) + +String.valueOf(LocalDate.now().getMonth()) + String.valueOf(counter); + } + + public String toString() { + return "(T"+idTask+" = "+description+":"+state+"("+duration+")"+" :"+deadline; + } + + void changeStatus(TaskStatus st){ + this.state=st; + } + + void changeStatus(char c){ + if (c=='T'){ + this.state=TaskStatus.TODO; + }else if (c=='O'){ + this.state=TaskStatus.ONGOING; + }else if (c=='D'){ + this.state=TaskStatus.DELAYED; + }else if (c=='F'){ + this.state=TaskStatus.FINISHED; + } + } + + void changeStatus(){ + int index=this.state.ordinal(); + this.state=TaskStatus.values()[(index+1)%TaskStatus.values().length]; + } + + boolean isLate(){ + Period period=LocalDate.now().until(this.deadline); + if(period.isNegative()){ + return true; + } + return false; + } + + void delay(int nbDays){ + this.deadline=this.deadline.plusDays(nbDays); + } + + LocalDate getDeadline(){ + return this.deadline; + } + + LocalDate getCreationDate(){ + return this.creationDate; + } + + Period getDuration(){ + return this.creationDate.until(this.deadline); + } +} \ No newline at end of file diff --git a/src/tp3/TaskStatus.java b/src/tp3/TaskStatus.java new file mode 100755 index 0000000000000000000000000000000000000000..a043094f48bd0128297033328314bf8848154ef7 --- /dev/null +++ b/src/tp3/TaskStatus.java @@ -0,0 +1,5 @@ +package tp3; + +public enum TaskStatus { + TODO, ONGOING, DELAYED, FINISHED; +} diff --git a/src/tp3/ToDoList.java b/src/tp3/ToDoList.java new file mode 100755 index 0000000000000000000000000000000000000000..6328dc77c71502f88dc3f12a9e160d5fe5e98fb5 --- /dev/null +++ b/src/tp3/ToDoList.java @@ -0,0 +1,68 @@ +package tp3; +import java.util.*; +import java.time.LocalDate; + +public class ToDoList { + private List<Task> chores = new ArrayList<Task>(); + + public void ToDoList(){ + + } + + public String toString(){ + return ""+this.chores; + } + + void addTask(Task aTask){ + chores.add(aTask); + } + + void removeTask(int i){ + chores.remove(i); + } + + void removeTask(Task aTask){ + int i = chores.indexOf(aTask); + chores.remove(i); + } + + boolean isOverwhelmed(){ + if(chores.get(chores.size() - 1) == null){ + return false; + } + + return true; + } + + int getNbTask(){ + return chores.size(); + } + + void onSickLeave(int nbDays){ + for (int ind = 0; ind < chores.size(); ind = ind + 1) { + chores.get(ind).delay(nbDays); + } + } + + + List<Task> dueTasks(){ + List<Task> res = new ArrayList<Task>(); + for (int ind = 0; ind < chores.size(); ind = ind + 1) { + if(chores.get(ind).getDeadline() == LocalDate.now()){ + res.add(chores.get(ind)); + } + } + + return res; + } + +/* + void durationSort(){ + chores.sort((Task o1, Task o2)->o1.getDuration().getDays().compareTo(o2.getDuration().getDays())); + } + + void senioritySort(){ + chores.sort((Task o1, Task o2)->o1.getCreationDate().compareTo(o2.getCreationDate())); + }*/ + +} diff --git a/src/tp3/UseCard.java b/src/tp3/UseCard.java new file mode 100755 index 0000000000000000000000000000000000000000..c1337f8dda16829cf91c5cf3975124cf927e2a59 --- /dev/null +++ b/src/tp3/UseCard.java @@ -0,0 +1,18 @@ +package tp3; +import tp3.Card; +import tp3.Color; +import tp3.Rank; + +public class UseCard { + public static void main(String[] args){ + Card c1 = new Card("CLUB", "NINE"); + Card c2 = new Card(Color.SPADE, Rank.ACE); + System.out.println(c1.getColor()); + System.out.println(c2.getRank()); + System.out.println(c1.compareColor(c2)); + System.out.println(c1.compareRank(c2)); + System.out.println(c1.isBefore(c2)); + System.out.println(c1.equals(c2)); + System.out.println(c1.toString()); + } +} diff --git a/src/tp3/UseLocalDate.java b/src/tp3/UseLocalDate.java new file mode 100755 index 0000000000000000000000000000000000000000..d663a4ce2c00ce39be85081b296a6cf9b51bc439 --- /dev/null +++ b/src/tp3/UseLocalDate.java @@ -0,0 +1,56 @@ +package tp3; +import java.time.LocalDate; +import java.time.Period; +import java.util.Scanner; + +public class UseLocalDate { + + public static String dateOfTheDay(){ + return "Today's date "+LocalDate.now(); + } + + public static LocalDate inputDate(){ + Scanner input = new Scanner(System.in); // Create a Scanner object + + System.out.println("Enter day"); + int day = input.nextInt(); + if(day < 1){ + day = 1; + }else{ + if(day > 31){ + day = 31; + } + } + + System.out.println("Enter month"); + int month = input.nextInt(); + if(month < 1){ + month = 1; + }else{ + if(month > 12){ + month = 12; + } + } + + System.out.println("Enter year"); + int year = input.nextInt(); + if(year < 0){ + year = 0; + } + + return LocalDate.of(year, month, day); + } + + public static String diffDate(){ + LocalDate date1=inputDate(); + LocalDate date2=inputDate(); + Period period=date1.until(date2); + return period.toString(); + } + + public static void main(String[] args){ + System.out.println(dateOfTheDay()); + System.out.println(inputDate().toString()); + System.out.println(diffDate()); + } +} diff --git a/src/tp4/PendingCaseQueue.java b/src/tp4/PendingCaseQueue.java new file mode 100755 index 0000000000000000000000000000000000000000..bd9a6996d31ddd3fa153b5e9657e5fd52099daed --- /dev/null +++ b/src/tp4/PendingCaseQueue.java @@ -0,0 +1,86 @@ +package tp4; +import tpOO.tp04.*; + +public class PendingCaseQueue{ + public final static int CAPACITY = 10; + + int id; + + PendingCase[] pendingCases; + + PendingCaseQueue(){ + pendingCases = new PendingCase[CAPACITY]; + + } + + void clear(){ + pendingCases = new PendingCase[CAPACITY]; + } + + boolean isEmpty(){ + if(pendingCases[0]==null){ + return true; + } + return false; + } + + boolean isFull(){ + if(pendingCases.length == CAPACITY){ + return true; + } + return false; + } + + int size(){ + return pendingCases.length; + } + + void addOne(PendingCase other){ + if(isFull()){ + System.out.println("impossible"); + }else{ + PendingCase[] before = pendingCases; + PendingCase[] newGrade = new PendingCase[pendingCases.length + 1]; + + for (int notes = 0; notes < before.length; notes = notes + 1) { + newGrade[notes] = before[notes]; + } + + newGrade[newGrade.length] = other; + + pendingCases = newGrade; + } + } + + PendingCase removeOne(){ + if(isEmpty()){ + return null; + }else{ + PendingCase[] before = pendingCases; + PendingCase[] newGrade = new PendingCase[pendingCases.length - 1]; + + for (int notes = 0; notes < before.length - 1; notes = notes + 1) { + newGrade[notes] = before[notes]; + } + + pendingCases = newGrade; + } + + return null; + } + + + public String toString(){ + String res = ""; + for (int name = 0; name < pendingCases.length; name++) { + if(pendingCases[name] != null){ + res = res + pendingCases[name]+"\n"; + }else{} + + } + + return res; + } + + +} \ No newline at end of file diff --git a/src/tp4/Person.java b/src/tp4/Person.java new file mode 100755 index 0000000000000000000000000000000000000000..34e4c0a55ccd1aa1b6ea163eb7253e1e16bea9f8 --- /dev/null +++ b/src/tp4/Person.java @@ -0,0 +1,59 @@ +package tp4; + +public class Person{ + private static int ID = -1; //pour être à 0 sur la première assignation + private String forename; + private String name; + + public Person(String forename, String name){ + this.forename = forename; + this.name = name; + ID++; //assignation automatique + } + + +//getters + + int getID() { + return this.ID; + } + + String getForename(){ + return this.forename; + } + + String getName(){ + return this.name; + } + + +//setters + void setName(String name){ + this.name = name; + } + + void setForename(String forename){ + this.forename = forename; + } + + public String toString(){ + return getID()+":"+getForename()+" "+getName(); + } + + + + public boolean equals(Object obj) { + if(this == obj) return true; + if(obj == null) return false; + if(getClass() != obj.getClass()) return false; + Person other = (Person) obj; + if(ID != other.ID) return false; + if (name == null) { + if (other.name != null) return false; + } else if (!name.equals(other.name)) return false; + if (forename == null) { + if (other.forename != null) return false; + } else if (!forename.equals(other.forename)) return false; + return true; + } +} \ No newline at end of file diff --git a/src/tp4/Student.java b/src/tp4/Student.java new file mode 100755 index 0000000000000000000000000000000000000000..681ee8b938e893dad3ccb80f04e0f67ca38ab108 --- /dev/null +++ b/src/tp4/Student.java @@ -0,0 +1,80 @@ +package tp4; +import tp4.Person; + +public class Student{ + private double[] grades; + private Person person; + + Student(Person pers, double[] grades){ + this.person = pers; + this.grades = grades; + } + + Student(String forename, String name, double[] grades){ + this(forename, name); + this.grades = grades; + } + + private Student(String forename, String name){ + person = new Person(forename, name); + } + + int getID() { + return person.getID(); + } + + String getForename(){ + return person.getForename(); + } + + String getName(){ + return person.getName(); + } +/* + double[] getGrade(){ + return thid.grades; + }*/ + + void setName(String name){ + person.setName(name); + } + + void setForename(String forename){ + person.setForename(forename); + } + + + double getAverage(){ + if(this.grades.length == 0) return 0.0; + double total = 0; + for (int notes = 0; notes < this.grades.length; notes = notes + 1) { + total = total + this.grades[notes]; + } + + return total/this.grades.length; + } + + public String toString(){ + String res; + res = "Student["+getID()+":"+ getForename()+" "+getName()+" = ["; + for (int notes = 0; notes < this.grades.length; notes = notes + 1) { + res = res + this.grades[notes]+", "; + } + + res = res + "]]"; + + return res; + } + + + void addGrade(double aGrade){ + double[] before = this.grades; + double[] newGrade = new double[this.grades.length + 1]; + + for (int notes = 0; notes < before.length; notes = notes + 1) { + newGrade[notes] = before[notes]; + } + + newGrade[newGrade.length - 1] = aGrade; + } +} \ No newline at end of file diff --git a/src/tp4/StudentAbs.java b/src/tp4/StudentAbs.java new file mode 100755 index 0000000000000000000000000000000000000000..64f803b772a9bfa340b5d5b15cbbe82d566a1f0d --- /dev/null +++ b/src/tp4/StudentAbs.java @@ -0,0 +1,30 @@ +package tp4; +import tp4.Student; + +public class StudentAbs{ + public Student student; + private int nbAbsence; + + StudentAbs(Student student, int nbAbsence){ + this.student = student; + this.nbAbsence = nbAbsence; + } + + public String toString(){ + return student.toString()+" nbAbs="+nbAbsence; + } + + boolean warning(int thresholdAbs, double thresholdAvg){ + if(thresholdAbs <= nbAbsence) return true; + if(student.getAverage() <= thresholdAvg) return true; + + return false; + } + + + boolean validation(int thresholdAbs, double thresholdAvg){ + if(thresholdAbs >= nbAbsence && student.getAverage() >= thresholdAvg) return true; + + return false; + } +} \ No newline at end of file diff --git a/src/tp4/UsePendingCaseQueue.java b/src/tp4/UsePendingCaseQueue.java new file mode 100755 index 0000000000000000000000000000000000000000..665a3bb743ede15125987c7c29e1041fb95ea09c --- /dev/null +++ b/src/tp4/UsePendingCaseQueue.java @@ -0,0 +1,31 @@ +package tp4; +import tpOO.tp04.PendingCase; + +public class UsePendingCaseQueue { + public static void main(String[] args) { + PendingCase pc1 = new PendingCase("Alice", "AAA", 1234.56); + PendingCase pc2 = new PendingCase("Bruno", "BBB", 0.42); + PendingCase pc3 = new PendingCase("Chloé", "CCC", 745.99); + PendingCase pc4 = new PendingCase("Denis", "DDD", 125.0); + + //PendingCaseQueue.CAPACITY = 3; + PendingCaseQueue pcq = new PendingCaseQueue(); + System.out.println("Before anything: " + pcq); + System.out.println("Empty? " + pcq.isEmpty() + "\tFull? " + pcq.isFull()); + pcq.addOne(pc1); + pcq.addOne(pc2); + System.out.println("After addition of pc1 and pc2: " + pcq); + System.out.println("Empty? " + pcq.isEmpty() + "\tFull? " + pcq.isFull()); + pcq.addOne(pc3); + System.out.println("After addition of pc3: " + pcq); + System.out.println("Empty? " + pcq.isEmpty() + "\tFull? " + pcq.isFull()); + pcq.addOne(pc4); + System.out.println("After addition of pc4: \t" + pcq); + pcq.removeOne(); + System.out.println("After a removal: " + pcq); + pcq.addOne(pc1); + System.out.println("After addition of pc1: " + pcq); + pcq.clear(); + System.out.println("After clearing: " + pcq); + } +} diff --git a/src/tp4/UsePerson.java b/src/tp4/UsePerson.java new file mode 100755 index 0000000000000000000000000000000000000000..949f44535bf1a959daa45b50ed797eb8616b0e8a --- /dev/null +++ b/src/tp4/UsePerson.java @@ -0,0 +1,28 @@ +package tp4; + +public class UsePerson { + public static void main(String[] args) { + Person alice = new Person("Alice", "A"); + Person bruno = new Person("Bruno", "B"); + Person autre = alice; + boolean testsOK = true; + // test des getters + if(!alice.getForename().equals("Alice") || !alice.getName().equals("A") || !bruno.getForename().equals("Bruno") || !bruno.getName().equals("B") || !autre.getForename().equals("Alice") || !autre.getName().equals("A")) { + System.out.println("Erreur de méthodes GET"); + testsOK = false; + } + // test des setters + alice.setForename("Anatole"); + bruno.setName("BB"); + if(!alice.getForename().equals("Anatole") || !alice.getName().equals("A") || !bruno.getForename().equals("Bruno") || !bruno.getName().equals("BB") || !autre.getForename().equals("Anatole") || !autre.getName().equals("A")) { + System.out.println("Erreur de méthodes SET"); + testsOK = false; + } + // test du equals + if(alice.equals(bruno) || !alice.equals(autre)) { + System.out.println("Erreur de méthode equals"); + testsOK = false; + } + if(testsOK) System.out.println("Tests de UsePerson réussis !"); + } +} diff --git a/src/tp4/UseStudent.java b/src/tp4/UseStudent.java new file mode 100755 index 0000000000000000000000000000000000000000..07e07564f94bf51fcfa4531f4eafa4fcfbea09e8 --- /dev/null +++ b/src/tp4/UseStudent.java @@ -0,0 +1,20 @@ +package tp4; +import tp4.Student; +import tp4.Person; + +class UseStudent{ + public static void main(String[] args){ + Student a = new Student("A", "a", new double[]{1, 2, 3}); + System.out.println(a.toString()); + System.out.println(a.getAverage()); + + Student b = new Student(new Person("Bruno", "B"), new double[]{1, 2, 3, 4}); + System.out.println(b.toString()); + System.out.println(b.getAverage()); + + + Student c = new Student("C", "c", new double[]{1, 2, 3}); + System.out.println(c.toString()); + System.out.println(c.getAverage()); + } +} \ No newline at end of file diff --git a/src/tp4/UseYearGroup.java b/src/tp4/UseYearGroup.java new file mode 100755 index 0000000000000000000000000000000000000000..f14285ad9906be7a90a5f67e65618d1f2f30c3ff --- /dev/null +++ b/src/tp4/UseYearGroup.java @@ -0,0 +1,8 @@ +package tp4; +import tp4.YearGroup; + +class UseYearGroup{ + public static void main(String[] args){ + + } +} \ No newline at end of file diff --git a/src/tp4/YearGroup.java b/src/tp4/YearGroup.java new file mode 100755 index 0000000000000000000000000000000000000000..843434149f51ab7c456d5a5d03d707ab35e2a5b1 --- /dev/null +++ b/src/tp4/YearGroup.java @@ -0,0 +1,28 @@ +package tp4; +import tp4.Student; + +class YearGroup{ + StudentAbs[] studentAbs; + + YearGroup(StudentAbs[] studentAbs){ + this.studentAbs = studentAbs; + } + + void addGrades(double[] aTest){ + for (int s = 0; s < studentAbs.length; s = s + 1) { + for (int notes = 0; notes < aTest.length; notes = notes + 1) { + studentAbs[s].student.addGrade(aTest[notes]); + } + + } + } + + void validation(int thresholdAbs, int thresholdAvg){ + for (int i = 0; i < studentAbs.length; i = i + 1) { + if(studentAbs[i].validation(thresholdAbs, thresholdAvg)){ + System.out.println(studentAbs[i].toString()); + } + } + } + +} \ No newline at end of file