diff --git a/DEV2.1/TP03/TP03_reponses.txt b/DEV2.1/TP03/TP03_reponses.txt index 93e7f36..695907e 100644 --- a/DEV2.1/TP03/TP03_reponses.txt +++ b/DEV2.1/TP03/TP03_reponses.txt @@ -26,3 +26,46 @@ public class Test { 2. +import javax.swing.*; +import java.awt.*; + +public class Test { + public static void main(String[] args) { + JFrame fenetre = new JFrame(); + int a = Integer.parseInt(args[0]); + + fenetre.setSize(500,500); + fenetre.setLocation(100,100); + fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + GridLayout layout = new GridLayout(a,a); + fenetre.setLayout(layout); + + Color color_1 = Color.WHITE; + Color color_2 = Color.CYAN; + + for (int j = 0; j < a; j++) { + Color temp = color_1; + color_1 = color_2; + color_2 = temp; + for(int i = 0; i < a; i++) { + JPanel panneau = new JPanel(); + if (i%2 == 0) { + panneau.setBackground(color_1); + } + else { + panneau.setBackground(color_2); + } + fenetre.add(panneau); + } + } + + + + fenetre.setVisible(true); + + } +} + +3. + diff --git a/DEV2.1/TP03/Test.class b/DEV2.1/TP03/Test.class index d479188..4341881 100644 Binary files a/DEV2.1/TP03/Test.class and b/DEV2.1/TP03/Test.class differ diff --git a/DEV2.1/TP03/Test.java b/DEV2.1/TP03/Test.java index 98de2ef..2d6de3c 100644 --- a/DEV2.1/TP03/Test.java +++ b/DEV2.1/TP03/Test.java @@ -4,36 +4,22 @@ import java.awt.*; public class Test { public static void main(String[] args) { JFrame fenetre = new JFrame(); - int a = Integer.parseInt(args[0]); fenetre.setSize(500,500); fenetre.setLocation(100,100); fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - GridLayout layout = new GridLayout(a,a); + FlowLayout layout = new FlowLayout(FlowLayout.CENTER); fenetre.setLayout(layout); - Color color_1 = Color.WHITE; - Color color_2 = Color.CYAN; - - for (int j = 0; j < a; j++) { - Color temp = color_1; - color_1 = color_2; - color_2 = temp; - for(int i = 0; i < a; i++) { - JPanel panneau = new JPanel(); - if (i%2 == 0) { - panneau.setBackground(color_1); - } - else { - panneau.setBackground(color_2); - } - fenetre.add(panneau); - } + JButton[] tab = {new JButton("Oui"), new JButton("Non"), new JButton("NSPP")}; + + fenetre.add(new JLabel("Aimez-vous les pieds ?")); + for (int i = 0; i < 3; i++) { + fenetre.add(tab[i]); } - fenetre.setVisible(true); } diff --git a/DEV2.1/TP04/Compteur.class b/DEV2.1/TP04/Compteur.class new file mode 100644 index 0000000..d6f12b6 Binary files /dev/null and b/DEV2.1/TP04/Compteur.class differ diff --git a/DEV2.1/TP04/Compteur.java b/DEV2.1/TP04/Compteur.java new file mode 100644 index 0000000..2d46358 --- /dev/null +++ b/DEV2.1/TP04/Compteur.java @@ -0,0 +1,16 @@ + +public class Compteur { + private int compte; + + public Compteur() { + this.compte = 0; + } + + public void plusUn() { + this.compte++; + } + + public String toString() { + return Integer.toBinaryString(this.compte); + } +} diff --git a/DEV2.1/TP04/Date.class b/DEV2.1/TP04/Date.class new file mode 100644 index 0000000..a3e8c1a Binary files /dev/null and b/DEV2.1/TP04/Date.class differ diff --git a/DEV2.1/TP04/Date.java b/DEV2.1/TP04/Date.java new file mode 100644 index 0000000..64c4d49 --- /dev/null +++ b/DEV2.1/TP04/Date.java @@ -0,0 +1,69 @@ +public class Date { + private int jour; + private int mois; + private int annee; + + public Date(int j, int m, int a) { + this.jour = j; + this.mois = m; + this.annee = a; + } + + public String toString() { + return "" + this.annee + "-" + this.mois + "-" + this.jour; + } + + public Date lendemain() { + int[] joursParMois = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + if (this.jour == joursParMois[this.mois-1]) { + if (this.mois == 12) { + return new Date(1, 1, this.annee+1); + } + return new Date(1, this.mois+1, this.annee); + } + return new Date(this.jour+1, this.mois, this.annee); + } + + public int getAnnee() { + return this.annee; + } + + public int getMois() { + return this.mois; + } + + public int getJour() { + return this.jour; + } + + public boolean dateInferieureA(Date aComparer) { + return (this.annee < aComparer.getAnnee() || this.mois < aComparer.getMois() || this.jour < aComparer.getJour()); + } + + public boolean dateSuperieureA(Date aComparer) { + return (this.annee > aComparer.getAnnee() || this.mois > aComparer.getMois() || this.jour > aComparer.getJour()); + } + + public boolean dateEgaleA(Date aComparer) { + return (this.annee == aComparer.getAnnee() && this.mois == aComparer.getMois() && this.jour == aComparer.getJour()); + } + + public String compareDates(Date aComparer) { + /* Affiche si la date actuelle est inférieure, égale ou supérieure à la date aComparer */ + if (this.dateEgaleA(aComparer)) { + return this.toString() + " est égale à " + aComparer.toString() ; + } + if (this.dateInferieureA(aComparer)) { + return this.toString() + " est inférieure à " + aComparer.toString() ; + } + return this.toString() + " est supérieure à " + aComparer.toString() ; + } + + public static void main(String[] args) { + Date d = new Date(15,10,2025); + //System.out.println(d); + Date lendemain = d.lendemain(); + //System.out.println(lendemain); + System.out.println(d.compareDates(new Date(17,9,2025))); + } +} \ No newline at end of file diff --git a/DEV2.1/TP04/Lendemains.java b/DEV2.1/TP04/Lendemains.java new file mode 100644 index 0000000..e69de29 diff --git a/DEV2.1/TP04/Periode.class b/DEV2.1/TP04/Periode.class new file mode 100644 index 0000000..590b498 Binary files /dev/null and b/DEV2.1/TP04/Periode.class differ diff --git a/DEV2.1/TP04/Periode.java b/DEV2.1/TP04/Periode.java new file mode 100644 index 0000000..eec64b4 --- /dev/null +++ b/DEV2.1/TP04/Periode.java @@ -0,0 +1,35 @@ +public class Periode { + private Date debut; + private Date fin; + + public Periode(Date debut, Date fin) { + this.debut = debut; + this.fin = fin; + } + + public String toString() { + return this.debut.toString() + " - " + this.fin.toString(); + } + + public void rallongeUneJournee() { + this.fin = this.fin.lendemain(); + } + + public int nombreDeJours() { + int compteur = 0; + Date temp = this.debut; + while (!temp.dateEgaleA(this.fin)) { + compteur++; + temp = temp.lendemain(); + } + return compteur; + } + + public static void main(String[] args) { + Periode p = new Periode(new Date(12,2,2025), new Date(17,2,2025)); + System.out.println(p); + p.rallongeUneJournee(); + System.out.println(p); + System.out.println("Nombre de jours entre les 2 dates : " + p.nombreDeJours()); + } +} \ No newline at end of file diff --git a/DEV2.1/TP04/Progression.class b/DEV2.1/TP04/Progression.class new file mode 100644 index 0000000..285e007 Binary files /dev/null and b/DEV2.1/TP04/Progression.class differ diff --git a/DEV2.1/TP04/Progression.java b/DEV2.1/TP04/Progression.java new file mode 100644 index 0000000..17ad831 --- /dev/null +++ b/DEV2.1/TP04/Progression.java @@ -0,0 +1,12 @@ +public class Progression { + public static void main(String[] args) { + Compteur c = new Compteur(); + for (int i = 0; i < 5; i++) { + c.plusUn(); + } + for (int i = 0; i < 5; i++) { + System.out.println(c.toString()); + c.plusUn(); + } + } +} \ No newline at end of file diff --git a/DEV2.1/TP04/TestDate.java b/DEV2.1/TP04/TestDate.java new file mode 100644 index 0000000..e69de29 diff --git a/DEV2.1/TP05/BaseHuit.class b/DEV2.1/TP05/BaseHuit.class new file mode 100644 index 0000000..18c93ef Binary files /dev/null and b/DEV2.1/TP05/BaseHuit.class differ diff --git a/DEV2.1/TP05/BaseHuit.java b/DEV2.1/TP05/BaseHuit.java new file mode 100644 index 0000000..422ad02 --- /dev/null +++ b/DEV2.1/TP05/BaseHuit.java @@ -0,0 +1,10 @@ +public class BaseHuit { + public static void main(String[] args) { + if (args.length == 0 || args.length >= 2) { + System.out.println("Nombre d'arguments incorrect."); + } + else { + System.out.println(Integer.toHexString(Integer.parseInt(args[0], 8))); + } + } +} \ No newline at end of file diff --git a/DEV2.1/TP05/Documentation.class b/DEV2.1/TP05/Documentation.class new file mode 100644 index 0000000..d3208f9 Binary files /dev/null and b/DEV2.1/TP05/Documentation.class differ diff --git a/DEV2.1/TP05/Documentation.java b/DEV2.1/TP05/Documentation.java new file mode 100644 index 0000000..2ece465 --- /dev/null +++ b/DEV2.1/TP05/Documentation.java @@ -0,0 +1,17 @@ +// La classe String se trouve dans le package java.lang +// Elle hérite de la classe Object +// Il existe 8 méthodes héritées de la classe Object + + +public class Documentation { + public static void main(String[] args) { + if (args.length == 0) { + System.out.println("Aucun argument en ligne de commande."); + } + else { + for (int i = 0; i < args.length; i++) { + System.out.println(args[i].toUpperCase()); + } + } + } +} \ No newline at end of file diff --git a/DEV2.1/TP05/Gris.class b/DEV2.1/TP05/Gris.class new file mode 100644 index 0000000..da103b2 Binary files /dev/null and b/DEV2.1/TP05/Gris.class differ diff --git a/DEV2.1/TP05/Gris.java b/DEV2.1/TP05/Gris.java new file mode 100644 index 0000000..e631f56 --- /dev/null +++ b/DEV2.1/TP05/Gris.java @@ -0,0 +1,22 @@ +import java.awt.*; +import javax.swing.*; + +public class Gris extends Color { + + public Gris(int n) { + super(n,n,n); + } + + public static void main(String[] args) { + Gris couleur = new Gris(50); + JFrame fenetre = new JFrame(); + fenetre.setSize(200, 200); + fenetre.setLocation(100, 100); + fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + JTextArea etiquette = new JTextArea("Bonjour !"); + etiquette.setBackground(couleur); // Fonctionne + fenetre.add(etiquette, BorderLayout.CENTER); + fenetre.setVisible(true); + + } +} \ No newline at end of file diff --git a/DEV2.1/TP05/Metrique.class b/DEV2.1/TP05/Metrique.class new file mode 100644 index 0000000..dfdb834 Binary files /dev/null and b/DEV2.1/TP05/Metrique.class differ diff --git a/DEV2.1/TP05/Metrique.java b/DEV2.1/TP05/Metrique.java new file mode 100644 index 0000000..fdebe3a --- /dev/null +++ b/DEV2.1/TP05/Metrique.java @@ -0,0 +1,74 @@ +import java.awt.print.Paper; + +public class Metrique extends Paper { + public Metrique() { + super(); + // WIDTH : 21*(1cm in inches)*72 HEIGHT : 29,7*(1cm en inches)*72 + this.setSize(595.27584, 841.88952); + // MARGE : 1.5*(1cm in inches)*72 DECALAGE : 3cm = 85.0392 1/72inches + this.setImageableArea(42.519672, 42.519672, 510.23664, 756.85032); + } + + public double getMetricHeight() { + return this.getHeight() / 72 * 25.4; // 1inch = 25.4mm + } + + public double getMetricWidth() { + return this.getWidth() / 72 * 25.4; // 1inch = 25.4mm + } + + public double getMetricImageableHeight() { + return this.getImageableHeight() / 72 * 25.4; // 1inch = 25.4mm + } + + public double getMetricImageableWidth() { + return this.getImageableWidth() / 72 * 25.4; // 1inch = 25.4mm + } + + public double getMetricImageableX() { + return this.getImageableX() / 72 * 25.4; // 1inch = 25.4mm + } + + public double getMetricImageableY() { + return this.getImageableY() / 72 * 25.4; // 1inch = 25.4mm + } + + public void setMetricImageableArea(double x, double y, double width, double height) { + this.setImageableArea( + x * 0.393701 * 72, + y * 0.393701 * 72, + width * 0.393701 * 72, + height * 0.393701 * 72 + ); + } + + public void setMetricSize(double width, double height) { + this.setSize( + width * 0.393701 * 72, + height * 0.393701 * 72 + ); + } + + public static void main(String[] args) { + Metrique papier = new Metrique(); + System.out.println("TESTS DE DEPART : "); + System.out.println("" + papier.getMetricHeight()); + System.out.println("" + papier.getMetricWidth()); + System.out.println("" + papier.getMetricImageableHeight()); + System.out.println("" + papier.getMetricImageableWidth()); + System.out.println("" + papier.getMetricImageableX()); + System.out.println("" + papier.getMetricImageableY()); + + System.out.println("MODIFICATION DES DIMENSIONS : "); + papier.setMetricSize(50,100); + System.out.println("" + papier.getMetricHeight()); + System.out.println("" + papier.getMetricWidth()); + + System.out.println("MODIFICATION DE LA TAILLE IMAGEABLE: "); + papier.setMetricImageableArea(5,5,40,80); + System.out.println("" + papier.getMetricImageableX()); + System.out.println("" + papier.getMetricImageableY()); + System.out.println("" + papier.getMetricImageableHeight()); + System.out.println("" + papier.getMetricImageableWidth()); + } +} \ No newline at end of file