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
+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;
}
}
}