TP4
This commit is contained in:
BIN
APL2.1/TP4/Date/Date.class
Normal file
BIN
APL2.1/TP4/Date/Date.class
Normal file
Binary file not shown.
44
APL2.1/TP4/Date/Date.java
Normal file
44
APL2.1/TP4/Date/Date.java
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
public class Date {
|
||||
|
||||
private int year;
|
||||
private int month;
|
||||
private int day;
|
||||
|
||||
public Date(int d, int m, int y) {
|
||||
this.year = y;
|
||||
this.month = m;
|
||||
this.day = d;
|
||||
}
|
||||
public int Day() {
|
||||
return this.day;
|
||||
}
|
||||
public int Month() {
|
||||
return this.month;
|
||||
}
|
||||
public int Year() {
|
||||
return this.year;
|
||||
}
|
||||
public String toString() {
|
||||
int i;
|
||||
String sday = Integer.toString(this.day);
|
||||
String smonth = Integer.toString(this.month);
|
||||
String syear = Integer.toString(this.year);
|
||||
if (sday.length() < 2) {
|
||||
for (i = 0; i<2-sday.length(); i++) {
|
||||
sday = "0"+sday;
|
||||
}
|
||||
}
|
||||
if (smonth.length() < 2) {
|
||||
for (i = 0; i<2-smonth.length(); i++) {
|
||||
smonth = "0"+smonth;
|
||||
}
|
||||
}
|
||||
if (syear.length() < 4) {
|
||||
for (i = 0; i<4-syear.length(); i++) {
|
||||
syear = "0"+syear;
|
||||
}
|
||||
}
|
||||
return syear+"-"+smonth+"-"+sday;
|
||||
}
|
||||
}
|
||||
BIN
APL2.1/TP4/Date/Testdate.class
Normal file
BIN
APL2.1/TP4/Date/Testdate.class
Normal file
Binary file not shown.
8
APL2.1/TP4/Date/Testdate.java
Normal file
8
APL2.1/TP4/Date/Testdate.java
Normal file
@@ -0,0 +1,8 @@
|
||||
public class Testdate {
|
||||
public static void main(String[] args) {
|
||||
Date date = new Date(8,2,2022);
|
||||
Date date2 = new Date(31, 1, 2022);
|
||||
|
||||
System.out.println("Date du jour : " + date);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user