Fin du TP Heritage

This commit is contained in:
Simoes Lukas 2025-02-06 14:32:11 +01:00
parent 209f320a5a
commit dd0903e9fc
21 changed files with 304 additions and 20 deletions

@ -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.

Binary file not shown.

@ -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);
}

BIN
DEV2.1/TP04/Compteur.class Normal file

Binary file not shown.

16
DEV2.1/TP04/Compteur.java Normal file

@ -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);
}
}

BIN
DEV2.1/TP04/Date.class Normal file

Binary file not shown.

69
DEV2.1/TP04/Date.java Normal file

@ -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)));
}
}

BIN
DEV2.1/TP04/Periode.class Normal file

Binary file not shown.

35
DEV2.1/TP04/Periode.java Normal file

@ -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());
}
}

Binary file not shown.

@ -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();
}
}
}

BIN
DEV2.1/TP05/BaseHuit.class Normal file

Binary file not shown.

10
DEV2.1/TP05/BaseHuit.java Normal file

@ -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)));
}
}
}

Binary file not shown.

@ -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());
}
}
}
}

BIN
DEV2.1/TP05/Gris.class Normal file

Binary file not shown.

22
DEV2.1/TP05/Gris.java Normal file

@ -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);
}
}

BIN
DEV2.1/TP05/Metrique.class Normal file

Binary file not shown.

74
DEV2.1/TP05/Metrique.java Normal file

@ -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());
}
}