initial commit
This commit is contained in:
@@ -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.
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,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
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user