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
+34
View File
@@ -0,0 +1,34 @@
<?php
class Rectangle{
// Donné
Largeur
Longueur
// Méthode :
Périmètre()
Aire()
}
class Point{
// Donnée
x
y
}
class Véhicule {
// Donée
roue
place
// Méthode
Rouler()
Frainer()
// Les objet :
Voiture {
4 roues
4 place
}
Velo {
2 roues
1 place
}
}
+114
View File
@@ -0,0 +1,114 @@
# 503 14/10/2024
## Lunivers de la programmation
Un programme est simplement la description de la solution que je propose pour un problème. La solution peu sappeler Modélisation ou Algorithme. Elle sera présentée par un programme.
Autrement dit : un programme est une suite dinstruction pour résoudre un problème.
Expliquer étape par étape ce que le programme doit faire, cest a nous de réfléchir pas a la machine.
* Analyse -> déterminer le problème à résoudre
* Conception -> réalisation dun lalgorithme pour trouver une solution
* Développement -> traduction de lalgorithme en langage de programmation
Compilation Traduction du code source du programme vers le langage natif.
Les erreurs possible sont : erreur de syntaxe, de logique et de Solution en soit.
Diférents tests sont possible, unitaire, fonctionnel et client.
Traducteur de programme, entre le programme et la compilation.
Deux sorte de traducteurs interprètes et les compilateurs.
Les compilateur vont analyser la syntaxe et les interprète, va simplement interpréter ce que vous avez donné.
Une langage typé, cest un langage ou chaque variable utilisé à forcément un type. (C, C++, JAVA, etc)
Type de variable 2 classe primitif (entier, float, double char et bool) et complexe (tableau , tableau multidimensionnel, string).
## Les langages de programmation
Il y a deux familles de langage, les langages de bas niveau et de haut niveau.
Les langages bas niveau sont les plus proche des langages de la machine (C etc)
Les langages de haut niveau sont les plus proches des utilisateurs.
Lorsque quon a un langage, compilation - interprétation ou procédural - orienté objet.
Procédural : un programme qui utiles une procédure, une méthode. Il ny a pas de modalité. Il sexécute ligne par ligne. Tendance à générer du code spaghetti. Maintenance est difficile et travail en équipe plus compliqué.
Orientation Objet : Centrée autour des objets. Ils peuvent t être concret ou de labstrait.
Méthode -> renvoie un resultat
Procédure -> ne renvoie pas de résultat
## Concept Orienté Objet
Le concept OO veut une modélisation du monde réel
Objet est une représentation abstraite par une chose concrète.
Propriété et action.
Statique -> propriété (Un chat)
Dynamique -> Action (Le saut dun chat)
Les classes : Représentation abstrait dun objet qui est concert (Humain abstrarit, Bob concret)
Une classe est un moule qui va pouvoir instancier des objets.
```
class Rectangle{
// Donné
Largeur
Longueur
// Méthode :
Périmètre()
Aire()
}
class Point{
// Donnée
x
y
}
```
```
class Véhicule {
// Donnée
roue
place
// Méthode
Rouler()
Frainer()
// Les objet :
Voiture {
4 roues
4 place
}
Velo {
2 roues
1 place
}
}
```
## Les propriétés de base de lorientation objet
La notion de lhéritage -> Permet de spécialiser une class, qui possède les propriétés de son parent et ses propres spécialisations.
La notion de Polymorphisme -> A partir du moment où on possède plusieurs types. Exemple créer une nouvelle voiture, elle sera composée de la class voiture et de la class parent véhicule, donc elle sera polymorphique.
La notion de Transtypage -> Dans sa nature propre il est dun type, mais je force le compilateur pour que lobjet soit dun autre type que le type initial.
La notion de Polymorphie paramétrique -> le constructeur etc (On ne voit pas cette notion à ce cour-là).
+46
View File
@@ -0,0 +1,46 @@
# 503 06/11/2024
## Exemple Explicatifs
Variable -> Traitement -> Résultat/Sortis
Propriétés = Variable
Comportements = Méthode
### Explication de l'héritage :
```
Figure Géométrique
|------ Cercle
|---------- Sphère
|---------- Disque
|------ Rectangle
```
### Explication Polymorfisme :
Le principe d'avoir le plus d'instentiation par exemple Sphère dépend de Cercle et lui même dépend de Figure Géométrique.
### Rappelle de l'Agorthimie
### Type de Variable :
Primitf :
- int
- flaot
- double
- Boolean
- Char
Complexe :
- String
- Tableau(vecteur et matrice)
- Objet
### Définir une variable :
Besoin de définir le type, le nom et finir par un point virgule
Commence par une minuscule être courte de préférence et explicipte.
+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.
@@ -0,0 +1,74 @@
public class Principale {
public static void main(String[] args) throws Exception {
System.out.println("Hello World !");
Separateur.Default();
int trois = 3;
System.out.println(trois);
Separateur.Default();
String phrase = "Salut comment il va ?";
System.out.println(phrase);
Separateur.Default();
// Opérateurs possible : + - * / % etc..
int nb1, nb2, nb3;
nb1 = 9;
nb2 = 5;
nb3 = nb1*nb2;
System.out.println(nb3);
Separateur.Default();
System.out.println("Exercice 1 \n");
// Exo 1
// 1- initialisation des variables a et b :
// a=5;
// b=8;
int a = 5;
int b = 8;
// 2- Calculez les 4 opérations avec les nombres a et b et mettez les résultats dans les
// variables somme, difference, produit et quotient :
// somme=a+b;
// difference=a-b;
// produit=a*b;
// quotient=a/b;
int somme = a+b;
int difference = a-b;
int produit = a*b;
int quotient = a/b;
// 3- Affichez les résultats à l’écran.
System.out.println("La somme de " + a + " et " + b + " est : " + somme );
System.out.println("La difference de " + a + " et " + b + " est : " + difference );
System.out.println("Le produit de " + a + " et " + b + " est : " + produit );
System.out.println("Le quotient de " + a + " et " + b + " est : " + quotient );
Separateur.Default();
System.out.println("Exercice 2 \n");
// Exo 2
// Calculez le diamètre, la circonférence et laire dun cercle, en fonction de son rayon «r».
// - Diamètre = r*2;
// - circonférence = 2*pi*r;
// - aire= pi*r*r;
// avec pi=3.14159265358979.
final double pi = 3.14159265358979;
double r = 12;
System.out.println("Pour un rayon de : " + r + "cm");
double diametre = r*2;
System.out.println("Le diamètre sera de : " + diametre + "cm");
double circonference = 2*pi*r;
System.out.println("La circonference sera de : " + circonference + "cm");
double aire = pi*r*r;
System.out.println("Son aire sera de : " + aire + "cm");
Separateur.Default();
System.out.println("Exercice 3 \n");
// Exo 3
// - Déclarez une variable de type String
// - Initiallisez de la chaîne de caractères
// - Affichez la chaîne de caractères à l’écran.
String variableuuu;
variableuuu = "Salut, comment il va ?";
System.out.println(variableuuu);
}
}
@@ -0,0 +1,7 @@
public class Separateur {
public static void Default() {
System.out.println("----------");
}
}
@@ -0,0 +1,3 @@
public enum test {
}
Binary file not shown.
+18
View File
@@ -0,0 +1,18 @@
# UTC 503 du 26 11 2024
## Les instructions :
### Les conditions
Elle permettes d'alterer le déroulement du programme.
Plusieurs type :
***If*** -> Voir Exemple 1 dans `"/java/projet/src/App.java"`
***If Else*** -> Voir Exemple 2 dans `"/java/projet/src/App.java"`
***If Else, If*** -> Voir Exemple 3 dans `"/java/projet/src/App.java"`
***Switch Case*** -> Voir Exemple 4 dans `"/java/projet/src/App.java"`
+175
View File
@@ -0,0 +1,175 @@
# TD1-Condition
>Guillaume Sanchez
## Exercice 1
a) Modifier lalgorithme afin que si une seule des coordonnées est correcte, il saffiche « es un TDM
```
Variable :
entier a
entier b
entier x
entier y
debut
a=3
b=4
saisir x
saisir y
si (x=a et y=b) alors
debut de si
afficher ("coulé")
fin de si
sinon si (x=a ou y=b) alors
debur de si
affiche ("TDM")
fin de si
sinon
debut de si
affiche ("à l'eau")
fin de sinon
fin
fin
```
b) Ecrire le programme correspondant en java.
```
import java.util.Scanner;
public class App {
public static void main(String[] args) throws Exception {
// instantation des 4 variables :
int a = 3;
int b = 4;
// Utilisation de Scanner pour que l'utilisateur puisse renseigner les valeurs 'x' et 'y'
Scanner scannerX = new Scanner(System.in);
System.out.print("Ecrire le nombre x: ");
int x = scannerX.nextInt();
Scanner scannerY = new Scanner(System.in);
System.out.print("Ecrire le nombre y: ");
int y = scannerY.nextInt();
// Première condition : Si 'x' est strictement égale à 'a' ET que 'y' est strictement égale à 'b'
if(x == a && y == b){
// alors on "affiche coulé"
System.out.println("coulé");
}
// Deuxième condition : Sinon Si 'x' est strictemment égale à 'a' OU 'y' est strictement égale à 'b'
else if(x == a || y == b){
// alors on affiche "TDM"
System.out.println("TDM");
}
// Sinon on affiche "à l'eau"
else{
System.out.println("à l'eau");
}
}
}
```
## Exercice 2
a) Ecrire unprogramme en java qui prend en entrée trois réels x, y et z et affiche le maximum des trois.
```
public class App {
public static void main(String[] args) throws Exception {
// instantiation de x, y et z
int x = 3;
int y = 4;
int z = 1;
// Si 'x' strictement suppérieur à 'y' et 'x' strictement supérieur 'z'
if (x > y && x > z) {
// Alors on affiche x
System.out.println("x est plus grand");
}
// Sinon, si 'y' strictement suppérieur à 'x' et 'y' strictement supérieur 'z'
else if(y > x && y > z){
// Alors on affiche y
System.out.println("y est plus grand");
}
// Sinon, si 'z' strictement suppérieur à 'x' et 'z' strictement supérieur 'y'
else if(z > x && z > y){
// Alors on affiche z
System.out.println("z est plus grand");
}
// Un dernier sinon pour gérer les éventuelles erreurs
else{
System.out.println("Une erreur est survenu");
System.exit(1);
}
}
}
```
## Exercice 3
```
// instantiation de a, b et c
int a =1;
int b =2;
int c =1;
// On instantie delta égale b² - 4ac :
int delta = (b*b)-(4*a*c);
// Si Delta est strictement inferieur à 0
if (delta < 0) {
// Alors on affiche que "l'equation admet aucune solution dans R"
System.out.println("L'équation admet aucune solution dans R");
}
// Sinon, Si Delta est strictement égale à 0
else if(delta == 0){
// Alors on affiche que "l'équation admet 1 solution dans R"
System.out.println("L'équation admet 1 solution dans R");
}
// Sinon, Si Delta est strictement supperieur à 0
else if(delta > 0){
// Alors on affiche que "l'équation admet 2 solution dans R"
System.out.println("L'équation admet 2 solution dans R");
}
// Un dernier sinon pour gérer les éventuelles erreurs
else{
System.out.println("Une erreur est survenu");
System.exit(1);
}
```
Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

+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.
@@ -0,0 +1,94 @@
/*
Exercice 1
On donne lalgorithme suivant :
Variable : entier a
entier b
entier x
entier y
debut
a=3
b=4
saisir x
saisir y
si (x=a et y=b) alors
debut de si
afficher ("coulé")
fin de si
sinon
debut de si
affiche ("à l'eau")
fin de sinon
fin
fin
a) Modifier lalgorithme afin que si une seule des coordonnées est correcte, il saffiche « es un TDM
Variable :
entier a
entier b
entier x
entier y
debut
a=3
b=4
saisir x
saisir y
si (x=a et y=b) alors
debut de si
afficher ("coulé")
fin de si
sinon si (x=a || y=b) alors
debur de si
affiche ("TDM")
fin de si
sinon
debut de si
affiche ("à l'eau")
fin de sinon
fin
fin
b) Ecrire le programme correspondant en java.
*/
import java.util.Scanner;
public class App {
public static void main(String[] args) throws Exception {
// instantation des 4 variables :
int a = 3;
int b = 4;
Scanner scannerX = new Scanner(System.in);
System.out.print("Ecrire le nombre x: ");
int x = scannerX.nextInt();
Scanner scannerY = new Scanner(System.in);
System.out.print("Ecrire le nombre y: ");
int y = scannerY.nextInt();
// Première condition : Si 'x' est strictement égale à 'a' ET que 'y' est strictement égale à 'b'
if(x == a && y == b){
// alors on "affiche coulé"
System.out.println("coulé");
}
// Deuxième condition : Sinon Si 'x' est strictemment égale à 'a' OU 'y' est strictement égale à 'b'
else if(x == a || y == b){
// alors on affiche "TDM"
System.out.println("TDM");
}
// Sinon on affiche "à l'eau"
else{
System.out.println("à l'eau");
}
}
}
+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.
@@ -0,0 +1,30 @@
/*
Exercice 2 :
a) Ecrire un programme en java qui prend en entrée trois réels x, y et z et affiche le maximum des trois.
*/
public class App {
public static void main(String[] args) throws Exception {
// instantiation de x, y et z
int x = 3;
int y = 4;
int z = 1;
if (x > y && x > z) {
System.out.println("x est plus grand");
}
else if(y > x && y > z){
System.out.println("y est plus grand");
}
else if(z > x && z > y){
System.out.println("z est plus grand");
}
}
}
+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.
@@ -0,0 +1,48 @@
/*
Exercice 3 :
Ecrire un programme qui, étant donné une équation du second degré,
détermine le nombre de ses solutions réelles et leurs valeurs approchées éventuelles.
*/
public class App {
public static void main(String[] args) throws Exception {
int a =1;
int b =2;
int c =1;
int delta = (b*b)-(4*a*c);
if (delta < 0) {
System.out.println("L'équation admet aucune solution dans R");
}
else if(delta == 0){
System.out.println("L'équation admet 1 solution dans R ");
}
else if(delta > 0){
System.out.println("L'équation admet 2 solution dans R");
}
else{
System.out.println("Une erreur est survenu");
System.exit(1);
}
}
}
/*
D = b² - 4ac
D > 0
D = 0
D < 0
ax² + bx + c
b² - 4ac
*/
+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.
+91
View File
@@ -0,0 +1,91 @@
public class App {
public static void main(String[] args) throws Exception {
// // Exemple 1 : If noramle (cette exemple n'est pas logique car le calcul s'effectu avant la vérification)
// int a = 6; // Déclaration
// int b = 2; // |
// if(b == 0){ // Traitement
// System.out.println("Division par 0 impossible !"); // |
// } // |
// System.out.println("Résultat est = "+ c); // |
// Exemple 2 : If Else
// int a = 6;
// if(a >= 10){
// System.out.println("Vous avez plus de la moyenne : " + a);
// }
// else{
// System.out.println("Vous passez au rattrapage car vous avez moins de 10");
// }
// Exemple 3 : If Else If
// La Bonne Pratique :
// int note = 12;
// if(note > 18){
// System.out.println("A");
// }
// else if(note > 16 && note <= 18){
// System.out.println("B");
// }
// else if(note > 14 && note <= 16){
// System.out.println("C");
// }
// else if(note > 12 && note <= 14){
// System.out.println("D");
// }
// else{
// System.out.println("F");
// }
// Exemple 4 : Switch Case
// char sexe = 'F';
// switch (sexe) {
// case 'F':
// System.out.println("Il s'agit d'une femme");
// break;
// case 'H':
// System.out.println("Il s'agit d'un homme");
// break;
// default:
// System.out.println("Sexe indéterminé");
// break;
// }
// Exercice Switch :
// int taille = 34;
// switch (taille) {
// case 34:
// System.out.println("XS");
// break;
// case 36:
// System.out.println("S");
// break;
// case 38:
// System.out.println("SM");
// break;
// case 40:
// System.out.println("M");
// break;
// case 42:
// System.out.println("L");
// break;
// default:
// System.out.println("La taille n'existe pas");
// break;
// }
}
}
+103
View File
@@ -0,0 +1,103 @@
# UTC 503 du 16/12/2024
## Les instructions :
### Les boucles
Répéter un traintement plusieurs fois
Une boule n'est utile que si on peut la controler -> éviter les boucle infini
plusieurs façon de les réaliser :
***for*** -> Pour i = 0; tant que i est inférieur à 5; ajouter 1 à i :
```
for (int i=0;i>5;i=i+1){
Système.out.println("****");
}
```
Cette exemple affichera 5 fois "****"
***while*** -> Tant que,
On boucle "tant que" la condition est celle demandé :
```
// instancie "reponse" par le caractère "O"
char reponse = 'O';
// Tant que reponse est égale et de même type que le caractère "O" :
while (reponse == 'O') {
// affiche la phrase :
System.out.println("veuiller saisir un prenom : ");
// scanner pour récupérer la valeur par l'utilisateur :
String prenom = sc.nextLine();
// Affiche "Bonjour" suivi de la saisi de l'utilisateur :
System.out.println("Bonjour, " + prenom);
// Affiche la pharse pour asvoir si on recommance :
System.out.println("voulez-vous réessayer ? (O/N) ");
// On récupère le premier caractère de la valeur saisi et on instanci reponse avec.
reponse = sc.nextLine().charAt(0);
}
// Si reponse = O, alors on rejout, sinon, on affiche :
System.out.println("Au revoir");
```
***Do while*** -> Faire, Tant que
Les instructions vont au moins s'executer une fois
(Même code qu'en dessous, mais )
```
char reponse = 'O';
do{
System.out.println("veuiller saisir un prenom : ");
String prenom = sc.nextLine();
System.out.println("Bonjour, " + prenom);
System.out.println("voulez-vous réessayer ? (O/N) ");
reponse = sc.nextLine().charAt(0);
} while (reponse == 'O');
System.out.println("A+");
```
### Scanner :
Pour qu'un utilisateur puissent saisire des caractères, on utilise la class Scanner, avec sa méthode nextLine exemple :
```
Scanner sc = new Scanner(System.in);
System.out.println("veuiller saisir un mot : ");
String str = sc.nextLine();
System.out.println("Vous avez saisi : " + str);
```
"Scanner sc" c'est la class, new Scanner(System.in) c'est l'utilisation du constructeur
### /!\ Décomposition d'une fonction Système :
(Demmandé en examen)
```
System.out.println("...")
| | |------> Methode
| |-----------> Objet
|-----------------> Class
```
+158
View File
@@ -0,0 +1,158 @@
# TD2-Boucle
>Guillaume Sanchez
## Exercice 1
écrire un programme affichant la table de multiclication d'un nombre saisi par l'utilisateur
```
import java.util.Scanner;
public class App {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
System.out.print("Entrez le chiffre que vous voulez : ");
int num = sc.nextInt();
for(int i = 1; i <= 10; i++ ){
System.out.println(num + " x " + i + " = " + num*i);
}
}
}
```
Le résultat de ce code :
```
Entrez le chiffre que vous voulez : 3
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
3 x 10 = 30
```
## Exercice 2
Écrire un programme affichant les tables de multiplications des nombres de 1 à 10 dans un tableau à deux entrées.
```
public class App {
public static void main(String[] args) throws Exception {
for(int a=1; a<=10; a++){
System.out.print(a + " : ");
for(int b=1; b<=10;b++){
System.out.print(a*b + ", " );
}
System.out.println();
}
}
}
```
Le résultat de ce code :
```
1 : 1 2 3 4 5 6 7 8 9 10
2 : 2 4 6 8 10 12 14 16 18 20
3 : 3 6 9 12 15 18 21 24 27 30
4 : 4 8 12 16 20 24 28 32 36 40
5 : 5 10 15 20 25 30 35 40 45 50
6 : 6 12 18 24 30 36 42 48 54 60
7 : 7 14 21 28 35 42 49 56 63 70
8 : 8 16 24 32 40 48 56 64 72 80
9 : 9 18 27 36 45 54 63 72 81 90
10 : 10 20 30 40 50 60 70 80 90 100
```
## Exercice 3
Écrire un programme demandant à lutilisateur de saisir deux valeurs numériques b et n (vérifier que n est positif) et affichant la valeur bn.
```
public class App {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
System.out.print("Entrez le premier chiffre que vous voulez (b) : ");
int b = sc.nextInt();
int n;
do{
System.out.print("Entrez le second chiffre que vous voulez (n), il doit être positif : ");
n = sc.nextInt();
// Vérification à effectuer pour savoir si "n" est positif, sinon on repart au "do"
} while (n < 0);
System.out.println(b + " * " + n + " = " + b*n);
}
}
```
Le résultat de ce code dans le cas ou "n" est positif :
```
Entrez le premier chiffre que vous voulez (b) : 3
Entrez le second chiffre que vous voulez (n), il doit être positif : 4
3 * 4 = 12
```
Le résultat de ce code dans le cas ou "n" est négatif, le programme revient au choix de "n" :
```
Entrez le premier chiffre que vous voulez (b) : 6
Entrez le second chiffre que vous voulez (n), il doit être positif : -6
Entrez le second chiffre que vous voulez (n), il doit être positif : 6
6 * 6 = 36
```
## Exercice 4
Ecrire un programme demandant la saisi d'une valeur `n` et affichant le carré suivant (n = 5 dans cette exemple):
xxxxx
xxxxx
xxxxx
xxxxx
xxxxx
```
import java.util.Scanner;
public class App {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
System.out.print("Entrez le chiffre que vous voulez : ");
int num = sc.nextInt();
for(int x = 1; x <= num; x++){
for(int y = 1; y <= num ; y++){
System.out.print('x');
}
System.out.println();
}
}
}
```
Le résultat de ce code :
```
Entrez le chiffre que vous voulez : 3
xxx
xxx
xxx
```
Binary file not shown.
+136
View File
@@ -0,0 +1,136 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TD2-Boucles.md</title>
<link rel="stylesheet" href="https://stackedit.io/style.css" />
</head>
<body class="stackedit">
<div class="stackedit__html"><h1 id="td2-boucle">TD2-Boucle</h1>
<blockquote>
<p>Guillaume Sanchez</p>
</blockquote>
<h2 id="exercice-1">Exercice 1</h2>
<p>écrire un programme affichant la table de multiplication dun nombre saisi par lutilisateur</p>
<pre><code>import java.util.Scanner;
public class App {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
System.out.print("Entrez le chiffre que vous voulez : ");
int num = sc.nextInt();
for(int i = 1; i &lt;= 10; i++ ){
System.out.println(num + " x " + i + " = " + num*i);
}
}
}
</code></pre>
<p>Le résultat de ce code :</p>
<pre><code>Entrez le chiffre que vous voulez : 3
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
3 x 10 = 30
</code></pre>
<h2 id="exercice-2">Exercice 2</h2>
<p>Écrire un programme affichant les tables de multiplications des nombres de 1 à 10 dans un tableau à deux entrées.</p>
<pre><code>public class App {
public static void main(String[] args) throws Exception {
for(int a=1; a&lt;=10; a++){
System.out.print(a + " : ");
for(int b=1; b&lt;=10;b++){
System.out.print(a*b + ", " );
}
System.out.println();
}
}
}
</code></pre>
<p>Le résultat de ce code :</p>
<pre><code>1 : 1 2 3 4 5 6 7 8 9 10
2 : 2 4 6 8 10 12 14 16 18 20
3 : 3 6 9 12 15 18 21 24 27 30
4 : 4 8 12 16 20 24 28 32 36 40
5 : 5 10 15 20 25 30 35 40 45 50
6 : 6 12 18 24 30 36 42 48 54 60
7 : 7 14 21 28 35 42 49 56 63 70
8 : 8 16 24 32 40 48 56 64 72 80
9 : 9 18 27 36 45 54 63 72 81 90
10 : 10 20 30 40 50 60 70 80 90 100
</code></pre>
<h2 id="exercice-3">Exercice 3</h2>
<p>Écrire un programme demandant à lutilisateur de saisir deux valeurs numériques b et n (vérifier que n est positif) et affichant la valeur bn.</p>
<pre><code>import java.util.Scanner;
public class App {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
System.out.print("Entrez le premier chiffre que vous voulez (b) : ");
int b = sc.nextInt();
int n;
do{
System.out.print("Entrez le second chiffre que vous
voulez (n), il doit être positif : ");
n = sc.nextInt();
} while (n &lt; 0);
System.out.println(b + " * " + n + " = " + b*n);
}
}
</code></pre>
<p>Le résultat de ce code dans le cas ou “n” est positif :</p>
<pre><code>Entrez le premier chiffre que vous voulez (b) : 3
Entrez le second chiffre que vous voulez (n), il doit être positif : 4
3 * 4 = 12
</code></pre>
<p>Le résultat de ce code dans le cas ou “n” est négatif, le programme revient au choix de “n” :</p>
<pre><code>Entrez le premier chiffre que vous voulez (b) : 6
Entrez le second chiffre que vous voulez (n), il doit être positif : -6
Entrez le second chiffre que vous voulez (n), il doit être positif : 6
6 * 6 = 36
</code></pre>
<h2 id="exercice-4">Exercice 4</h2>
<p>Ecrire un programme demandant la saisi dune valeur <code>n</code> et affichant le carré suivant (n = 5 dans cette exemple):<br>
xxxxx<br>
xxxxx<br>
xxxxx<br>
xxxxx<br>
xxxxx</p>
<pre><code>import java.util.Scanner;
public class App {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
System.out.print("Entrez le chiffre que vous voulez : ");
int num = sc.nextInt();
for(int x = 1; x &lt;= num; x++){
for(int y = 1; y &lt;= num ; y++){
System.out.print('x');
}
System.out.println();
}
}
}
</code></pre>
<p>Le résultat de ce code :</p>
<pre><code>Entrez le chiffre que vous voulez : 3
xxx
xxx
xxx
</code></pre>
</div>
</body>
</html>
Binary file not shown.
+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.
+46
View File
@@ -0,0 +1,46 @@
import java.util.Scanner;
public class App {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
// for(int i = 0; i < 5; i = i + 1){
// System.out.println("**** " + i);
// }
// System.out.println("veuiller saisir un mot : ");
// String str = sc.nextLine();
// System.out.println("Vous avez saisi : " + str);
// int a = 1; int b = 15;
// while (a < b){
// System.out.println("coucou " + a + " " + b);
// a++;
// }
// char reponse = 'O';
// while (reponse == 'O') {
// System.out.println("veuiller saisir un prenom : ");
// String prenom = sc.nextLine();
// System.out.println("Bonjour, " + prenom);
// System.out.println("voulez-vous réessayer ? (O/N) ");
// reponse = sc.nextLine().charAt(0);
// }
// System.out.println("A+");
char reponse = 'O';
do{
System.out.println("veuiller saisir un prenom : ");
String prenom = sc.nextLine();
System.out.println("Bonjour, " + prenom);
System.out.println("voulez-vous réessayer ? (O/N) ");
reponse = sc.nextLine().charAt(0);
} while (reponse == 'O');
System.out.println("A+");
}
}
+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.
@@ -0,0 +1,17 @@
// Exercice 1 :
// écrire un programme affichant la table de multiclication d'un nombre saisi par l'utilisateur
import java.util.Scanner;
public class App {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
System.out.println("Entrez le chiffre que vous voulez :");
int num = sc.nextInt();
for(int i = 1; i <= 10; i++ ){
System.out.println(num + " x " + i + " = " + num*i);
}
}
}
+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.
@@ -0,0 +1,14 @@
// Écrire un programme affichant les tables de multiplications des nombres de 1 à 10 dans un tableau à deux entrées.
public class App {
public static void main(String[] args) throws Exception {
for(int a=1; a<=10; a++){
System.out.print(a + " : ");
for(int b=1; b<=10;b++){
System.out.print(a*b + " " );
}
System.out.println();
}
}
}
+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.
@@ -0,0 +1,21 @@
// Écrire un programme demandant à lutilisateur de saisir deux valeurs numériques b et n (vérifier que n est positif) et affichant la valeur bn.
import java.util.Scanner;
public class App {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
System.out.print("Entrez le premier chiffre que vous voulez (b) : ");
int b = sc.nextInt();
int n;
do{
System.out.print("Entrez le second chiffre que vous voulez (n), il doit être positif : ");
n = sc.nextInt();
// Vérification à effectuer pour savoir si "n" est positif, sinon on repart au "do"
} while (n < 0);
System.out.println(b + " * " + n + " = " + b*n);
}
}
+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.
@@ -0,0 +1,29 @@
// Ecrire un programme demandant la saisi d'une valeur `n` et afficahnt le carré suivant (n = 5 dans cette exemple):
// xxxxx
// xxxxx
// xxxxx
// xxxxx
// xxxxx
import java.util.Scanner;
public class App {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
System.out.print("Entrez le chiffre que vous voulez : ");
int num = sc.nextInt();
for(int x = 1; x <= num; x++){
for(int y = 1; y <= num ; y++){
System.out.print('x');
}
System.out.println();
}
}
}
+72
View File
@@ -0,0 +1,72 @@
# 503 06/01/2025
## Tableau
>Unidimentionnel -> C'est un tableau de type vecteur
>MultiDimentionnel -> C'est un tableau de type matrice
### Tableau Unidimentionnel
Un tableau est une variable un peu particlière, nous pouvons lui affecter plusieurs valeurs ordonnées séquentiellement.
Tab1 = {5,1,8,3,4,7,6,7,8,0}
Nous appelons ces valeurs au moyen d'un indice.
- Tab1 = {5,1,8,3,4,7,6,7,8,0}
- indice = {0,1,2,3,4,5,6,7,8,9}
Un indice permet de se positionnener dans un tableau, d'identifier une valeur, exemple ci dessus, [0] = 5
Déclaration d'un tableau en java :
<"Type du Tableau"> <"nom du tableau"> [] = {"contenu du tableau"}
Dans la pratique :
```
int tableauEntier[] = {0,1,2,3,4,5,6,7,8,9};
double tableauDouble
```
Déclaration d'un tableau à une dimention :
```
int tableauEntier[] = new int[6];
ou
int[] tableauEntier2[] = new int[6];
```
### Tableau multidimentionnel :
Un tableau multidimentionnel n'est rien d'autre qu'un tableau contenant au minimum deux tableaux.
Exemple soit un tableau multidimentionnel (2 lignes) appelé premierNombre
- La première contiendra les nombres paires
- La seconde contiendra les nombres impraires
PremierNombre = {{0,2,4,6,8},{1,3,5,7,9}};
>Conceille pratique utiliser la methode clone() pour éviter d'utiliser votre tableau originel.
## Fonction et Procédure
- Méthode : peut être une fonction ou une prcoédure
- Fonction : retourne une valeur
- Procédure : ne retourne pas de valeur
Une fonction permet de créer un traitement qui pourra être utiliser à chaque fois qu'on en a besoin.
`public static double`
Détails de cela :
- Tous d'abort public, C'est ce qui définit la portée de la méthodes (programmation objets)
- Ensuite il y a static
- Juste après nous avons double, Il s'agit du type de retour de la méthode. Pour faire simple, ici, notre méthode va renvoyer un double.
- Vient ensuite le nom de la méthode, C'est avec ce nom que nous l'appellerons
- Puis arrivent les arguments de la méthode. Ce sont en fait les paramètres ont la méthode à besoin.
etc...
+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.
+121
View File
@@ -0,0 +1,121 @@
public class App {
public static void main(String[] args) throws Exception {
// Exemple d'un tableau unidimentionnel
System.out.println("================== Cours ===================");
System.out.println("");
int tab[] = {1,2,3,4};
for(int i=0; i < tab.length; i++){
System.out.println("La valeur " + tab[i] + " a pour indice " + i);
}
System.out.println("La valeur du dernier élément du tableau est : " + tab[tab.length -1]);
System.out.println("");
System.out.println("===============================================");
System.out.println("");
// Exemple d'un tableau multidimentionnel
int premierNombres[][] = {{1,2,3,4},{5,6,7,8}};
// for(int i=0;i<2;i++){
// for(int j=0;j<4;j++){
// System.out.print(premierNombres[i][j]);
// }
// System.out.println("");
// }
int i = 0;
while(i < 2){
int j = 0;
while(j < 4){
System.out.print(premierNombres[i][j]);
j++;
}
System.out.println("");
i++;
}
// Exemple 1 :
System.out.println("");
System.out.println("=============== Exercice 1================");
System.out.println("");
int tabExemple1[] = {75,25};
System.out.println(tabExemple1[0] + " + " + tabExemple1[1] + " = " + tabExemple1[0]+tabExemple1[1]);
// Exemple 2 :
System.out.println("");
System.out.println("=============== Exercice 2================");
System.out.println("");
int tabExemple2[] = {5,5};
System.out.println(tabExemple2[0] + " * " + tabExemple2[1] + " = " + tabExemple2[0]*tabExemple2[1]);
// Exemple 3 :
System.out.println("");
System.out.println("=============== Exerice 3================");
System.out.println("");
int tabACopier[] = {1,2,3,4,5,6,7,8,9};
int tabExemple3[] = tabACopier.clone();
for(i=0; i < tabACopier.length; i++){
//tabExemple3[i] = tabACopier[i];
System.out.print(tabExemple3[i]);
}
// System.out.println("");
System.out.println("");
System.out.println("=============== Suite Cours, les Fonctions : ================");
System.out.println("");
// Les Méthode utiles :
System.out.println("Voici une valeur aléatoire : " + Math.random());
System.out.println("Voici le sinus de 120 : " + Math.sin(120));
System.out.println("Voici le cosinus de 120 : " + Math.cos(120));
System.out.println("Voici la tangente de 120 : " + Math.tan(120));
System.out.println("La valeur absolu de -120.25 : " + Math.abs(-125.25));
System.out.println("L'exposant de 2 ': " + Math.pow(2, 2));
System.out.println("");
System.out.println("=============== Créer sa méthode : ================");
System.out.println("");
// Exemple avec la méthode printLnTableau :
int tableau1[] = {1,2,3,4,5,6,7,8,9};
int tableau2[] = {9,8,7,6,5};
int tableau3[] = {4,3,2,1,0};
printLnTableau(tableau1);
printLnTableau(tableau2);
printLnTableau(tableau3);
String tabBis1[] = {"toto","tata","titi","tutu"};
printTableauString(tabBis1);
}
static void printLnTableau(int tab[]){
System.out.print("|");
for(int i=0; i<tab.length; i++){
System.out.print(tab[i] + "|");
}
System.out.println("");
}
static void printTableauString( String[] tabBis){
for(String str : tabBis){
System.out.println(str);
}
}
}
@@ -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.
@@ -0,0 +1,39 @@
public class App {
public static void main(String[] args) throws Exception {
String tableau[] = {"toto", "tata", "titi", "tutu"};
parcourirTableau(tableau);
System.out.println(toString2(tableau));
}
static void parcourirTableau(String tab[]){
System.out.println("Parcours du tableau :");
for(String str : tab){
System.out.println(str);
}
}
static void toString(String tab[]){
System.out.println("Affiche la tableau en chaine de caractère :");
for(String str : tab){
System.out.print(str);
}
System.out.println("");
}
static String toString2(String tab[]){
System.out.println("Méthode toString()");
String retour = "";
for(String str : tab){
retour += str + "\n";
}
return retour;
}
}
+10
View File
@@ -0,0 +1,10 @@
# UTC 503 28-01-25
Un constructeur, c'esu une méthode qui nous permet de fabriquer des objets à partir d'une classe.
Utilisation d'une class :
```
Ville ville = new Ville();
Class (Ville) objet (ville) operateur (new) consturcteur (Ville())
```
+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.
+17
View File
@@ -0,0 +1,17 @@
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());
}
}
+47
View File
@@ -0,0 +1,47 @@
public class Ville {
private String nomVille;
private String nomPays;
private int nbreHabitants;
public Ville(){
System.out.println("Création d'une ville");
nomVille= "toto";
nomPays = "tata";
nbreHabitants= 0;
}
public Ville(String pNom, int pNbre, String pPays){
System.out.println("Création d'une ville");
nomVille= pNom;
nomPays = pPays;
nbreHabitants= pNbre;
}
public int getNbreHabitants() {
return nbreHabitants;
}
public String getNomPays() {
return nomPays;
}
public String getNomVille() {
return nomVille;
}
public void setNbreHabitants(int nbreHabitants) {
this.nbreHabitants = nbreHabitants;
}
public void setNomPays(String nomPays) {
this.nomPays = nomPays;
}
public void setNomVille(String nomVille) {
this.nomVille = nomVille;
}
}
+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;
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+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).

Some files were not shown because too many files have changed in this diff Show More