diff --git a/Ordonnanceur.java b/Ordonnanceur.java new file mode 100644 index 0000000000000000000000000000000000000000..7b6a3403f68139a639ccdc42f706263d80ccd00c --- /dev/null +++ b/Ordonnanceur.java @@ -0,0 +1,3 @@ +public class Ordonnanceur { + +} \ No newline at end of file diff --git a/bin/TP04/Exercice_3/Container.class b/bin/TP04/Exercice_3/Container.class new file mode 100644 index 0000000000000000000000000000000000000000..1c486834de9d266e5fdcfc47263e547efd1c6298 Binary files /dev/null and b/bin/TP04/Exercice_3/Container.class differ diff --git a/bin/TP04/Exercice_3/ExtendedException.class b/bin/TP04/Exercice_3/ExtendedException.class new file mode 100644 index 0000000000000000000000000000000000000000..97c6bbf6892b135335b955043aa1a5bedbfb9d37 Binary files /dev/null and b/bin/TP04/Exercice_3/ExtendedException.class differ diff --git a/bin/TP04/Exercice_3/Thing.class b/bin/TP04/Exercice_3/Thing.class new file mode 100644 index 0000000000000000000000000000000000000000..595c3d58f47d94309b0ea6c0ef71f7f00a699d8b Binary files /dev/null and b/bin/TP04/Exercice_3/Thing.class differ diff --git a/bin/TP04/Exercice_3/UseThing.class b/bin/TP04/Exercice_3/UseThing.class new file mode 100644 index 0000000000000000000000000000000000000000..c562c41325a67f63f4a2c9f464cb1d5f2c111154 Binary files /dev/null and b/bin/TP04/Exercice_3/UseThing.class differ diff --git "a/src/TP04/Exercice n\302\2601/Exemple1/Exemple1.java" b/src/TP04/Exercice_1/Exemple1/Exemple1.java similarity index 83% rename from "src/TP04/Exercice n\302\2601/Exemple1/Exemple1.java" rename to src/TP04/Exercice_1/Exemple1/Exemple1.java index f3e95696662e2341437a42d8d64030c3d1f03644..095f73add2641b6dedfd853a8797eeeda76b7b50 100644 --- "a/src/TP04/Exercice n\302\2601/Exemple1/Exemple1.java" +++ b/src/TP04/Exercice_1/Exemple1/Exemple1.java @@ -1,4 +1,4 @@ -package TP04.Exemple1; +package TP04.Exercice_1.Exemple1; public class Exemple1 { diff --git "a/src/TP04/Exercice n\302\2601/Exemple2/Dutilisation.java" b/src/TP04/Exercice_1/Exemple2/Dutilisation.java similarity index 77% rename from "src/TP04/Exercice n\302\2601/Exemple2/Dutilisation.java" rename to src/TP04/Exercice_1/Exemple2/Dutilisation.java index 26ecfdeb076438760a49f7c9f310fae4217718bc..053f4a8f851d43f213f7909b7c3986c463bd80ad 100644 --- "a/src/TP04/Exercice n\302\2601/Exemple2/Dutilisation.java" +++ b/src/TP04/Exercice_1/Exemple2/Dutilisation.java @@ -1,4 +1,4 @@ -package TP04.Exemple2; +package TP04.Exercice_1.Exemple2; public class Dutilisation { public void example2() throws MyException { diff --git "a/src/TP04/Exercice n\302\2601/Exemple2/MyException.java" b/src/TP04/Exercice_1/Exemple2/MyException.java similarity index 79% rename from "src/TP04/Exercice n\302\2601/Exemple2/MyException.java" rename to src/TP04/Exercice_1/Exemple2/MyException.java index 12525340a56d8185f37b662099a8c2621b4200c6..4e80c52d176b4fd7297f46f65cf5cf990dbcf513 100644 --- "a/src/TP04/Exercice n\302\2601/Exemple2/MyException.java" +++ b/src/TP04/Exercice_1/Exemple2/MyException.java @@ -1,4 +1,4 @@ -package TP04.Exemple2; +package TP04.Exercice_1.Exemple2; public class MyException extends Exception { public MyException() {} diff --git "a/src/TP04/Exercice n\302\2601/Exemple3/Exemple3.java" b/src/TP04/Exercice_1/Exemple3/Exemple3.java similarity index 79% rename from "src/TP04/Exercice n\302\2601/Exemple3/Exemple3.java" rename to src/TP04/Exercice_1/Exemple3/Exemple3.java index 2f5fe15270ccf9288ca977e6172e253ff72fd6ae..5e3364415d340965a675599d111c4c593472dd42 100644 --- "a/src/TP04/Exercice n\302\2601/Exemple3/Exemple3.java" +++ b/src/TP04/Exercice_1/Exemple3/Exemple3.java @@ -1,6 +1,6 @@ -package TP04.Exemple3; +package TP04.Exercice_1.Exemple3; -import TP04.Exemple2.MyException; +import TP04.Exercice_1.Exemple2.MyException; public class Exemple3 { public void doItAgain() throws MyException { diff --git "a/src/TP04/Exercice n\302\2601/Exemple4/Exemple4.java" b/src/TP04/Exercice_1/Exemple4/Exemple4.java similarity index 91% rename from "src/TP04/Exercice n\302\2601/Exemple4/Exemple4.java" rename to src/TP04/Exercice_1/Exemple4/Exemple4.java index c12f108e172758758e8625313f7c2b9ee46f6fe2..136022fd9bdbd61c7640b1ec06e5d61cf4ce7533 100644 --- "a/src/TP04/Exercice n\302\2601/Exemple4/Exemple4.java" +++ b/src/TP04/Exercice_1/Exemple4/Exemple4.java @@ -1,4 +1,4 @@ -package TP04.Exemple4; +package TP04.Exercice_1.Exemple4; public class Exemple4 { public int example4() { diff --git "a/src/TP04/Exercice n\302\2601/Exemple5/Exemple5.java" b/src/TP04/Exercice_1/Exemple5/Exemple5.java similarity index 86% rename from "src/TP04/Exercice n\302\2601/Exemple5/Exemple5.java" rename to src/TP04/Exercice_1/Exemple5/Exemple5.java index 7b1389e6efe742c6a4aa27f1a50ccf4936ebf554..f128c79872803fc7fe3b91b6a055bb64d41e874a 100644 --- "a/src/TP04/Exercice n\302\2601/Exemple5/Exemple5.java" +++ b/src/TP04/Exercice_1/Exemple5/Exemple5.java @@ -1,4 +1,4 @@ -package TP04.Exemple5; +package TP04.Exercice_1.Exemple5; public class Exemple5 { public void example5() { diff --git "a/src/TP04/Exercice n\302\2601/Exemple6/Exemple6.java" b/src/TP04/Exercice_1/Exemple6/Exemple6.java similarity index 93% rename from "src/TP04/Exercice n\302\2601/Exemple6/Exemple6.java" rename to src/TP04/Exercice_1/Exemple6/Exemple6.java index 3f5eec0d31319ca16855b3ac7dfc112ddc87d014..b270f999eca0fb9be2a580c31a79798d1c65053e 100644 --- "a/src/TP04/Exercice n\302\2601/Exemple6/Exemple6.java" +++ b/src/TP04/Exercice_1/Exemple6/Exemple6.java @@ -1,4 +1,4 @@ -package TP04.Exemple6; +package TP04.Exercice_1.Exemple6; public class Exemple6 { public static void main(String[] args) { diff --git a/src/TP04/Exercice_2/Exercice2.java b/src/TP04/Exercice_2/Exercice2.java new file mode 100644 index 0000000000000000000000000000000000000000..9fa825f57ef69b07cac4aec7773d0b64c20b20cf --- /dev/null +++ b/src/TP04/Exercice_2/Exercice2.java @@ -0,0 +1,29 @@ +package TP04.Exercice_2; + +import java.util.Scanner; + +public class Exercice2 { + + class LocalKeyboard { + public static int readInt(String message) { + Scanner scanner = new Scanner(System.in); + System.out.println(message); + int r = scanner.nextInt(); + scanner.close(); + return r; + } + } + + public static int[] tab = {17, 12, 15, 38, 29, 157, 89, -22, 0, 5}; + + public static int division(int index, int divisor) { + return tab[index]/divisor; + } + + public static void statement() { + int x, y; + x = LocalKeyboard.readInt("Write the index of the integer to divide: "); + y = LocalKeyboard.readInt("Write the divisor: "); + System.out.println("The result is: " + division(x,y)); + } +} \ No newline at end of file diff --git a/src/TP04/Exercice_3/Container.java b/src/TP04/Exercice_3/Container.java new file mode 100644 index 0000000000000000000000000000000000000000..71b5413ef0ede7f403b8660450ed43f5e9535481 --- /dev/null +++ b/src/TP04/Exercice_3/Container.java @@ -0,0 +1,17 @@ +package TP04.Exercice_3; + +public enum Container { + BLISTER(1), + BOX(10), + CRATE(50); + + private final int capacity; + + Container(int capacity) { + this.capacity = capacity; + } + + public int getCapacity() { + return this.capacity; + } +} \ No newline at end of file diff --git a/src/TP04/Exercice_3/ExtendedException.java b/src/TP04/Exercice_3/ExtendedException.java new file mode 100644 index 0000000000000000000000000000000000000000..30b844bfc59c4ddcd28f2003f0b35c499b66182a --- /dev/null +++ b/src/TP04/Exercice_3/ExtendedException.java @@ -0,0 +1,7 @@ +package TP04.Exercice_3; + +public class ExtendedException extends Exception { + public ExtendedException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/src/TP04/Exercice_3/Thing.java b/src/TP04/Exercice_3/Thing.java new file mode 100644 index 0000000000000000000000000000000000000000..2a8392816ba307e55b75f4afaa5e7824a0942cde --- /dev/null +++ b/src/TP04/Exercice_3/Thing.java @@ -0,0 +1,71 @@ +package TP04.Exercice_3; + +public class Thing { + private String name; + private int quantity; + private Container container; + + public Thing(String name, int quantity, Container container) { + this.name = name; + this.quantity = quantity; + this.container = container; + } + + public String getName() { + return name; + } + + public int getQuantity() { + return quantity; + } + + public Container getContainer() { + return container; + } + + public void setName(String name) { + this.name = name; + } + + public void setContainer(Container container) { + this.container = container; + } + + @Override + public String toString() { + return "Thing{" + + "name='" + name + '\'' + + ", quantity=" + quantity + + ", container=" + container + + '}'; + } + + public void setQuantity(int value) throws ExtendedException { + try { + if(value < this.container.getCapacity()) { + this.quantity = value; + } else { + throw new ExtendedException("Quantity too high to fit in the box."); + } + } catch(ExtendedException e) { + System.out.println("Addition Impossible !"); + } + } + + public boolean transferToLargerContainer() { + if (this.container.ordinal() == Container.values().length - 1) { + return false; + } + this.container = Container.values()[this.container.ordinal() + 1]; + return true; + } + + public void add(int value) throws ExtendedException { + try { + setQuantity(value + this.getQuantity()); + } catch(ExtendedException e) { + transferToLargerContainer(); + setQuantity(value + this.getQuantity()); + } + } +} \ No newline at end of file diff --git a/src/TP04/Exercice_3/UseThing.java b/src/TP04/Exercice_3/UseThing.java new file mode 100644 index 0000000000000000000000000000000000000000..be6116845127728e7f8184a6e91da2b84856001c --- /dev/null +++ b/src/TP04/Exercice_3/UseThing.java @@ -0,0 +1,14 @@ +package TP04.Exercice_3; + +public class UseThing { + public static void main(String[] args) throws ExtendedException { + Thing ch1 = new Thing("uneThing", 3, Container.BOX); + System.out.println(ch1); + ch1.add(20); + System.out.println(ch1 + "\n"); + Thing ch2 = new Thing("maThing", 12, Container.BOX); + System.out.println(ch2); + ch2.add(60); + System.out.println(ch2 + "\n"); + } +} \ No newline at end of file diff --git a/src/TP04/Exercice_4/Competitor.java b/src/TP04/Exercice_4/Competitor.java new file mode 100644 index 0000000000000000000000000000000000000000..185253d619d5b62420c4a5216269037e7b22926d --- /dev/null +++ b/src/TP04/Exercice_4/Competitor.java @@ -0,0 +1,49 @@ +package TP04.Exercice_4; + + +public class Competitor { + private int ID; + private final String NAME; + private Country nationality; + private Team team; + + public Competitor(String name, Country nationality, Team team) { + NumAuto temp = new NumAuto(); + this.ID = temp.getID(); + this.NAME = name; + this.nationality = nationality; + this.team = team; + } + + public int getID() { + return this.ID; + } + + public String getName() { + return this.NAME; + } + + public Country getCountry() { + return this.nationality; + } + + public Team getTeam() { + return this.team; + } + + public String toString() { + return this.ID + " - " + this.NAME + " (" + this.nationality.getCode() + ") -> " + this.team.toString(); + } + + public boolean isFrom(Team team) { + return this.team == team; + } + + public boolean isFrom(Country country) { + return this.nationality == country; + } + + public boolean equals(int ID) { + return this.ID == ID; + } +} \ No newline at end of file diff --git a/src/TP04/Exercice_4/Country.java b/src/TP04/Exercice_4/Country.java new file mode 100644 index 0000000000000000000000000000000000000000..7fa1f59104b98a15ec95b846d1ef7d28c3ad4b84 --- /dev/null +++ b/src/TP04/Exercice_4/Country.java @@ -0,0 +1,20 @@ +package TP04.Exercice_4; + +public enum Country { + FRANCE("FR"), + GERMANY("GE"), + RUSSIA("RU"), + SWEDEN("SW"), + AUSTRIA("AU"), + ITALY("IT"); + + private String code; + + Country(String code) { + this.code = code; + } + + public String getCode() { + return this.code; + } +} \ No newline at end of file diff --git a/src/TP04/Exercice_4/NumAuto.java b/src/TP04/Exercice_4/NumAuto.java new file mode 100644 index 0000000000000000000000000000000000000000..34defd7272ec01145d79df7d42327ec2af4e6964 --- /dev/null +++ b/src/TP04/Exercice_4/NumAuto.java @@ -0,0 +1,9 @@ +package TP04.Exercice_4; + +public class NumAuto { + private static int ID = 0; + + public int getID() { + return ++ID; + } +} \ No newline at end of file diff --git a/src/TP04/Exercice_4/Team.java b/src/TP04/Exercice_4/Team.java new file mode 100644 index 0000000000000000000000000000000000000000..dee5c206e15de8c6c6f66851fc7eebaccabf1ebf --- /dev/null +++ b/src/TP04/Exercice_4/Team.java @@ -0,0 +1,7 @@ +package TP04.Exercice_4; + +public enum Team { + TEAM_1, + TEAM_2, + TEAM_3; +} \ No newline at end of file diff --git a/src/tp04/Person.java b/src/tp04/Person.java index b6e4a6ee464ea66fed436cda11235ea1f7b31772..89c22a9158b76f38701d2e4eef656273735c8f62 100644 --- a/src/tp04/Person.java +++ b/src/tp04/Person.java @@ -1,6 +1,5 @@ package tp04; -import tp04.NumeroAutomatique; public class Person { private int ID;