initial commit

This commit is contained in:
Guillaume-Sanchez
2026-05-26 13:56:03 +02:00
parent 4c720637a1
commit ff4bb12d22
539 changed files with 12415 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
# UTC 503 17/02/2025
## Comment appeler une nouvelle class / comment créer un Objet :
```
"Nom de la class" "nom de l'objet" = new "NomConstructeur()"
Exemple
Ville villeParDefaut = new Ville();
```
## Getter et Setteur
Methode qui vont nous permetre d'avoir accès à des variables ou pour apporter des modifications.
>Getter -> Accesseurs en FR
>Setter -> Mutateurs en FR
## this
Binary file not shown.
@@ -0,0 +1,480 @@
# TDs Entrainement Java Guillaume Sanchez
## Exercice 1 : Création d'une classe Personne
### 1. Crée une classe Personne avec les attributs suivants :
- nom (String)
- âge (int)
```
public class Personne {
private String nom;
private int age;
Personne(){
this.nom = "Inconnu";
this.age = 0;
}
Personne(String nomInput, int ageInput){
this.nom = nomInput;
this.age = ageInput;
}
}
```
### 2. Crée les getters et setters pour ces attributs.
```
public class Personne {
private String nom;
private int age;
Personne(){
this.nom = "Inconnu";
this.age = 0;
}
Personne(String nomInput, int ageInput){
this.nom = nomInput;
this.age = ageInput;
}
public String getNom(){
return this.nom;
}
public void setNom(String nomInput){
this.nom = nomInput;
}
public int getAge(){
return this.age;
}
public void setAge(int ageInput){
this.age = ageInput;
}
}
```
### 3. Dans la classe Main, crée un objet Personne, affecte-lui un nom et un âge, puis affiche ses valeurs.
```
public class App {
public static void main(String[] args) throws Exception {
// Création d'une personne :
Personne personne1 = new Personne("Jean", 25);
// Affichage des données de la personne :
System.out.println(personne1.getNom() +
" a " + personne1.getAge() + " ans.");
}
}
```
Ce code donne en résultat :
`Jean a 25 ans.`
## Exercice 2 : Gestion dun Compte Bancaire
### 1. Crée une classe CompteBancaire avec les attributs privés :
- titulaire (String)
- solde (double)
```
public class CompteBancaire {
private double solde;
private String titulaire;
CompteBancaire(){
this.solde = 0;
this.titulaire = "Inconnu";
}
CompteBancaire(double soldeInput, String titulaireInput){
this.solde = soldeInput;
this.titulaire = titulaireInput;
}
}
```
### 2. Implémente les getters et setters, mais :
- Empêche la modification du solde en dehors des méthodes de la classe.
- Ajoute une méthode deposer(double montant) qui augmente le solde.
- Ajoute une méthode retirer (double montant) qui diminue le solde uniquement si l'utilisateur a assez d'argent.
```
public class CompteBancaire {
private double solde;
private String titulaire;
CompteBancaire(){
this.solde = 0;
this.titulaire = "Inconnu";
}
CompteBancaire(double soldeInput, String titulaireInput){
this.solde = soldeInput;
this.titulaire = titulaireInput;
}
public void deposer(double montant){
this.setSolde(this.getSolde() + montant);
}
public void retirer(double montant){
this.setSolde(this.getSolde() - montant);
}
public double getSolde(){
return this.solde;
}
private void setSolde(double soldeInput){
this.solde = soldeInput;
}
public String getTitulaire(){
return this.titulaire;
}
public void setTitulaire(String titulaireInput){
this.titulaire = titulaireInput;
}
}
```
### 3. Dans Main, crée un compte, effectue des dépôts et retraits, et affiche le solde.
```
public class App {
public static void main(String[] args) throws Exception {
// Création d'un compte bancaire :
CompteBancaire compte1 = new CompteBancaire(1000, "Jean");
// affichage des données initialisées :
System.out.println(compte1.getTitulaire()
+ " a un solde de " + compte1.getSolde() + " euros.");
// dépôt de 500 euros :
compte1.deposer(500);
// affichage du nouveau solde :
System.out.println(compte1.getTitulaire()
+ " a un solde de " + compte1.getSolde() + " euros.");
// retrait de 200 euros :
compte1.retirer(200);
// affichage du nouveau solde :
System.out.println(compte1.getTitulaire()
+ " a un solde de " + compte1.getSolde() + " euros.");
}
}
```
Ce code donne en résultat :
```
Jean a un solde de 1000.0 euros.
Jean a un solde de 1500.0 euros.
Jean a un solde de 1300.0 euros.
```
## Exercice 3 : Gestion d'un Produit
### 1. Crée une classe Produit avec :
- nom (String)
- prix (double)
- quantiteStock (int)
```
public class Produit {
private String nom;
private double prix;
private int quantiteStock;
Produit(){
this.nom = "Inconnu";
this.prix = 0;
}
Produit(String nomInput, double prixInput){
this.nom = nomInput;
this.prix = prixInput;
}
}
```
### 2. Implémente les getters et setters, en ajoutant :
- Une validation dans setPrix(double prix): ne pas autoriser un prix négatif.
- Une validation dans setQuantiteStock(int quantite): ne pas accepter une
quantité négative.
```
public class Produit {
private String nom;
private double prix;
private int quantiteStock;
Produit(){
this.nom = "Inconnu";
this.prix = 0;
}
Produit(String nomInput, double prixInput){
this.nom = nomInput;
this.prix = prixInput;
}
public String getNom(){
return this.nom;
}
public void setNom(String nomInput){
this.nom = nomInput;
}
public double getPrix(){
return this.prix;
}
public void setPrix(double prixInput){
if(prixInput < 0){
System.out.println("
Le prix ne peut pas être négatif."); }
else{
this.prix = prixInput;
}
}
public int getQuantiteStock(){
return this.quantiteStock;
}
public void setQuantiteStock(int quantiteStockInput){
if(quantiteStockInput < 0){
System.out.println("
La quantité ne peut pas être négative.");
}
else{
this.quantiteStock = quantiteStockInput;
}
}
}
```
### 3. Dans Main, crée un produit et teste les restrictions.
```
public class App {
public static void main(String[] args) throws Exception {
// Création d'un produit :
Produit produit1 = new Produit("Ordinateur", 1000);
// Essai de modification du prix avec une valeur négative
// Affiche un message d'erreur :
produit1.setPrix(-5);
// Essai de modification du prix avec une valeur positive :
produit1.setPrix(5);
// Affichage du nouveau prix :
System.out.println("Le prix est " +
produit1.getPrix() + " euros.");
// Essai de modification du stock avec une valeur négative
// Affiche un message d'erreur :
produit1.setQuantiteStock(-5);
// Essai de modification du stock avec une valeur positive :
produit1.setQuantiteStock(5);
// Affichage de la nouvelle quantité de stock :
System.out.println("La Quantité du Stock est " +
produit1.getQuantiteStock());
}
}
```
Ce code donne en résultat :
```
Le prix ne peut pas être négatif.
Le prix est 5.0 euros.
La quantité ne peut pas être négative.
La Quantité du Stock est 5
```
## Exercice 4 : Gestion des étudiants
### 1. Crée une classe Etudiant avec les attributs :
- nom (String)
- moyenne (double)
```
public class Etudiant {
private String nom;
private double moyenne;
Etudiant() {
this.nom = "Inconnu";
this.moyenne = 0;
}
Etudiant(String nomInput, double moyenneInput) {
this.nom = nomInput;
this.moyenne = moyenneInput;
}
}
```
### 2. Implémente les getters et setters avec une contrainte :
- La moyenne doit être comprise entre 0 et 20. Si une valeur hors de cet intervalle est donnée, elle nest pas prise en compte.
```
public class Etudiant {
private String nom;
private double moyenne = -1;
/* -1 instancié par defaut pour qu'elle
ne soit pas prise en compte en cas de mauvaise
donnée
*/
Etudiant() {
this.nom = "Inconnu";
this.moyenne = -1;
}
Etudiant(String nomInput, double moyenneInput) {
this.nom = nomInput;
if(moyenneInput < 0 || moyenneInput > 20) {
System.out.println("La moyenne doit être comprise entre 0 et 20.");
}
else{
this.moyenne = moyenneInput;
}
}
public String getNom() {
return this.nom;
}
public void setNom(String nomInput) {
this.nom = nomInput;
}
public double getMoyenne() {
return this.moyenne;
}
public void setMoyenne(double moyenneInput) {
if(moyenneInput < 0 || moyenneInput > 20) {
System.out.println("La moyenne doit être comprise entre 0 et 20.");
}
else{
this.moyenne = moyenneInput;
}
}
}
```
### 3. Ajoute une méthode afficherDetails() pour afficher les infos de l’étudiant.
```
public void afficherDetails() {
System.out.println("Nom : " + this.nom);
if(this.moyenne >= 0 && this.moyenne <= 20) {
System.out.println("Moyenne : " + this.moyenne);
}
else {
System.out.println("Moyenne : Non définie.");
}
}
```
### 4. Dans Main, crée plusieurs étudiants et teste les restrictions.
```
public class App {
public static void main(String[] args) throws Exception {
System.out.println("--------------------------------------");
// Création d'un Etudiant :
Etudiant etudiant1 = new Etudiant("Jean", 15);
// Utilisation de la méthode afficherDetails() :
etudiant1.afficherDetails();
System.out.println("--------------------------------------");
// Création d'un second Etudiant avec une moyenne incorrecte superieur à 20 :
Etudiant etudiant2 = new Etudiant("Paul", 25);
// Utilisation de la méthode afficherDetails() :
etudiant2.afficherDetails();
System.out.println("--------------------------------------");
// Création d'un troisième Etudiant avec une moyenne incorrecte inferieur à 0 :
Etudiant etudiant3 = new Etudiant("Marie", -5);
etudiant3.afficherDetails();
System.out.println("--------------------------------------");
// Création d'un quatrième Etudiant avec une moyenne correcte :
Etudiant etudiant4 = new Etudiant("Luc", 18);
etudiant4.afficherDetails();
System.out.println("--------------------------------------");
// Tentative de changement de la moyenne avec une valeur positive incorrecte :
etudiant4.setMoyenne(25);
etudiant4.afficherDetails();
System.out.println("--------------------------------------");
// Tentative de changement de la moyenne avec une valeur negative incorrecte :
etudiant4.setMoyenne(-30);
etudiant4.afficherDetails();
System.out.println("--------------------------------------");
// Tentative de changement de la moyenne avec une valeur correcte :
etudiant4.setMoyenne(10);
etudiant4.afficherDetails();
System.out.println("--------------------------------------");
}
}
```
Ce code donne en résultat :
```
--------------------------------------
Nom : Jean
Moyenne : 15.0
--------------------------------------
La moyenne doit être comprise entre 0 et 20.
Nom : Paul
Moyenne : Non définie.
--------------------------------------
La moyenne doit être comprise entre 0 et 20.
Nom : Marie
Moyenne : Non définie.
--------------------------------------
Nom : Luc
Moyenne : 18.0
--------------------------------------
La moyenne doit être comprise entre 0 et 20.
Nom : Luc
Moyenne : 18.0
--------------------------------------
La moyenne doit être comprise entre 0 et 20.
Nom : Luc
Moyenne : 18.0
--------------------------------------
Nom : Luc
Moyenne : 10.0
--------------------------------------
```
Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.
@@ -0,0 +1,30 @@
# TDs Classe Java Guillaume Sanchez
J'ai volontairement sur commenté pour expliquer mon code.
La lecture suit normalement les consignes données.
![Class_Eleve](https://image.noelshack.com/fichiers/2025/08/1/1739816455-class-eleve.png)
J'ai laissé l'arborescence afin de montrer que "gestionEleves" est bien un package. Il est importé dans App.java
![Class_App_Et_Arborescence](https://image.noelshack.com/fichiers/2025/08/1/1739816454-class-app-et-arborescence.png)
Voici ce que ce code retourne :
```
Jean (11.25)
[10, 15, 20, 5, 0, 0, 20, 20]
Jean
11.25
```
`Jean (11.25)` correspond à la ligne 14
`[10, 15, 20, 5, 0, 0, 20, 20]` correspond à la ligne 15
`Jean` correspond à la ligne 16
`11.25` correspond à la ligne 17
On observe que toutes les notes ont bien été ajoutées à “listesNotes”, que “getNom”, “getMoyenne”, “getListeNotes” fonctionne bien et que “ajouterNotes” modifie les notes négatives en 0 et les notes supérieures à 20 en 20.
+18
View File
@@ -0,0 +1,18 @@
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+85
View File
@@ -0,0 +1,85 @@
public class App {
public static void main(String[] args) throws Exception {
// Exercice 1
System.out.println("\n--------------Exercice 1--------------\n");
// Création d'une personne :
Personne personne1 = new Personne("Jean", 25);
// Affichage des données de la personne :
System.out.println(personne1.getNom() +
" a " + personne1.getAge() + " ans.");
// Exercice 2
System.out.println("\n--------------Exercice 2--------------\n");
// Création d'un compte bancaire :
CompteBancaire compte1 = new CompteBancaire(1000, "Jean");
// affichage des données initialisées :
System.out.println(compte1.getTitulaire() + " a un solde de " + compte1.getSolde() + " euros.");
// dépôt de 500 euros :
compte1.deposer(500);
// affichage du nouveau solde :
System.out.println(compte1.getTitulaire() + " a un solde de " + compte1.getSolde() + " euros.");
// retrait de 200 euros :
compte1.retirer(200);
// affichage du nouveau solde :
System.out.println(compte1.getTitulaire() + " a un solde de " + compte1.getSolde() + " euros.");
// Exercice 3
System.out.println("\n--------------Exercice 3--------------\n");
// Création d'un produit :
Produit produit1 = new Produit("Ordinateur", 1000);
// Essai de modification du prix avec une valeur négative
// Affiche un message d'erreur :
produit1.setPrix(-5);
// Essai de modification du prix avec une valeur positive :
produit1.setPrix(5);
// Affichage du nouveau prix :
System.out.println("Le prix est " + produit1.getPrix() + " euros.");
// Essai de modification du stock avec une valeur négative
// Affiche un message d'erreur :
produit1.setQuantiteStock(-5);
// Essai de modification du stock avec une valeur positive :
produit1.setQuantiteStock(5);
// Affichage de la nouvelle quantité de stock :
System.out.println("La Quantité du Stock est " + produit1.getQuantiteStock());
// Exercice 4
System.out.println("\n--------------Exercice 4--------------\n");
// Création d'un Etudiant :
Etudiant etudiant1 = new Etudiant("Jean", 15);
// Utilisation de la méthode afficherDetails() :
etudiant1.afficherDetails();
System.out.println("--------------------------------------");
// Création d'un second Etudiant avec une moyenne incorrecte superieur à 20 :
Etudiant etudiant2 = new Etudiant("Paul", 25);
// Utilisation de la méthode afficherDetails(), normalement, la moyenne ne s'affiche pas :
etudiant2.afficherDetails();
System.out.println("--------------------------------------");
// Création d'un troisième Etudiant avec une moyenne incorrecte inferieur à 0 :
Etudiant etudiant3 = new Etudiant("Marie", -5);
etudiant3.afficherDetails();
System.out.println("--------------------------------------");
// Création d'un quatrième Etudiant avec une moyenne correcte :
Etudiant etudiant4 = new Etudiant("Luc", 18);
etudiant4.afficherDetails();
System.out.println("--------------------------------------");
// Tentative de changement de la moyenne avec une valeur positive incorrecte :
etudiant4.setMoyenne(25);
etudiant4.afficherDetails();
System.out.println("--------------------------------------");
// Tentative de changement de la moyenne avec une valeur negative incorrecte :
etudiant4.setMoyenne(-30);
etudiant4.afficherDetails();
System.out.println("--------------------------------------");
// Tentative de changement de la moyenne avec une valeur correcte :
etudiant4.setMoyenne(10);
etudiant4.afficherDetails();
System.out.println("--------------------------------------");
}
}
@@ -0,0 +1,40 @@
public class CompteBancaire {
private double solde;
private String titulaire;
CompteBancaire(){
this.solde = 0;
this.titulaire = "Inconnu";
}
CompteBancaire(double soldeInput, String titulaireInput){
this.solde = soldeInput;
this.titulaire = titulaireInput;
}
public void deposer(double montant){
this.setSolde(this.getSolde() + montant);
}
public void retirer(double montant){
this.setSolde(this.getSolde() - montant);
}
public double getSolde(){
return this.solde;
}
private void setSolde(double soldeInput){
this.solde = soldeInput;
}
public String getTitulaire(){
return this.titulaire;
}
public void setTitulaire(String titulaireInput){
this.titulaire = titulaireInput;
}
}
@@ -0,0 +1,57 @@
public class Etudiant {
private String nom;
private double moyenne = -1;
/* -1 instancié par defaut pour qu'elle
ne soit pas prise en compte en cas de mauvaise
donnée
*/
Etudiant() {
this.nom = "Inconnu";
this.moyenne = 0;
}
Etudiant(String nomInput, double moyenneInput) {
this.nom = nomInput;
if(moyenneInput < 0 || moyenneInput > 20) {
System.out.println("La moyenne doit être comprise entre 0 et 20.");
}
else{
this.moyenne = moyenneInput;
}
}
public void afficherDetails() {
System.out.println("Nom : " + this.nom);
if(this.moyenne >= 0 && this.moyenne <= 20) {
System.out.println("Moyenne : " + this.moyenne);
}
else {
System.out.println("Moyenne : Non définie.");
}
}
public String getNom() {
return this.nom;
}
public void setNom(String nomInput) {
this.nom = nomInput;
}
public double getMoyenne() {
return this.moyenne;
}
public void setMoyenne(double moyenneInput) {
if(moyenneInput < 0 || moyenneInput > 20) {
System.out.println("La moyenne doit être comprise entre 0 et 20.");
}
else{
this.moyenne = moyenneInput;
}
}
}
@@ -0,0 +1,32 @@
public class Personne {
private String nom;
private int age;
Personne(){
this.nom = "Inconnu";
this.age = 0;
}
Personne(String nomInput, int ageInput){
this.nom = nomInput;
this.age = ageInput;
}
public String getNom(){
return this.nom;
}
public void setNom(String nomInput){
this.nom = nomInput;
}
public int getAge(){
return this.age;
}
public void setAge(int ageInput){
this.age = ageInput;
}
}
+49
View File
@@ -0,0 +1,49 @@
public class Produit {
private String nom;
private double prix;
private int quantiteStock;
Produit(){
this.nom = "Inconnu";
this.prix = 0;
}
Produit(String nomInput, double prixInput){
this.nom = nomInput;
this.prix = prixInput;
}
public String getNom(){
return this.nom;
}
public void setNom(String nomInput){
this.nom = nomInput;
}
public double getPrix(){
return this.prix;
}
public void setPrix(double prixInput){
if(prixInput < 0){
System.out.println("Le prix ne peut pas être négatif."); }
else{
this.prix = prixInput;
}
}
public int getQuantiteStock(){
return this.quantiteStock;
}
public void setQuantiteStock(int quantiteStockInput){
if(quantiteStockInput < 0){
System.out.println("La quantité ne peut pas être négative.");
}
else{
this.quantiteStock = quantiteStockInput;
}
}
}
+18
View File
@@ -0,0 +1,18 @@
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
Binary file not shown.
+20
View File
@@ -0,0 +1,20 @@
import gestionEleves.*; // Importation du package gestionEleves et de toutes ses classes
public class App {
public static void main(String[] args) throws Exception {
Eleve eleve = new Eleve("Jean"); // Création d'un nouvel objet Eleve
eleve.ajouterNote(10); // Ajout d'une note à l'objet eleve
eleve.ajouterNote(15); // Ajout d'une note à l'objet eleve
eleve.ajouterNote(20); // Ajout d'une note à l'objet eleve
eleve.ajouterNote(5); // Ajout d'une note à l'objet eleve
eleve.ajouterNote(-3); // Note ajustée à 0
eleve.ajouterNote(-3); // Note ajustée à 0
eleve.ajouterNote(25); // Note ajustée à 20
eleve.ajouterNote(75); // Note ajustée à 20
System.out.println(eleve); // Affiche : Jean (11.25)
System.out.println(eleve.getListeNotes()); // Affiche : [10, 15, 20, 5, 0, 0, 20, 20]
System.out.println(eleve.getNom()); // Affiche : Jean
System.out.println(eleve.getMoyenne()); // Affiche : 11.25
}
}
@@ -0,0 +1,57 @@
package gestionEleves; // Déclaration du package gestionEleves
import java.util.ArrayList; // Importation de la classe ArrayList
public class Eleve { // Création de la classe Eleve
private String nom; // Déclaration de l'attribut nom
private ArrayList<Integer> listeNotes = new ArrayList<>(); // Déclaration de l'attribut listeNotes
// Initialisation de l'attribut listeNotes avec un nouvel objet ArrayList vide
private double moyenne; // Déclaration de l'attribut moyenne
public Eleve() { // Déclaration du constructeur Eleve par défaut
this.nom = "Inconnu";
}
public Eleve(String nomImput) { // Déclaration du constructeur Eleve
this.nom = nomImput; // Initialisation de l'attribut nom avec la valeur de nomImput
}
public String getNom() { // Déclaration de la méthode getNom
return this.nom; // getNom retourne la valeur de l'attribut nom
}
public double getMoyenne() { // Déclaration de la méthode getMoyenne
return this.moyenne; // getMoyenne retourne la valeur de l'attribut moyenne
}
public ArrayList<Integer> getListeNotes() { // Déclaration de la méthode getListeNotes
return listeNotes; // getListeNotes retourne la liste de toutes les notes contenu dans listeNotes
}
public void ajouterNote(int noteInput) { // Déclaration de la méthode ajouterNote
// Condition pour ajuster la noteInput si elle est inférieure à 0
if (noteInput < 0) { // Si noteInput est inférieur à 0
noteInput = 0; // noteInput prend la valeur 0
// Condition pour ajuster la noteInput si elle est supérieure à 20
} else if (noteInput > 20) { // Sinon si noteInput est supérieur à 20
noteInput = 20; // noteInput prend la valeur 20
}
this.listeNotes.add(noteInput); // Ajout de la noteInput à la liste listeNotes
if (this.listeNotes.isEmpty()) { // Si la liste listeNotes est vide
this.moyenne = 0; // La moyenne prend la valeur 0
} else { // Sinon
int somme = 0; // Initialisation de la variable somme à 0
for (int note : this.listeNotes) { // Pour chaque note dans la liste listeNotes
somme += note; // Ajout de la note à la somme
}
// Calcul de la moyenne et affectation à l'attribut moyenne
this.moyenne = (double) somme / this.listeNotes.size();
}
}
public String toString() { // Déclaration de la méthode toString
return this.nom + " (" + this.moyenne + ")"; // Retourne le nom et la moyenne de l'élève
}
}
+18
View File
@@ -0,0 +1,18 @@
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,44 @@
public class Adresse {
private int numero;
private String nomDeRue;
private int codePostal;
public Adresse(){
System.out.println("Création d'une adresse par defaut");
numero= 0;
nomDeRue = "Nom De Rue Par Defaut";
codePostal= 0;
}
public Adresse(String nomDeRueInput, int codePostalInput){
System.out.println("Création d'une adresse custom " + nomDeRueInput);
nomDeRue = nomDeRueInput;
codePostal= codePostalInput;
}
public int getNumero(){
return this.numero;
}
public void setNumero(int numeroInput){
this.numero = numeroInput;
}
public String getNomDeRue(){
return this.nomDeRue;
}
public void setNomDeRue(String nomDeRueInput){
this.nomDeRue = nomDeRueInput;
}
public int getcodePostal(){
return this.codePostal;
}
public void setCodePostal(int codePostalInput){
this.codePostal = codePostalInput;
}
}
+57
View File
@@ -0,0 +1,57 @@
import java.util.Scanner;
public class App {
public static void main(String[] args) throws Exception {
//Ville villeParDefaut = new Ville();
//Ville paris = new Ville("Paris", 123456, "France");
//Ville marseille = new Ville("Marseille", 654321, "France");
//System.out.println(villeParDefaut.getNomVille());
//System.out.println(paris.getNomVille());
//System.out.println(marseille.getNomVille());
Ville v1 = new Ville("Marseille", 123456, "France", 13000);
System.out.println("v1 = " + v1.getNomVille() + ", " + v1.getNbreHabitants() + ", " + v1.getNomPays());
Ville v2 = new Ville("Rio", 321654, "Brésil", 78945);
System.out.println("v2 = " + v2.getNomVille() + ", " + v2.getNbreHabitants() + ", " + v2.getNomPays());
System.out.println();
System.out.println("On inverse v1 et v2");
Ville temp = new Ville();
temp = v1;
v1 = v2;
v2 = temp;
System.out.println();
System.out.println("v1 = " + v1.getNomVille() + ", " + v1.getNbreHabitants() + ", " + v1.getNomPays());
System.out.println("v2 = " + v2.getNomVille() + ", " + v2.getNbreHabitants() + ", " + v2.getNomPays());
System.out.println();
System.out.println("On change les nom de Ville");
v1.setNomVille("Hong Kong");
v2.setNomVille("Dijbouti");
System.out.println();
System.out.println(v1.getNomVille() + ", " + v1.getNbreHabitants() + ", " + v1.getNomPays());
System.out.println(v2.getNomVille() + ", " + v2.getNbreHabitants() + ", " + v2.getNomPays());
System.out.println("\n ==== Passage à l'exo adresse ====\n");
Adresse adresse1 = new Adresse("rue toto", 77300);
Ville melun = new Ville("Melun", 15000, "France", 77300);
System.out.println("code postal = " + adresse1.getcodePostal());
melun.findVilleFromCodePostal(adresse1.getcodePostal());
adresse1.getNumero();
}
}
+68
View File
@@ -0,0 +1,68 @@
public class Ville {
private String nomVille;
private String nomPays;
private int nbreHabitants;
private int codePostal;
public Ville(){
System.out.println("Création d'une ville par defaut");
nomVille= "NomDeVilleParDefaut";
nomPays = "NomDePaysParDefaut";
nbreHabitants= 0;
codePostal= 00000;
}
public Ville(String pNom, int pNbre, String pPays, int pCodePostal){
System.out.println("Création d'une ville custom " + pNom);
nomVille= pNom;
nomPays = pPays;
nbreHabitants= pNbre;
codePostal = pCodePostal;
}
public void findVilleFromCodePostal(int adresseCodePostal) {
if(adresseCodePostal == this.codePostal){
System.out.println("La ville du code postal " + adresseCodePostal + " est " + this.nomVille);
}
else{
System.out.println("Le code postal " + adresseCodePostal + " ne correspond pas à la ville" + this.nomVille);
}
}
public int getNbreHabitants() {
return nbreHabitants;
}
public void setNbreHabitants(int nbreHabitants) {
this.nbreHabitants = nbreHabitants;
}
public String getNomPays() {
return nomPays;
}
public void setNomPays(String nomPays) {
this.nomPays = nomPays;
}
public String getNomVille() {
return nomVille;
}
public void setNomVille(String nomVille) {
this.nomVille = nomVille;
}
public int getCodePostal() {
return this.codePostal;
}
public void setCodePostal(int codePostal) {
this.codePostal = codePostal;
}
}