lab7 - classe et tableaux
This commit is contained in:
		
							
								
								
									
										7
									
								
								.vscode/launch.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										7
									
								
								.vscode/launch.json
									
									
									
									
										vendored
									
									
								
							| @@ -4,6 +4,13 @@ | ||||
|     // Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387 | ||||
|     "version": "0.2.0", | ||||
|     "configurations": [ | ||||
|         { | ||||
|             "type": "java", | ||||
|             "name": "Launch Task2Runner", | ||||
|             "request": "launch", | ||||
|             "mainClass": "lab7_Classe_et_tableaux.Task2Runner", | ||||
|             "projectName": "Labo_6a2f7ad1" | ||||
|         }, | ||||
|         { | ||||
|             "type": "java", | ||||
|             "name": "Launch Task1Runner", | ||||
|   | ||||
							
								
								
									
										98
									
								
								src/lab7_Classe_et_tableaux/Auto.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										98
									
								
								src/lab7_Classe_et_tableaux/Auto.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,98 @@ | ||||
| package lab7_Classe_et_tableaux; | ||||
|  | ||||
| /** | ||||
|  * @author Rémi Heredero | ||||
|  * @Klagarge | ||||
|  */ | ||||
| public class Auto { | ||||
|     private String name; | ||||
|     private double horsepower; | ||||
|     private double maxSpeed; | ||||
|     public Consommation consommation = new Consommation(); | ||||
|  | ||||
|     /** | ||||
|      * Définition d'une voiture | ||||
|      * @param name Nom du type de voiture | ||||
|      * @param horsepower Puissance en chevaux | ||||
|      * @param maxSpeed Vitesse maximale | ||||
|      * @author Rémi Heredero | ||||
|      */ | ||||
|     public Auto(String name, double horsepower, double maxSpeed){ | ||||
|         this.name = name; | ||||
|         this.horsepower = horsepower; | ||||
|         this.maxSpeed = maxSpeed; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Définition d'une voiture avec consommation mix | ||||
|      * @param name Nom du type de voiture | ||||
|      * @param horsepower Puissance en chevaux | ||||
|      * @param maxSpeed Vitesse maximale | ||||
|      * @param urban valeur en l/100km pen régime urbain | ||||
|      * @author Rémi Heredero | ||||
|      */ | ||||
|     public Auto(String name, double horsepower, double maxSpeed, double combined){ | ||||
|         this.name = name; | ||||
|         this.horsepower = horsepower; | ||||
|         this.maxSpeed = maxSpeed; | ||||
|         consommation.combined = combined; | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * Définition complète d'une voiture | ||||
|      * @param name Nom du type de voiture | ||||
|      * @param horsepower Puissance en chevaux | ||||
|      * @param maxSpeed Vitesse maximale | ||||
|      * @param urban valeur en l/100km pen régime urbain | ||||
|      * @param highway valeur en l/100km pen régime autoroutier | ||||
|      * @param combined valeur en l/100km pen régime combiné | ||||
|      * @author Rémi Heredero | ||||
|      */ | ||||
|     public Auto(String name, double horsepower, double maxSpeed, double urban, double highway, double combined){ | ||||
|         this.name = name; | ||||
|         this.horsepower = horsepower; | ||||
|         this.maxSpeed = maxSpeed; | ||||
|         consommation.urban = urban; | ||||
|         consommation.highway = highway; | ||||
|         consommation.combined = combined; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Renvoie sous forme de texte les caractéristique principale d'une voiture | ||||
|      */ | ||||
|     public String toString() { | ||||
|         String s = ""; | ||||
|         s += this.name; | ||||
|         s += ", "; | ||||
|         s += this.horsepower; | ||||
|         s += " hp, "; | ||||
|         s += this.maxSpeed; | ||||
|         s += " km/h"; | ||||
|         return s; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Test si une voiture est vraiment rapide (>200km/h) | ||||
|      * @return vrai si la voiture est plus rapide que 200 km/h | ||||
|      */ | ||||
|     public boolean isVeryFast() { | ||||
|         boolean fast = false; | ||||
|         if (this.maxSpeed>200) { | ||||
|             fast = true; | ||||
|         } | ||||
|         return fast; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Test si une voiture est "écologique" | ||||
|      * @return vrai si la consommation mix est inférieur à 8 l/100km et la consommation urbaine <10l/100km | ||||
|      */ | ||||
|     public boolean isEco() { | ||||
|         boolean eco = false; | ||||
|         if (consommation.combined<8 && consommation.urban<10) { | ||||
|             eco = true; | ||||
|         } | ||||
|         return eco; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										33
									
								
								src/lab7_Classe_et_tableaux/Consommation.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/lab7_Classe_et_tableaux/Consommation.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| package lab7_Classe_et_tableaux; | ||||
|  | ||||
| /** | ||||
|  * @author Rémi Heredero | ||||
|  * @Klagarge | ||||
|  */ | ||||
| public class Consommation { | ||||
|     double urban; | ||||
|     double highway; | ||||
|     double combined; | ||||
|  | ||||
|     Consommation(){}; | ||||
|      | ||||
|     /** | ||||
|      * Consommation mix | ||||
|      * @param combined valeur en l/100km pen régime combiné | ||||
|      */ | ||||
|     Consommation(double combined){ | ||||
|         this.combined = combined; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Tous les types de consommation d'une voiture | ||||
|      * @param urban valeur en l/100km pen régime urbain | ||||
|      * @param highway valeur en l/100km pen régime autoroutier | ||||
|      * @param combined valeur en l/100km pen régime combiné | ||||
|      */ | ||||
|     Consommation(double urban, double highway, double combined){ | ||||
|         this.urban = urban; | ||||
|         this.highway = highway; | ||||
|         this.combined = combined; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										80
									
								
								src/lab7_Classe_et_tableaux/Garage.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								src/lab7_Classe_et_tableaux/Garage.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,80 @@ | ||||
| package lab7_Classe_et_tableaux; | ||||
|  | ||||
| /** | ||||
|  * @author Rémi Heredero | ||||
|  * @Klagarge | ||||
|  */ | ||||
| public class Garage { | ||||
|     private Auto[] stock = new Auto[100]; | ||||
|     private int nbrOfCars = 0; | ||||
|  | ||||
|     /** | ||||
|      * Ajout d'une voiture | ||||
|      * @param a objet de Classe Auto | ||||
|      */ | ||||
|     public void addCar(Auto a) { | ||||
|         stock[nbrOfCars] = a; | ||||
|         this.nbrOfCars++; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Retourne le nombre de voiture présente dans le garage | ||||
|      * @return le nombre de voiture dans le garage | ||||
|      */ | ||||
|     public int getNumberOfCars() { | ||||
|         return this.nbrOfCars; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Retourne sous forme de String toutes les voitures présente dans le garage | ||||
|      */ | ||||
|     public String toString() { | ||||
|         String s = ""; | ||||
|         for (int i = 0; i < stock.length; i++) { | ||||
|             if (stock[i] != null) { | ||||
|                 s += "Car "; | ||||
|                 s += i; | ||||
|                 s += " : "; | ||||
|                 s += stock[i].toString(); | ||||
|                 s += "\n"; | ||||
|             } | ||||
|         } | ||||
|         return s; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Retourne sous forme de String les voiture vraiment rapide (>200km/h) présente dans le garage | ||||
|      * @return Liste des voiture qui vont à plus de 200 km/h | ||||
|      */ | ||||
|     public String displayFastCars() { | ||||
|         String s = ""; | ||||
|         for (int i = 0; i < stock.length; i++) { | ||||
|             if ((stock[i] != null) && (stock[i].isVeryFast())) { | ||||
|                 s += "Car "; | ||||
|                 s += i; | ||||
|                 s += " : "; | ||||
|                 s += stock[i].toString(); | ||||
|                 s += "\n"; | ||||
|             } | ||||
|         } | ||||
|         return s; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Retourne toutes les voitures "écologique" présente dans le garage | ||||
|      * @return liste des voiture <8l/100km mix et <10l/100km urbain présentent dans le garage | ||||
|      */ | ||||
|     public String displayEcoCars() { | ||||
|         String s = ""; | ||||
|         for (int i = 0; i < stock.length; i++) { | ||||
|             if ((stock[i] != null) && (stock[i].isEco())) { | ||||
|                 s += "Car "; | ||||
|                 s += i; | ||||
|                 s += " : "; | ||||
|                 s += stock[i].toString(); | ||||
|                 s += "\n"; | ||||
|             } | ||||
|         } | ||||
|         return s; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										20
									
								
								src/lab7_Classe_et_tableaux/Task2Runner.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								src/lab7_Classe_et_tableaux/Task2Runner.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| package lab7_Classe_et_tableaux; | ||||
|  | ||||
| public class Task2Runner { | ||||
|     public static void main(String[] args) { | ||||
|          | ||||
|         //Auto audi = new Auto("Audi TT", 135, 250); | ||||
|         Garage perso = new Garage(); | ||||
|         perso.addCar(new Auto("Audi TT", 135, 250, 12, 7, 8.3)); | ||||
|         perso.addCar(new Auto("VW Golf", 100, 180, 9, 6.5, 7.5)); | ||||
|         perso.addCar(new Auto("Lancia Y", 60, 150, 8, 5, 6.6)); | ||||
|         perso.addCar(new Auto("Porsche 911", 400, 312, 35, 15, 20)); | ||||
|         System.out.println("Number of car in garage: " + perso.getNumberOfCars()); | ||||
|         System.out.println(""); | ||||
|         System.out.println(perso.toString()); | ||||
|         System.out.println(""); | ||||
|         System.out.println("Garage fast cars: \n" + perso.displayFastCars()); | ||||
|         System.out.println(""); | ||||
|         System.out.println("Garage \"eco\" cars: \n" + perso.displayEcoCars()); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user