diff --git a/APL2.1/TP03/Piege/Piege.class b/APL2.1/TP03/Piege/Piege.class new file mode 100644 index 0000000..83e4ecd Binary files /dev/null and b/APL2.1/TP03/Piege/Piege.class differ diff --git a/APL2.1/TP03/Piege/Piege.java b/APL2.1/TP03/Piege/Piege.java new file mode 100644 index 0000000..782f2f2 --- /dev/null +++ b/APL2.1/TP03/Piege/Piege.java @@ -0,0 +1,44 @@ +import javax.swing.*; +import java.awt.*; + +public class Piege { + public static void main(String[] args) { + JFrame fenetre = new JFrame("Rose"); + fenetre.setSize(300, 300); + fenetre.setLocation(100, 100); + fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + fenetre.setLayout(null); + + JButton one = new JButton("1"); + JButton two = new JButton("2"); + JButton three = new JButton("3"); + JButton four = new JButton("4"); + JButton five = new JButton("5"); + + int offsetX = 10; + int offsetY = 35; + + one.setSize(250 - offsetX, 50); + + two.setSize(50, 250 - offsetY); + two.setLocation(250 - offsetX, 0); + + three.setSize(250 - offsetX, 50); + three.setLocation(50, 250 - offsetY); + + four.setSize(50, 250 - offsetY); + four.setLocation(0, 50); + + five.setSize(200 - offsetX, 200 - offsetY); + five.setLocation(50, 50); + + fenetre.add(one); + fenetre.add(two); + fenetre.add(three); + fenetre.add(four); + fenetre.add(five); + + fenetre.setResizable(false); + fenetre.setVisible(true); + } +} \ No newline at end of file diff --git a/APL2.1/TP03/Rose/Rose.class b/APL2.1/TP03/Rose/Rose.class new file mode 100644 index 0000000..d516efc Binary files /dev/null and b/APL2.1/TP03/Rose/Rose.class differ diff --git a/APL2.1/TP03/Rose/Rose.java b/APL2.1/TP03/Rose/Rose.java new file mode 100644 index 0000000..65f5eed --- /dev/null +++ b/APL2.1/TP03/Rose/Rose.java @@ -0,0 +1,30 @@ +import javax.swing.*; +import java.awt.*; + +public class Rose { + public static void main(String[] args) { + JFrame fenetre = new JFrame("Rose"); + fenetre.setSize(300, 200); + fenetre.setLocation(100, 100); + fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + GridLayout grid = new GridLayout(3, 3); + fenetre.setLayout(grid); + + String[] nameList = new String[] {"Mystral", "Tramontane", "Grec", "Ponant", "", "Levant", "Libeccio", "Marin", "Sirocco"}; + + for (int i = 0; i < 9; i++) { + JLabel label = new JLabel(nameList[i]); + if (i % 3 == 0) label.setHorizontalAlignment(SwingConstants.LEFT); + else if (i % 3 == 1) label.setHorizontalAlignment(SwingConstants.CENTER); + else label.setHorizontalAlignment(SwingConstants.RIGHT); + + if (i < 3) label.setVerticalAlignment(SwingConstants.TOP); + else if (i > 5) label.setVerticalAlignment(SwingConstants.BOTTOM); + + fenetre.add(label); + } + + fenetre.setVisible(true); + } +} \ No newline at end of file diff --git a/APL2.1/TP04/Date/Date.class b/APL2.1/TP04/Date/Date.class new file mode 100644 index 0000000..d215343 Binary files /dev/null and b/APL2.1/TP04/Date/Date.class differ diff --git a/APL2.1/TP04/Date/Date.java b/APL2.1/TP04/Date/Date.java new file mode 100644 index 0000000..cab80e1 --- /dev/null +++ b/APL2.1/TP04/Date/Date.java @@ -0,0 +1,6 @@ +public class Date { + public static void main(String[] args) { + MyDate date = new MyDate(2002, 05, 29); + System.out.println(date.toString()); + } +} \ No newline at end of file diff --git a/APL2.1/TP04/Date/MyDate.class b/APL2.1/TP04/Date/MyDate.class new file mode 100644 index 0000000..2d3c5c8 Binary files /dev/null and b/APL2.1/TP04/Date/MyDate.class differ diff --git a/APL2.1/TP04/Date/MyDate.java b/APL2.1/TP04/Date/MyDate.java new file mode 100644 index 0000000..7caddb0 --- /dev/null +++ b/APL2.1/TP04/Date/MyDate.java @@ -0,0 +1,33 @@ +public class MyDate { + private int year; + private int month; + private int day; + + private int[] monthDurations = new int[] {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + + public String toString() { + return String.format("%04d-%02d-%02d", year, month, day); + } + + public MyDate tomorrow() { + MyDate newDate = new MyDate(this.year, this.month, this.day+1); + + if (newDate.day > monthDurations[newDate.month-1]) { + newDate.day = 1; + newDate.month += 1; + } + + if (newDate.month > 12) { + newDate.month = 1; + newDate.year += 1; + } + + return newDate; + } + + public MyDate(int y, int m, int d) { + this.year = y; + this.month = m; + this.day = d; + } +} \ No newline at end of file diff --git a/APL2.1/TP04/Lendemains/Lendemains.class b/APL2.1/TP04/Lendemains/Lendemains.class new file mode 100644 index 0000000..6521b6c Binary files /dev/null and b/APL2.1/TP04/Lendemains/Lendemains.class differ diff --git a/APL2.1/TP04/Lendemains/Lendemains.java b/APL2.1/TP04/Lendemains/Lendemains.java new file mode 100644 index 0000000..a310bf7 --- /dev/null +++ b/APL2.1/TP04/Lendemains/Lendemains.java @@ -0,0 +1,10 @@ +public class Lendemains { + public static void main(String[] args) { + MyDate date = new MyDate(2002, 12, 31); + MyDate tomorrow = date.tomorrow(); + + System.out.println(date); + System.out.println(tomorrow); + System.out.println(date.isEqual(tomorrow)); + } +} \ No newline at end of file diff --git a/APL2.1/TP04/Lendemains/MyDate.class b/APL2.1/TP04/Lendemains/MyDate.class new file mode 100644 index 0000000..79988c1 Binary files /dev/null and b/APL2.1/TP04/Lendemains/MyDate.class differ diff --git a/APL2.1/TP04/Lendemains/MyDate.java b/APL2.1/TP04/Lendemains/MyDate.java new file mode 100644 index 0000000..b3bdb04 --- /dev/null +++ b/APL2.1/TP04/Lendemains/MyDate.java @@ -0,0 +1,37 @@ +public class MyDate { + private int year; + private int month; + private int day; + + private int[] monthDurations = new int[] {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + + public String toString() { + return String.format("%04d-%02d-%02d", year, month, day); + } + + public MyDate tomorrow() { + MyDate newDate = new MyDate(this.year, this.month, this.day+1); + + if (newDate.day > monthDurations[newDate.month-1]) { + newDate.day = 1; + newDate.month += 1; + } + + if (newDate.month > 12) { + newDate.month = 1; + newDate.year += 1; + } + + return newDate; + } + + public boolean isEqual(MyDate date) { + return (this.year == date.year && this.month == date.month && this.day == date.day); + } + + public MyDate(int y, int m, int d) { + this.year = y; + this.month = m; + this.day = d; + } +} \ No newline at end of file diff --git a/APL2.1/TP04/Periode/MyDate.class b/APL2.1/TP04/Periode/MyDate.class new file mode 100644 index 0000000..79988c1 Binary files /dev/null and b/APL2.1/TP04/Periode/MyDate.class differ diff --git a/APL2.1/TP04/Periode/MyDate.java b/APL2.1/TP04/Periode/MyDate.java new file mode 100644 index 0000000..b3bdb04 --- /dev/null +++ b/APL2.1/TP04/Periode/MyDate.java @@ -0,0 +1,37 @@ +public class MyDate { + private int year; + private int month; + private int day; + + private int[] monthDurations = new int[] {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + + public String toString() { + return String.format("%04d-%02d-%02d", year, month, day); + } + + public MyDate tomorrow() { + MyDate newDate = new MyDate(this.year, this.month, this.day+1); + + if (newDate.day > monthDurations[newDate.month-1]) { + newDate.day = 1; + newDate.month += 1; + } + + if (newDate.month > 12) { + newDate.month = 1; + newDate.year += 1; + } + + return newDate; + } + + public boolean isEqual(MyDate date) { + return (this.year == date.year && this.month == date.month && this.day == date.day); + } + + public MyDate(int y, int m, int d) { + this.year = y; + this.month = m; + this.day = d; + } +} \ No newline at end of file diff --git a/APL2.1/TP04/Periode/MyPeriod.class b/APL2.1/TP04/Periode/MyPeriod.class new file mode 100644 index 0000000..a772e5a Binary files /dev/null and b/APL2.1/TP04/Periode/MyPeriod.class differ diff --git a/APL2.1/TP04/Periode/MyPeriod.java b/APL2.1/TP04/Periode/MyPeriod.java new file mode 100644 index 0000000..34aab20 --- /dev/null +++ b/APL2.1/TP04/Periode/MyPeriod.java @@ -0,0 +1,31 @@ +public class MyPeriod { + + private int length; + + public String toString() { + return "Periode : " + length + " jour" + (length > 1 ? "s" : ""); + } + + public void addDay() { + this.length += 1; + } + + public MyPeriod(MyDate date1, MyDate date2) { + if (date1.isEqual(date2)) { + this.length = 0; + return; + } + + //Très dangereux et inefficace, ne faites pas ca svp. + while (!date1.isEqual(date2)) { + date1 = date1.tomorrow(); + length++; + } + } + + public MyPeriod(int length) { + this.length = length; + } + + +} \ No newline at end of file diff --git a/APL2.1/TP04/Periode/Periode.class b/APL2.1/TP04/Periode/Periode.class new file mode 100644 index 0000000..fa08fd6 Binary files /dev/null and b/APL2.1/TP04/Periode/Periode.class differ diff --git a/APL2.1/TP04/Periode/Periode.java b/APL2.1/TP04/Periode/Periode.java new file mode 100644 index 0000000..7309b74 --- /dev/null +++ b/APL2.1/TP04/Periode/Periode.java @@ -0,0 +1,9 @@ +public class Periode { + public static void main(String[] args) { + MyDate date1 = new MyDate(2002, 05, 29); + MyDate date2 = new MyDate(2022, 05, 29); + + MyPeriod p = new MyPeriod(date1, date2); + System.out.println(p.toString()); + } +} \ No newline at end of file diff --git a/APL2.1/TP04/Progression/Compteur.class b/APL2.1/TP04/Progression/Compteur.class new file mode 100644 index 0000000..2e325bc Binary files /dev/null and b/APL2.1/TP04/Progression/Compteur.class differ diff --git a/APL2.1/TP04/Progression/Compteur.java b/APL2.1/TP04/Progression/Compteur.java new file mode 100644 index 0000000..23a0d22 --- /dev/null +++ b/APL2.1/TP04/Progression/Compteur.java @@ -0,0 +1,16 @@ +public class Compteur { + // attribut + private int compte; + // méthode + public void plusUn() { + this.compte++; + } + // autre méthode + public String toString() { + return Integer.toBinaryString(this.compte); + } + + public Compteur() { + this.compte = 0; + } +} \ No newline at end of file diff --git a/APL2.1/TP04/Progression/Progression.class b/APL2.1/TP04/Progression/Progression.class new file mode 100644 index 0000000..a872de3 Binary files /dev/null and b/APL2.1/TP04/Progression/Progression.class differ diff --git a/APL2.1/TP04/Progression/Progression.java b/APL2.1/TP04/Progression/Progression.java new file mode 100644 index 0000000..2698eef --- /dev/null +++ b/APL2.1/TP04/Progression/Progression.java @@ -0,0 +1,10 @@ +public class Progression { + public static void main(String[] args) { + Compteur cp = new Compteur(); + + for (int i = 0; i < 9; i++) { + cp.plusUn(); + if (i > 3) System.out.println(cp.toString()); + } + } +} \ No newline at end of file