diff --git a/bin/tp01/Book.class b/bin/tp01/Book.class new file mode 100644 index 0000000000000000000000000000000000000000..2e7802094328dcbda209d5dceaed3ca20fa29888 Binary files /dev/null and b/bin/tp01/Book.class differ diff --git a/bin/tp01/Irregular.class b/bin/tp01/Irregular.class new file mode 100644 index 0000000000000000000000000000000000000000..351b2743023fe9a53ebe52764263d0eba57a33f0 Binary files /dev/null and b/bin/tp01/Irregular.class differ diff --git a/bin/tp01/Parameter.class b/bin/tp01/Parameter.class new file mode 100644 index 0000000000000000000000000000000000000000..8507a36115f81dfd00e14fd38b02e388c9c4984d Binary files /dev/null and b/bin/tp01/Parameter.class differ diff --git a/bin/tp01/RandomSequence.class b/bin/tp01/RandomSequence.class new file mode 100644 index 0000000000000000000000000000000000000000..66821eb2eba02ba6e497e4b8cd9537ff9b8d9f0c Binary files /dev/null and b/bin/tp01/RandomSequence.class differ diff --git a/bin/tp01/UseBook.class b/bin/tp01/UseBook.class new file mode 100644 index 0000000000000000000000000000000000000000..1f63cc464fd16515dde66c16674d0b0aef0cc662 Binary files /dev/null and b/bin/tp01/UseBook.class differ diff --git a/bin/tp01/UseIrregular.class b/bin/tp01/UseIrregular.class new file mode 100644 index 0000000000000000000000000000000000000000..b0122ed22e8551d1a84a3f9980ff6fb25e540562 Binary files /dev/null and b/bin/tp01/UseIrregular.class differ diff --git a/bin/tp02/Competitor.class b/bin/tp02/Competitor.class new file mode 100644 index 0000000000000000000000000000000000000000..7f15ea18b2f9a1069ed510eb17130731c19be4bb Binary files /dev/null and b/bin/tp02/Competitor.class differ diff --git a/bin/tp02/Dice.class b/bin/tp02/Dice.class new file mode 100644 index 0000000000000000000000000000000000000000..9945d9c879110b094e289a851f997c817c915679 Binary files /dev/null and b/bin/tp02/Dice.class differ diff --git a/bin/tp02/DicePlayer.class b/bin/tp02/DicePlayer.class new file mode 100644 index 0000000000000000000000000000000000000000..c0a18bf55ce4f13b748ff4dfc2c0e03fad3f520e Binary files /dev/null and b/bin/tp02/DicePlayer.class differ diff --git a/bin/tp02/NbDicePlayerGame.class b/bin/tp02/NbDicePlayerGame.class new file mode 100644 index 0000000000000000000000000000000000000000..433a6545e15932a5627b7a7b26f037833e251808 Binary files /dev/null and b/bin/tp02/NbDicePlayerGame.class differ diff --git a/bin/tp02/OneDicePlayerGame.class b/bin/tp02/OneDicePlayerGame.class new file mode 100644 index 0000000000000000000000000000000000000000..30a0adbab508671423d65bc1340e9f47233b5ca4 Binary files /dev/null and b/bin/tp02/OneDicePlayerGame.class differ diff --git a/bin/tp02/Read.class b/bin/tp02/Read.class new file mode 100644 index 0000000000000000000000000000000000000000..aa297e753cf056b86e2bbd6fa1e436821c2d4f3c Binary files /dev/null and b/bin/tp02/Read.class differ diff --git a/bin/tp02/TwoDicePlayerGame.class b/bin/tp02/TwoDicePlayerGame.class new file mode 100644 index 0000000000000000000000000000000000000000..d3b661bbebb71eea9251147c120315fd6e6191f8 Binary files /dev/null and b/bin/tp02/TwoDicePlayerGame.class differ diff --git a/bin/tp03/Card.class b/bin/tp03/Card.class new file mode 100644 index 0000000000000000000000000000000000000000..db4a6db5a13687701604baa87172e610da909667 Binary files /dev/null and b/bin/tp03/Card.class differ diff --git a/bin/tp03/Color.class b/bin/tp03/Color.class new file mode 100644 index 0000000000000000000000000000000000000000..3da4b9b124d38c221c206eee1e10d7fb3946c7c8 Binary files /dev/null and b/bin/tp03/Color.class differ diff --git a/bin/tp03/Rank.class b/bin/tp03/Rank.class new file mode 100644 index 0000000000000000000000000000000000000000..00ac76a18f87ef8fdb15fbc0f99fc3f2a6ea2ac5 Binary files /dev/null and b/bin/tp03/Rank.class differ diff --git a/bin/tp03/UseCard.class b/bin/tp03/UseCard.class new file mode 100644 index 0000000000000000000000000000000000000000..df7fdcdb6f39c6e7bd16f83b23772067140efa3a Binary files /dev/null and b/bin/tp03/UseCard.class differ diff --git a/bin/tp03/UseLocalDate.class b/bin/tp03/UseLocalDate.class new file mode 100644 index 0000000000000000000000000000000000000000..bf128a28249422d5b1d9dfb52f786fcef240125c Binary files /dev/null and b/bin/tp03/UseLocalDate.class differ diff --git a/bin/tp04/NumeroAutomatique.class b/bin/tp04/NumeroAutomatique.class new file mode 100644 index 0000000000000000000000000000000000000000..46c6a8b0e86a3f70f077dffe48ec660434dde408 Binary files /dev/null and b/bin/tp04/NumeroAutomatique.class differ diff --git a/bin/tp04/Person.class b/bin/tp04/Person.class new file mode 100644 index 0000000000000000000000000000000000000000..04df7d2cba7cab56ae4459ddbbb04e29d1c55960 Binary files /dev/null and b/bin/tp04/Person.class differ diff --git a/bin/tp04/Student.class b/bin/tp04/Student.class new file mode 100644 index 0000000000000000000000000000000000000000..96fe70c7ec2c6c0de26d2f450ed40671565cb83f Binary files /dev/null and b/bin/tp04/Student.class differ diff --git a/bin/tp04/StudentAbs.class b/bin/tp04/StudentAbs.class new file mode 100644 index 0000000000000000000000000000000000000000..c7e89208f54b9bc409c5147e6347583c414f972c Binary files /dev/null and b/bin/tp04/StudentAbs.class differ diff --git a/bin/tp04/UsePerson.class b/bin/tp04/UsePerson.class new file mode 100644 index 0000000000000000000000000000000000000000..d4fcca8b588dbf16b23b11425258252b906e65d7 Binary files /dev/null and b/bin/tp04/UsePerson.class differ diff --git a/bin/tp04/UseStudent.class b/bin/tp04/UseStudent.class new file mode 100644 index 0000000000000000000000000000000000000000..baa83602ea354287fe118ae2da2df7a528055dad Binary files /dev/null and b/bin/tp04/UseStudent.class differ diff --git a/bin/tp04/UseYearGroup.class b/bin/tp04/UseYearGroup.class new file mode 100644 index 0000000000000000000000000000000000000000..19827b94879675462c0e3570525120056158342a Binary files /dev/null and b/bin/tp04/UseYearGroup.class differ diff --git a/bin/tp04/YearGroup.class b/bin/tp04/YearGroup.class new file mode 100644 index 0000000000000000000000000000000000000000..2339368a6b73708f068712b9cf097f1cac9a790b Binary files /dev/null and b/bin/tp04/YearGroup.class differ diff --git a/bin/tp05/Book.class b/bin/tp05/Book.class new file mode 100644 index 0000000000000000000000000000000000000000..92ddc7f52e8bec29ebf13325b1b85dacaa6ce437 Binary files /dev/null and b/bin/tp05/Book.class differ diff --git a/bin/tp05/ComicBook.class b/bin/tp05/ComicBook.class new file mode 100644 index 0000000000000000000000000000000000000000..7e2ce185f03b74fbe9731f8cca819b4fbf6e154b Binary files /dev/null and b/bin/tp05/ComicBook.class differ diff --git a/bin/tp05/Library.class b/bin/tp05/Library.class new file mode 100644 index 0000000000000000000000000000000000000000..e8e1db513aa85a7755b483f7b127d527e21e579a Binary files /dev/null and b/bin/tp05/Library.class differ diff --git a/bin/tp05/Test.class b/bin/tp05/Test.class new file mode 100644 index 0000000000000000000000000000000000000000..612f300092ac15166a611329c544380b1c9c733e Binary files /dev/null and b/bin/tp05/Test.class differ diff --git a/bin/tp05/UseLibrary.class b/bin/tp05/UseLibrary.class new file mode 100644 index 0000000000000000000000000000000000000000..7cca2623cfb119c49717954558f6b24d11a8ba64 Binary files /dev/null and b/bin/tp05/UseLibrary.class differ diff --git a/bin/tp06/Company.class b/bin/tp06/Company.class new file mode 100644 index 0000000000000000000000000000000000000000..5734a4b63eff7f33f06048db0ad13b7e4e5bd773 Binary files /dev/null and b/bin/tp06/Company.class differ diff --git a/bin/tp06/CompanyTest.class b/bin/tp06/CompanyTest.class new file mode 100644 index 0000000000000000000000000000000000000000..ff38d7ab0aae3bc9201bcb518a0cbe55c460ee9b Binary files /dev/null and b/bin/tp06/CompanyTest.class differ diff --git a/bin/tp06/Employee.class b/bin/tp06/Employee.class new file mode 100644 index 0000000000000000000000000000000000000000..dea97690e58096b5acdaf4273ee51c0dc1675dd5 Binary files /dev/null and b/bin/tp06/Employee.class differ diff --git a/bin/tp06/Salesperson.class b/bin/tp06/Salesperson.class new file mode 100644 index 0000000000000000000000000000000000000000..7cb8e0627d422bdb39d07040a86a9e7a3ae031d1 Binary files /dev/null and b/bin/tp06/Salesperson.class differ diff --git a/bin/tp06/TravellingSalesperson.class b/bin/tp06/TravellingSalesperson.class new file mode 100644 index 0000000000000000000000000000000000000000..a1d4f53a01a3b973a190f8444627bcbd5c35974d Binary files /dev/null and b/bin/tp06/TravellingSalesperson.class differ diff --git a/bin/tp06/Vendor.class b/bin/tp06/Vendor.class new file mode 100644 index 0000000000000000000000000000000000000000..95ad601ef0111c14d841375eff29ae7bd9b9deff Binary files /dev/null and b/bin/tp06/Vendor.class differ diff --git a/bin/tp06/Worker.class b/bin/tp06/Worker.class new file mode 100644 index 0000000000000000000000000000000000000000..3cf6dd1c86074ef04711f489f448cfa9f51ac7c4 Binary files /dev/null and b/bin/tp06/Worker.class differ diff --git a/bin/tp08/Food.class b/bin/tp08/Food.class new file mode 100644 index 0000000000000000000000000000000000000000..995b780b01e65d58aba3a6f72cafa52f42899aa4 Binary files /dev/null and b/bin/tp08/Food.class differ diff --git a/bin/tp08/Furniture.class b/bin/tp08/Furniture.class new file mode 100644 index 0000000000000000000000000000000000000000..1c7e0f97be203844db63e501af39bfcb60839a63 Binary files /dev/null and b/bin/tp08/Furniture.class differ diff --git a/bin/tp08/IProduct.class b/bin/tp08/IProduct.class new file mode 100644 index 0000000000000000000000000000000000000000..a17d8ba345927f98e1c989e9b81fc652b45fcd42 Binary files /dev/null and b/bin/tp08/IProduct.class differ diff --git a/bin/tp08/Shelf.class b/bin/tp08/Shelf.class new file mode 100644 index 0000000000000000000000000000000000000000..e3d454b46e6b9b8705b48525d1c69d350a2bf3ad Binary files /dev/null and b/bin/tp08/Shelf.class differ diff --git a/bin/tp08/Shop.class b/bin/tp08/Shop.class new file mode 100644 index 0000000000000000000000000000000000000000..8f7b4d62db0512920a4f217e29c03ea892da5d36 Binary files /dev/null and b/bin/tp08/Shop.class differ diff --git a/bin/tp08/ShopTest.class b/bin/tp08/ShopTest.class new file mode 100644 index 0000000000000000000000000000000000000000..0998777c6bf61697ffc592f3cab4f25dc900dfc1 Binary files /dev/null and b/bin/tp08/ShopTest.class differ diff --git a/bin/tp08/UseComparable.class b/bin/tp08/UseComparable.class new file mode 100644 index 0000000000000000000000000000000000000000..d60712e3f6353cda5b6f1db400b9d0c9f4252e17 Binary files /dev/null and b/bin/tp08/UseComparable.class differ diff --git a/bin/tp09/LogInManagement.class b/bin/tp09/LogInManagement.class new file mode 100644 index 0000000000000000000000000000000000000000..21fbf3479eef4fafcab54c3b6cfc6582fa35ba33 Binary files /dev/null and b/bin/tp09/LogInManagement.class differ diff --git a/bin/tp09/WrongLengthException.class b/bin/tp09/WrongLengthException.class new file mode 100644 index 0000000000000000000000000000000000000000..bdf3a21509db739e906881dde334e0b712709b56 Binary files /dev/null and b/bin/tp09/WrongLengthException.class differ diff --git a/bin/tp09/WrongPWDException.class b/bin/tp09/WrongPWDException.class new file mode 100644 index 0000000000000000000000000000000000000000..9f17238c16d445cb65fb942b7d957557bfec00be Binary files /dev/null and b/bin/tp09/WrongPWDException.class differ diff --git a/bin/tp09/WrongUserException.class b/bin/tp09/WrongUserException.class new file mode 100644 index 0000000000000000000000000000000000000000..509fd802bf01d5acc509811866e402ea8eac4786 Binary files /dev/null and b/bin/tp09/WrongUserException.class differ diff --git a/lib/hamcrest-core-1.3.jar b/lib/hamcrest-core-1.3.jar new file mode 100644 index 0000000000000000000000000000000000000000..9d5fe16e3dd37ebe79a36f61f5d0e1a69a653a8a Binary files /dev/null and b/lib/hamcrest-core-1.3.jar differ diff --git a/lib/junit-4.13.2.jar b/lib/junit-4.13.2.jar new file mode 100644 index 0000000000000000000000000000000000000000..6da55d8b8520dcc03c250a605151cc0d23a45518 Binary files /dev/null and b/lib/junit-4.13.2.jar differ diff --git a/lib/junit-platform-console-standalone-1.10.2.jar b/lib/junit-platform-console-standalone-1.10.2.jar new file mode 100644 index 0000000000000000000000000000000000000000..7ca10e60183a168b228fd60a233281dd697b1cea Binary files /dev/null and b/lib/junit-platform-console-standalone-1.10.2.jar differ diff --git a/src/td07/Animaux.java b/src/td07/Animaux.java deleted file mode 100644 index f3d98f0563021fffb4c4facb199df27a51dc452d..0000000000000000000000000000000000000000 --- a/src/td07/Animaux.java +++ /dev/null @@ -1,7 +0,0 @@ -package td07; - -public interface Animaux { - public String shout(); - public int foodAmount(); - public boolean isPet(); -} \ No newline at end of file diff --git a/src/td07/Banc.java b/src/td07/Banc.java deleted file mode 100644 index ad8c5d79ad430443643e8dcb5322f2c999a8bd72..0000000000000000000000000000000000000000 --- a/src/td07/Banc.java +++ /dev/null @@ -1,5 +0,0 @@ -package td07; - -public class Banc { - -} \ No newline at end of file diff --git a/src/td07/Fish.java b/src/td07/Fish.java deleted file mode 100644 index 485836963780201668c308d8cb0b184a4b278283..0000000000000000000000000000000000000000 --- a/src/td07/Fish.java +++ /dev/null @@ -1,34 +0,0 @@ -package td07; - -public class Fish implements Animaux{ - private static final int FOOD = 1; //En UML, un final doit être écrit en majuscules. - private String name; - - public Fish(String name) { //+Fish(String) - this.name = name; - } - - public String shout() { //+shout() : String - return "Blob!"; - } - - public int foodAmount() { - return this.FOOD; //+foodAmount() : int - } - - public boolean isPet() { //+isPet() : boolean - return true; - } - - public String toString() { //+toString() : String - return ""; - } - - public int getFOOD() { //+getFOOD() : int - return this.mealSize; - } - - public int getName() { //+getName() : String - return this.weight; - } -} \ No newline at end of file diff --git a/src/td07/Pig.java b/src/td07/Pig.java deleted file mode 100644 index e351f7dc2b36f4ca56af356955233fa5631ebf2e..0000000000000000000000000000000000000000 --- a/src/td07/Pig.java +++ /dev/null @@ -1,44 +0,0 @@ -package td07; - -public class Pig implements Animaux{ - private static int mealSize; //En UML, static doit être souligné. - private int weight; - private String name; - - public Pig(String name, int weight) { //+Pig(String, int) - this.name = name; - this.weight = weight; - } - - public String shout() { //shout() : String - return "Grouik!"; - } - - public int foodAmount() { //foodAmount() : int - return this.mealSize; - } - - public boolean isPet() { //isPet() : boolean - return true; - } - - public void rollingInMud() { //rollingInMud() : void - println("Rolls in the mud."); - } - - public String toString() { //toString() : String - return ""; - } - - public int getMealSize() { //getMealSize() : int - return this.mealSize; - } - - public int getWeight() { //getWeight() : int - return this.weight; - } - - public String getName() { //getName() : String - return this.name; - } -} \ No newline at end of file diff --git a/src/td07/Tigre.java b/src/td07/Tigre.java deleted file mode 100644 index bda0be11b06162540f1ab09b1d5a905f74602a4d..0000000000000000000000000000000000000000 --- a/src/td07/Tigre.java +++ /dev/null @@ -1,32 +0,0 @@ -package td07; - -public class Tigre implements Animaux{ - private static final int MIN_FOOD = 0; //En UML, un final doit être écrit en majuscules. - private static final int MAX_FOOD = 20; - - public Tiger() { //+Tigre() - } - - public String shout() { //+shout() : String - return "Purr!"; - } - - public int foodAmount() { //+foodAmount() : int - } - - public boolean isPet() { //+isPet() : boolean - return true; - } - - public String toString() { //+toString() : String - return ""; - } - - public int getMIN_FOOD() { //+getMIN_FOOD() : int - return this.mealSize; - } - - public int getWeight() { //+getMAX_FOOD() : int - return this.weight; - } -} \ No newline at end of file diff --git a/src/tp01/Book.java b/src/tp01/Book.java new file mode 100644 index 0000000000000000000000000000000000000000..611c3ca0365b463078f19a6a47c4ba9319eb6f04 --- /dev/null +++ b/src/tp01/Book.java @@ -0,0 +1,27 @@ +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; + } + + public static void main(String[] args) { + Book buch = new Book("Edwin A. Abbott", "Flatland", 1884); + System.out.println(buch.author + " a écrit " + buch.title + " en " + buch.year + "."); + } +} \ No newline at end of file diff --git a/src/tp01/Irregular.java b/src/tp01/Irregular.java new file mode 100644 index 0000000000000000000000000000000000000000..88bdb9b63d93106f5ca251345616db3e887c15bf --- /dev/null +++ b/src/tp01/Irregular.java @@ -0,0 +1,72 @@ +class Irregular { + int[][] table; + + Irregular(int[] lineSize) { + this.table = new int[lineSize.length][]; + for (int i = 0; i < lineSize.length; i++) { + this.table[i] = new int[lineSize[i]]; + } + } + + void randomFilling() { + for(int i = 0; i < this.table.length; i++) { + for (int j = 0; j < this.table[i].length; j++) { + this.table[i][j] = (int)(Math.random()*10); + } + } + } + + String display() { + String retour = ""; + for(int i = 0; i < this.table.length; i++) { + for (int j = 0; j < this.table[i].length; j++) { + retour = retour + this.table[i][j] + " "; + } + retour = retour + "\n"; + } + return retour; + } + + boolean isCommon(int integer) { + int verif = 0; + for (int i = 0; i < this.table.length; i++) { + int j = 0; + boolean found = false; + while(j < this.table[i].length && found == false) { + if (this.table[i][j] == integer) { + verif++; + found = true; + } + j++; + } + } + return verif == this.table.length; + } + + boolean existCommon() { + int[] possibleEntrys = this.table[0]; + int[] oui = new int[possibleEntrys.length]; + for (int w = 0; w<oui.length; w++) { + oui[w] = 0; + } + for (int i = 0; i<possibleEntrys.length; i++) { + for (int j = 0; j<this.table.length; j++) { + int k = 0; + boolean found = false; + while (k < this.table[j].length && found == false) { + if (this.table[j][k] == possibleEntrys[i]) { + oui[i]++; + found = true; + } + k++; + } + } + } + for (int l = 0; l<oui.length;l++) { + if (oui[l] == this.table.length) { + return true; + } + } + return false; + } +} \ No newline at end of file diff --git a/src/tp01/Parameter.java b/src/tp01/Parameter.java new file mode 100644 index 0000000000000000000000000000000000000000..eb31d43c77fc8bc4484cb18d0c0914f2d087f1d7 --- /dev/null +++ b/src/tp01/Parameter.java @@ -0,0 +1,10 @@ +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]); + } + } +} \ No newline at end of file diff --git a/src/tp01/RandomSequence.java b/src/tp01/RandomSequence.java new file mode 100644 index 0000000000000000000000000000000000000000..1f645e830fd319095e1fb7b97b2340cf1ad0f016 --- /dev/null +++ b/src/tp01/RandomSequence.java @@ -0,0 +1,16 @@ +class RandomSequence { + public static void main(String[] args) { + if (args.length==0) { + System.out.println("No parameter"); + } else if (args.length<2||args.length>3||(args.length==3&&!args[2].equals("REAL")&&!args[2].equals("INTEGER"))) { + System.out.println("Correct usage : <nbElt> <maxVal> [INTEGER|REAL]"); + } + for (int i = 0; i<Integer.parseInt(args[0]);i++) { + if (args.length==3 && args[2].equals("REAL")) { + System.out.println(Math.random()*Integer.parseInt(args[1])); + } else { + System.out.println((int)(Math.random()*Integer.parseInt(args[1]))); + } + } + } +} \ No newline at end of file diff --git a/src/tp01/UseBook.java b/src/tp01/UseBook.java new file mode 100644 index 0000000000000000000000000000000000000000..9aa47231e663ebb14cc19f7227b3b93b27eb54d9 --- /dev/null +++ b/src/tp01/UseBook.java @@ -0,0 +1,12 @@ +class UseBook { + public static void main(String[] args) { + Book[] biblio = new Book[]{new Book("Ma in", "Kampf", 1934), new Book("Hoa", "Lache", 1820), new Book("Cond", "Amener", 1346)}; + printBooks(biblio); + } + + public static void printBooks(Book[] biblio) { + for (Book book : biblio) { + System.out.println(book.print()); + } + } +} \ No newline at end of file diff --git a/src/tp01/UseIrregular.java b/src/tp01/UseIrregular.java new file mode 100644 index 0000000000000000000000000000000000000000..f3800c8c4ea27164660211a937258841bcec6c50 --- /dev/null +++ b/src/tp01/UseIrregular.java @@ -0,0 +1,10 @@ +class UseIrregular { + public static void main(String[] args) { + Irregular suite = new Irregular(new int[]{1, 3, 2, 1, 1, 3, 3}); + suite.randomFilling(); + String table = suite.display(); + System.out.println(table); + System.out.println(suite.isCommon(2)); + System.out.println(suite.existCommon()); + } +} \ No newline at end of file diff --git a/src/tp02/Competitor.java b/src/tp02/Competitor.java new file mode 100644 index 0000000000000000000000000000000000000000..78b24d2eadeea15367468d4747a2f277120d8da2 --- /dev/null +++ b/src/tp02/Competitor.java @@ -0,0 +1,43 @@ +class Competitor { + public String numberSign; + int time; + int score; + + Competitor(int numberSign, int score, int min, int sec) { + if (numberSign>100||numberSign<1||min<0||min>59||sec<0||sec>60||score<0||score>50) {this.numberSign=null;} + else { + this.numberSign = "No" + numberSign; + this.score = score; + this.time = sec + (min*60); + } + } + + public String display() { + String print = "["; + if (this.numberSign == null) { + print = print + "<invalide>"; + } else { + print = print + this.numberSign; + } + print = print + ", " + this.score + " points, " + this.time + " s]"; + return print; + } + + public static void main(String[] args) { + Competitor[] table = new Competitor[100]; + table[0] = new Competitor(1, 45, 15, 20); + table[1] = new Competitor(2, 32, 12, 45); + table[2] = new Competitor(5, 12, 13, 59); + table[3] = new Competitor(12, 12, 15, 70); + table[4] = new Competitor(32, 75, 15, 20); + int i = 0; + while (table[i] != null) { + if (table[i].numberSign == null) { + i++; + } else { + System.out.println(table[i].display()); + i++; + } + } + } +} \ No newline at end of file diff --git a/src/tp02/Dice.java b/src/tp02/Dice.java new file mode 100644 index 0000000000000000000000000000000000000000..06ea555d8b8d96403ab6a9f947fce6fc28a31300 --- /dev/null +++ b/src/tp02/Dice.java @@ -0,0 +1,22 @@ +import java.util.Random; +class Dice { + int numberSides; + int value; + Random rand; + + Dice(int faces) { + if (faces < 1) { + this.numberSides = 1; + } else {this.numberSides = faces;} + this.rand = new Random(); + roll(); + } + + public void roll() { + this.value = rand.nextInt(1, this.numberSides); + } + + public String toString() { + return "" + value; + } +} \ No newline at end of file diff --git a/src/tp02/DicePlayer.java b/src/tp02/DicePlayer.java new file mode 100644 index 0000000000000000000000000000000000000000..cdc111074eb7c57bc572290a701df39ff0f83ada --- /dev/null +++ b/src/tp02/DicePlayer.java @@ -0,0 +1,21 @@ +class DicePlayer { + String name; + int totalValue; + int nbDiceRolls; + + DicePlayer(String name) { + this.name = name; + this.totalValue = 0; + this.nbDiceRolls = 0; + } + + public void play(Dice de) { + de.roll(); + this.totalValue += Integer.parseInt(de.toString()); + this.nbDiceRolls++; + } + + public String toString() { + return this.name + ": " + this.totalValue + " en " + this.nbDiceRolls + " coups."; + } +} \ No newline at end of file diff --git a/src/tp02/NbDicePlayerGame.java b/src/tp02/NbDicePlayerGame.java new file mode 100644 index 0000000000000000000000000000000000000000..b516c46c6242b57185a6775b8b2b659fe4d8b879 --- /dev/null +++ b/src/tp02/NbDicePlayerGame.java @@ -0,0 +1,69 @@ +class NbDicePlayerGame { + public static final Read read = new Read(); + + public static DicePlayer[] players; + public static Dice[] dices; + + + + public static void main(String[] args) { + System.out.print("Combien de joueurs : "); + int nb = read.readInt(); + players = new DicePlayer[nb]; + dices = new Dice[nb]; + + for (int i = 0; i < players.length; i++) { + DicePlayer player = new DicePlayer("Michelle" + i); + Dice dice = new Dice(6); + players[i] = player; + dices[i] = dice; + } + + while (!finished()) { + for (int i = 0; i < players.length; i++) { + if (players[i].totalValue < 20) { + players[i].play(dices[i]); + } + } + } + + System.out.println("Le(s) gagnant(s) est/sont : "); + DicePlayer[] winners = winner(); + int i = 0; + while (winners[i] != null && i<winners.length) { + System.out.println("- " + winners[i].toString()); + i++; + } + } + + public static DicePlayer[] winner() { + int[] scores = new int[players.length]; + DicePlayer[] winners = new DicePlayer[players.length]; + int min = players[0].nbDiceRolls; + for (int i = 1; i<players.length;i++) { + if (players[i].nbDiceRolls < min) { + min = players[i].nbDiceRolls; + } + } + int w = 0; + for (int i = 0; i<players.length;i++) { + if (players[i].nbDiceRolls == min) { + winners[w] = players[i]; + w++; + } + } + return winners; + } + + public static boolean finished() { + boolean retour = true; + int i = 0; + while (retour && i<players.length) { + if (players[i].totalValue<19) { + retour = false; + } + i++; + } + return retour; + } +} \ No newline at end of file diff --git a/src/tp02/OneDicePlayerGame.java b/src/tp02/OneDicePlayerGame.java new file mode 100644 index 0000000000000000000000000000000000000000..e437c6dde6da9b95579396b5028277c5db9516e9 --- /dev/null +++ b/src/tp02/OneDicePlayerGame.java @@ -0,0 +1,14 @@ +class OneDicePlayerGame { + public static final Read read = new Read(); + + public static void main(String[] args) { + System.out.print("Entrez votre nom : "); + DicePlayer player = new DicePlayer(read.readString()); + System.out.print("Le nombre de faces : "); + Dice dice = new Dice(read.readInt()); + while (player.totalValue < 20) { + player.play(dice); + } + System.out.println(player.toString()); + } +} \ No newline at end of file diff --git a/src/tp02/Read.java b/src/tp02/Read.java new file mode 100644 index 0000000000000000000000000000000000000000..266058278960bcf30567e6be58983a1f688df5dd --- /dev/null +++ b/src/tp02/Read.java @@ -0,0 +1,14 @@ +import java.util.Scanner; +class Read { + public static Scanner scanner = new Scanner(System.in); + + public static int readInt() { + int scan = scanner.nextInt(); + return scan; + } + + public static String readString() { + String scan = scanner.nextLine(); + return scan; + } +} \ No newline at end of file diff --git a/src/tp02/TwoDicePlayerGame.java b/src/tp02/TwoDicePlayerGame.java new file mode 100644 index 0000000000000000000000000000000000000000..ee97a91768582ff5da27202a7c4be8fb913da94e --- /dev/null +++ b/src/tp02/TwoDicePlayerGame.java @@ -0,0 +1,40 @@ +class TwoDicePlayerGame { + public static final Read read = new Read(); + + public static DicePlayer player1; + public static Dice dice1; + public static DicePlayer player2; + public static Dice dice2; + + + + public static void main(String[] args) { + System.out.print("Entrez votre nom : "); + player1 = new DicePlayer(read.readString()); + System.out.print("Le nombre de faces : "); + dice1 = new Dice(read.readInt()); + + System.out.print("Entrez votre nom : "); + player2 = new DicePlayer(read.readString()); + System.out.print("Le nombre de faces : "); + dice2 = new Dice(read.readInt()); + while (player1.totalValue < 20 || player2.totalValue < 20) { + if (player1.totalValue < 20) { + player1.play(dice1); + } + if (player2.totalValue < 20) { + player2.play(dice2); + } + } + + System.out.println("Le gagnant est " + winner().toString()); + } + + public static DicePlayer winner() { + if (player1.nbDiceRolls < player2.nbDiceRolls) { + return player1; + } else { + return player2; + } + } +} \ No newline at end of file diff --git a/src/tp06 b/src/tp06 new file mode 160000 index 0000000000000000000000000000000000000000..a3a413ddd7a02a4055d86a2a8452438bba4ab392 --- /dev/null +++ b/src/tp06 @@ -0,0 +1 @@ +Subproject commit a3a413ddd7a02a4055d86a2a8452438bba4ab392 diff --git a/src/tp08/Food.java b/src/tp08/Food.java new file mode 100644 index 0000000000000000000000000000000000000000..2dff960fb0728b559a858642218db0a3d27bbefb --- /dev/null +++ b/src/tp08/Food.java @@ -0,0 +1,65 @@ +package tp08; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; + +public class Food implements IProduct, Comparable<Food> { + private String label; + private double price; + private LocalDate bestBeforDate; + private static int refIconnue = 0; + + public Food(String label, double price, LocalDate bestBeforDate) { + if(label == null) { + this.label = "refUnknown" + refIconnue; + refIconnue++; + } else { + this.label = label; + } + this.price = price; + this.bestBeforDate = bestBeforDate; + } + + public Food(String label, double price) { + if(label == null) { + this.label = "refUnknown" + refIconnue; + refIconnue++; + } else { + this.label = label; + } + this.price = price; + this.bestBeforDate = LocalDate.now().plus(10, ChronoUnit.DAYS); + } + + public String getLabel() { + return this.label; + } + + public double getPrice() { + return this.price; + } + + public LocalDate getBestBeforDate() { + return this.bestBeforDate; + } + + public boolean isPerishable() { + return true; + } + + public boolean isBestBefore(LocalDate date) { + return this.bestBeforDate.isBefore(date); + } + + @Override + public int compareTo(Food arg0) { + if(this.isBestBefore(arg0.getBestBeforDate())) { + return 1; + } else { + return -1; + } + } + + public String toString() { + return "[" + this.label + "=" + this.price + " -> before " + this.bestBeforDate + "]"; + } +} \ No newline at end of file diff --git a/src/tp08/Furniture.java b/src/tp08/Furniture.java new file mode 100644 index 0000000000000000000000000000000000000000..cd3756f892eff4a708987611594619ed6a90b07d --- /dev/null +++ b/src/tp08/Furniture.java @@ -0,0 +1,32 @@ +package tp08; +public class Furniture implements IProduct { + private String label; + private double price; + private static int refInconnue = 0; + + public Furniture(String label, double price) { + if(label == null) { + this.label = "refUnknown" + refInconnue; + refInconnue++; + } else { + this.label = label; + } + this.price = price; + } + + public String getLabel() { + return this.label; + } + + public double getPrice() { + return this.price; + } + + public boolean isPerishable() { + return false; + } + + public String toString() { + return "[" + this.label + "=" + this.price + "]"; + } +} \ No newline at end of file diff --git a/src/tp08/IProduct.java b/src/tp08/IProduct.java new file mode 100644 index 0000000000000000000000000000000000000000..3402ad9d1acf64c436934a30a4fbeeac5ba2f69e --- /dev/null +++ b/src/tp08/IProduct.java @@ -0,0 +1,6 @@ +package tp08; +public interface IProduct { + + public double getPrice(); + public boolean isPerishable(); +} \ No newline at end of file diff --git a/src/tp08/Shelf.java b/src/tp08/Shelf.java new file mode 100644 index 0000000000000000000000000000000000000000..d233f617c88b5d8f93325f085f904d6b2eebe6a8 --- /dev/null +++ b/src/tp08/Shelf.java @@ -0,0 +1,47 @@ +package tp08; +import java.util.ArrayList; + +public class Shelf{ + private boolean refregirated; + private int capacityMax; + private ArrayList<IProduct> products; + + public Shelf(boolean refregirated, int capacityMax){ + this.refregirated = refregirated; + this.capacityMax = capacityMax; + this.products = new ArrayList<IProduct>(); + } + + public ArrayList<IProduct> getShelves(){ + return this.products; + } + + public int getCapacityMax(){ + return this.capacityMax; + } + + public boolean isFull(){ + return this.products.size() == this.capacityMax; + } + + public boolean isEmpty(){ + return this.products.size() == 0; + } + + public boolean isRefregirated(){ + return this.refregirated; + } + + public String toString() { + return "[" + isRefregirated() + ": " + getCapacityMax() + " -> " + getShelves().toString() + "]"; + } + + public boolean add(IProduct product){ + if(isFull()){ + return false; + } + this.products.add(product); + return true; + } + +} \ No newline at end of file diff --git a/src/tp08/Shop.java b/src/tp08/Shop.java new file mode 100644 index 0000000000000000000000000000000000000000..8e19d42ecb8e5aa3f3016e1ff58e67362a6a0143 --- /dev/null +++ b/src/tp08/Shop.java @@ -0,0 +1,64 @@ +package tp08; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; + +public class Shop { + private ArrayList<Shelf> shelves; + + public Shop(){ + this.shelves = new ArrayList<Shelf>(); + } + + public Shop(ArrayList<Shelf> shelves){ + this.shelves = shelves; + } + + public ArrayList<Shelf> getShelving(){ + return this.shelves; + } + + public String toString() { + String retour = ""; + for(Shelf shelf : this.shelves){ + retour += shelf.toString() + "\n"; + } + return retour; + } + + public void tidy(ArrayList<IProduct> products){ + for(int i = 0; i<products.size(); i++) { + if(products.get(i).isPerishable()){ + for(Shelf shelf : this.shelves){ + if(shelf.isRefregirated() && shelf.add(products.get(i))){ + products.remove(i); + i--; + break; + } + } + } else { + for(Shelf shelf : this.shelves){ + if(!shelf.isRefregirated() && shelf.add(products.get(i))){ + products.remove(i); + i--; + break; + } + } + } + } + } + + public ArrayList<IProduct> closeBestBeforeDate(int nbDays) { + ArrayList<IProduct> retour = new ArrayList<IProduct>(); + for (Shelf shelf : this.shelves) { + if(shelf.isRefregirated()) { + for (IProduct product : shelf.getShelves()) { + if (((Food)product).isBestBefore(LocalDate.now().plus(nbDays, ChronoUnit.DAYS))) { + retour.add(product); + } + } + } + } + return retour; + } +} \ No newline at end of file diff --git a/src/tp08/ShopTest.java b/src/tp08/ShopTest.java new file mode 100644 index 0000000000000000000000000000000000000000..169b27e0ca202df1df2bce8e8f905046c98246eb --- /dev/null +++ b/src/tp08/ShopTest.java @@ -0,0 +1,76 @@ +package tp08; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; + +import java.time.LocalDate; +import java.util.ArrayList; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class ShopTest { + public IProduct p1, p2, p3, p4, p5; + public ArrayList<IProduct> aStock; + public Shelf e1, e2, e3, e4; + public ArrayList<Shelf> shelves; + public Shop m; + + @BeforeEach + public void initialization() { + this.p1 = new Food("pasta", 3.25, LocalDate.of(2019, 1, 1)); + this.p2 = new Furniture("chair", 50.0); + this.p3 = new Furniture("table", 100.0); + this.p4 = new Food("fish", 10.0); + this.p5 = new Food("meat", 15.0, LocalDate.of(2019, 1, 1)); + this.aStock = new ArrayList<IProduct>(); + this.aStock.add(p1); this.aStock.add(p2); this.aStock.add(p3); this.aStock.add(p4); this.aStock.add(p5); + + this.e1 = new Shelf(false, 1); + this.e2 = new Shelf(false, 2); + this.e3 = new Shelf(true, 2); + this.e4 = new Shelf(true, 2); + this.shelves = new ArrayList<Shelf>(); + this.shelves.add(e1); this.shelves.add(e2); this.shelves.add(e3); this.shelves.add(e4); + + this.m = new Shop(shelves); + } + + @Test + public void initTest() { + ArrayList<Shelf> tmp = m.getShelving(); + assertEquals(4, tmp.size()); + assertTrue(tmp.get(0).isEmpty()); + assertFalse(tmp.get(0).isRefregirated()); + assertTrue(tmp.get(1).isEmpty()); + assertFalse(tmp.get(1).isRefregirated()); + assertTrue(tmp.get(2).isEmpty()); + assertTrue(tmp.get(2).isRefregirated()); + assertTrue(tmp.get(3).isEmpty()); + assertTrue(tmp.get(3).isRefregirated()); + } + @Test + public void tidyTest() { + ArrayList<Shelf> tmp = m.getShelving(); + m.tidy(this.aStock); + assertTrue(tmp.get(0).isFull()); + assertEquals(this.p2, tmp.get(0).getShelves().get(0)); + assertFalse(tmp.get(1).isFull()); + assertFalse(tmp.get(1).isEmpty()); + assertEquals(this.p3, tmp.get(1).getShelves().get(0)); + assertTrue(tmp.get(2).isFull()); + assertEquals(this.p1, tmp.get(2).getShelves().get(0)); + assertEquals(this.p4, tmp.get(2).getShelves().get(1)); + assertFalse(tmp.get(3).isFull()); + assertFalse(tmp.get(3).isEmpty()); + assertEquals(this.p5, tmp.get(3).getShelves().get(0)); + } + @Test + public void closeBeforeDateTest() { + m.tidy(this.aStock); + ArrayList<IProduct> res = m.closeBestBeforeDate(-3); + assertEquals(2, res.size()); + assertEquals(this.p1, res.get(0)); + assertEquals(this.p5, res.get(1)); + } +} diff --git a/src/tp08/UseComparable.java b/src/tp08/UseComparable.java new file mode 100644 index 0000000000000000000000000000000000000000..5442921a4f6c476e5ae8e8a270482a2803ca811c --- /dev/null +++ b/src/tp08/UseComparable.java @@ -0,0 +1,18 @@ +package tp08; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class UseComparable{ + public static void main(String[] args) { + Food f1 = new Food("pasta", 3.25, LocalDate.of(2019, 1, 1)); + Food f2 = new Food("fish", 10.0, LocalDate.of(2019, 1, 10)); + Food f3 = new Food("meat", 15.0, LocalDate.of(2019, 1, 3)); + List<Food> storage = new ArrayList<Food>(); + storage.add(f1);storage.add(f2);storage.add(f3); + System.out.println(storage); + Collections.sort(storage); + System.out.println(storage); + } +} \ No newline at end of file diff --git a/src/tp09/LogInManagement.java b/src/tp09/LogInManagement.java new file mode 100644 index 0000000000000000000000000000000000000000..ec3512cf301e236918179bb010fd5ab1ac267460 --- /dev/null +++ b/src/tp09/LogInManagement.java @@ -0,0 +1,36 @@ +package tp09; +import java.util.Scanner; + +public class LogInManagement { + public static final String username = "admin"; + public static final String password = "admin"; + + public static void getUserPWD() throws WrongPWDException, WrongUserException, WrongLengthException { + Scanner scanner = new Scanner(System.in); + System.out.println("Enter your username: "); + String enteredUsername = scanner.nextLine(); + System.out.println("Enter your password: "); + String enteredPassword = scanner.nextLine(); + if (enteredUsername.equals(username) && enteredPassword.equals(password)) { + System.out.println("Welcome " + username + "!"); + } else { + if(enteredPassword.length() > 10 || enteredUsername.length() > 10) { + throw new WrongLengthException("Username and password must be less than 10 characters!"); + } else { + if (!enteredUsername.equals(username) && !enteredPassword.equals(password)) { + throw new WrongUserException("Wrong username and password!"); + } else if (!enteredUsername.equals(username)) { + throw new WrongUserException("Wrong username!"); + } else { + throw new WrongPWDException("Wrong password!"); + } + } + } + } + + public static void main(String[] args) throws WrongPWDException, WrongUserException, WrongLengthException { + getUserPWD(); + } + + +} \ No newline at end of file diff --git a/src/tp09/WrongLengthException.java b/src/tp09/WrongLengthException.java new file mode 100644 index 0000000000000000000000000000000000000000..65a53e446db95569de30eba17146cfc5982dfd10 --- /dev/null +++ b/src/tp09/WrongLengthException.java @@ -0,0 +1,7 @@ +package tp09; + +public class WrongLengthException extends Exception { + public WrongLengthException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/src/tp09/WrongPWDException.java b/src/tp09/WrongPWDException.java new file mode 100644 index 0000000000000000000000000000000000000000..5f4381c8d4af350054fedd73dcd06f9395342a16 --- /dev/null +++ b/src/tp09/WrongPWDException.java @@ -0,0 +1,7 @@ +package tp09; + +public class WrongPWDException extends Exception { + public WrongPWDException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/src/tp09/WrongUserException.java b/src/tp09/WrongUserException.java new file mode 100644 index 0000000000000000000000000000000000000000..b8b0f6ffbd3b861d5c670ca810c54de4f7b5e099 --- /dev/null +++ b/src/tp09/WrongUserException.java @@ -0,0 +1,7 @@ +package tp09; + +public class WrongUserException extends Exception { + public WrongUserException(String message) { + super(message); + } +} \ No newline at end of file