diff --git a/bin/C13_Heritage/13_objects2_16x9_fr.pdf b/bin/C13_Heritage/13_objects2_16x9_fr.pdf new file mode 100644 index 0000000..53e0f80 Binary files /dev/null and b/bin/C13_Heritage/13_objects2_16x9_fr.pdf differ diff --git a/bin/C13_Heritage/App.class b/bin/C13_Heritage/App.class new file mode 100644 index 0000000..600f699 Binary files /dev/null and b/bin/C13_Heritage/App.class differ diff --git a/bin/C13_Heritage/Building.class b/bin/C13_Heritage/Building.class new file mode 100644 index 0000000..5aaadae Binary files /dev/null and b/bin/C13_Heritage/Building.class differ diff --git a/bin/C13_Heritage/Car.class b/bin/C13_Heritage/Car.class new file mode 100644 index 0000000..897b803 Binary files /dev/null and b/bin/C13_Heritage/Car.class differ diff --git a/bin/C13_Heritage/House.class b/bin/C13_Heritage/House.class new file mode 100644 index 0000000..17dad92 Binary files /dev/null and b/bin/C13_Heritage/House.class differ diff --git a/bin/C13_Heritage/Test.class b/bin/C13_Heritage/Test.class new file mode 100644 index 0000000..f8dac5f Binary files /dev/null and b/bin/C13_Heritage/Test.class differ diff --git a/bin/C13_Heritage/Truck.class b/bin/C13_Heritage/Truck.class new file mode 100644 index 0000000..6d4e2a8 Binary files /dev/null and b/bin/C13_Heritage/Truck.class differ diff --git a/bin/C13_Heritage/Vehicle.class b/bin/C13_Heritage/Vehicle.class new file mode 100644 index 0000000..5401202 Binary files /dev/null and b/bin/C13_Heritage/Vehicle.class differ diff --git a/src/C13_Heritage/13_objects2_16x9_fr.pdf b/src/C13_Heritage/13_objects2_16x9_fr.pdf new file mode 100644 index 0000000..53e0f80 Binary files /dev/null and b/src/C13_Heritage/13_objects2_16x9_fr.pdf differ diff --git a/src/C13_Heritage/App.java b/src/C13_Heritage/App.java new file mode 100644 index 0000000..e448a9d --- /dev/null +++ b/src/C13_Heritage/App.java @@ -0,0 +1,22 @@ +package C13_Heritage; + +public class App { + public static void main(String[] args) { + House maison = new House("Route du stade 30", 5); + House gp = new House(null, 0); + Building hes = new Building("Rue de l'industrie"); + Building alpolEPFL = new Building(); + + System.out.println(maison.toString()); + System.out.println(gp.toString()); + System.out.println(hes.toString()); + System.out.println(alpolEPFL.toString()); + + gp.setAddress("Toulouse"); + gp.setnRooms(4); + alpolEPFL.setAddress("Sion"); + + System.out.println(gp.toString()); + System.out.println(alpolEPFL.toString()); + } +} diff --git a/src/C13_Heritage/Building.java b/src/C13_Heritage/Building.java new file mode 100644 index 0000000..59c0b44 --- /dev/null +++ b/src/C13_Heritage/Building.java @@ -0,0 +1,25 @@ +package C13_Heritage; + +public class Building { + private String address; + + Building(){ + + } + Building(String address){ + this.address = address; + } + + void setAddress(String address){ + this.address = address; + } + + public String getAddress() { + return address; + } + + @Override + public String toString() { + return Building.class.getName() + "@" + address; + } +} diff --git a/src/C13_Heritage/Car.java b/src/C13_Heritage/Car.java new file mode 100644 index 0000000..e47ae40 --- /dev/null +++ b/src/C13_Heritage/Car.java @@ -0,0 +1,19 @@ +package C13_Heritage; + +public class Car extends Vehicle{ + + Car(int year, int price) { + super(year, price); + } + + @Override + void start() { + System.out.println("Vroum vroum"); + } + + @Override + void accelerate() { + System.out.println("Vrooom"); + } + +} diff --git a/src/C13_Heritage/House.java b/src/C13_Heritage/House.java new file mode 100644 index 0000000..1c30991 --- /dev/null +++ b/src/C13_Heritage/House.java @@ -0,0 +1,22 @@ +package C13_Heritage; + +public class House extends Building{ + private int nRooms; + House(String address, int nRooms){ + super(address); + this.nRooms = Math.abs(nRooms); + } + + public void setnRooms(int nRooms) { + this.nRooms = Math.abs(nRooms); + } + public int getnRooms() { + return nRooms; + } + + @Override + public String toString() { + return super.toString() + "#" + nRooms; + } + +} diff --git a/src/C13_Heritage/Test.java b/src/C13_Heritage/Test.java new file mode 100644 index 0000000..4050857 --- /dev/null +++ b/src/C13_Heritage/Test.java @@ -0,0 +1,14 @@ +package C13_Heritage; + +public class Test { + public static void main(String[] args) { + Car suzuki = new Car(2003, 4000); + Truck tracteur = new Truck(2020, 12000); + Car citroen = new Car(2006, 8000); + + System.out.println(suzuki); + System.out.println(tracteur); + System.out.println(citroen); + + } +} diff --git a/src/C13_Heritage/Truck.java b/src/C13_Heritage/Truck.java new file mode 100644 index 0000000..3c9130a --- /dev/null +++ b/src/C13_Heritage/Truck.java @@ -0,0 +1,19 @@ +package C13_Heritage; + +public class Truck extends Vehicle{ + + Truck(int year, int price) { + super(year, price); + } + + @Override + void start() { + System.out.println("Peuf-peuf"); + } + + @Override + void accelerate() { + System.out.println("Broum"); + } + +} diff --git a/src/C13_Heritage/Vehicle.java b/src/C13_Heritage/Vehicle.java new file mode 100644 index 0000000..8d13bea --- /dev/null +++ b/src/C13_Heritage/Vehicle.java @@ -0,0 +1,24 @@ +package C13_Heritage; + +public abstract class Vehicle { + private static int nVehicle; + private int matricule; + private int year; + private int price; + + Vehicle(int year, int price){ + this.year = year; + this.price = price; + nVehicle++; + this.matricule = nVehicle; + } + + abstract void start(); + abstract void accelerate(); + + @Override + public String toString() { + return "Vehicle " + matricule + ". Built in " + year + ", price: " + price; + } + +}