TP03 fin ; TP04

This commit is contained in:
HORVILLE 2022-02-08 17:20:59 +01:00
parent 759ba2dc5d
commit f24050cb7e
22 changed files with 263 additions and 0 deletions

Binary file not shown.

View File

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

BIN
APL2.1/TP03/Rose/Rose.class Normal file

Binary file not shown.

View File

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

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

Binary file not shown.

View File

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

Binary file not shown.

View File

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

Binary file not shown.

View File

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

Binary file not shown.

View File

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

Binary file not shown.

View File

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

Binary file not shown.

View File

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

Binary file not shown.

View File

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

Binary file not shown.

View File

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

Binary file not shown.

View File

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