End chapter 13
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								bin/C13_Heritage/13_objects2_16x9_fr.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/C13_Heritage/13_objects2_16x9_fr.pdf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/C13_Heritage/App.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/C13_Heritage/App.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/C13_Heritage/Building.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/C13_Heritage/Building.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/C13_Heritage/Car.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/C13_Heritage/Car.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/C13_Heritage/House.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/C13_Heritage/House.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/C13_Heritage/Test.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/C13_Heritage/Test.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/C13_Heritage/Truck.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/C13_Heritage/Truck.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/C13_Heritage/Vehicle.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/C13_Heritage/Vehicle.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								src/C13_Heritage/13_objects2_16x9_fr.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/C13_Heritage/13_objects2_16x9_fr.pdf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										22
									
								
								src/C13_Heritage/App.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/C13_Heritage/App.java
									
									
									
									
									
										Normal file
									
								
							| @@ -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()); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										25
									
								
								src/C13_Heritage/Building.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/C13_Heritage/Building.java
									
									
									
									
									
										Normal file
									
								
							| @@ -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; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								src/C13_Heritage/Car.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/C13_Heritage/Car.java
									
									
									
									
									
										Normal file
									
								
							| @@ -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"); | ||||
|     } | ||||
|      | ||||
| } | ||||
							
								
								
									
										22
									
								
								src/C13_Heritage/House.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/C13_Heritage/House.java
									
									
									
									
									
										Normal file
									
								
							| @@ -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; | ||||
|     } | ||||
|  | ||||
| } | ||||
							
								
								
									
										14
									
								
								src/C13_Heritage/Test.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/C13_Heritage/Test.java
									
									
									
									
									
										Normal file
									
								
							| @@ -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); | ||||
|          | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								src/C13_Heritage/Truck.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/C13_Heritage/Truck.java
									
									
									
									
									
										Normal file
									
								
							| @@ -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"); | ||||
|     } | ||||
|      | ||||
| } | ||||
							
								
								
									
										24
									
								
								src/C13_Heritage/Vehicle.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/C13_Heritage/Vehicle.java
									
									
									
									
									
										Normal file
									
								
							| @@ -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; | ||||
|     } | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user