├── .gitignore ├── README.md ├── cours ├── src │ └── main │ │ └── java │ │ └── solution_exo │ │ ├── examenFinal │ │ ├── final │ │ │ ├── .vscode │ │ │ │ └── settings.json │ │ │ ├── target │ │ │ │ └── classes │ │ │ │ │ ├── question1 │ │ │ │ │ ├── Etat.class │ │ │ │ │ ├── Main4.class │ │ │ │ │ ├── Tache.class │ │ │ │ │ ├── Tableau.class │ │ │ │ │ ├── TacheAvecDate.class │ │ │ │ │ └── otherVersions │ │ │ │ │ │ ├── Etat.class │ │ │ │ │ │ ├── Main.class │ │ │ │ │ │ ├── Main3.class │ │ │ │ │ │ ├── Tache.class │ │ │ │ │ │ ├── Tableau.class │ │ │ │ │ │ └── TacheAvecDate.class │ │ │ │ │ └── question2 │ │ │ │ │ ├── Main3.class │ │ │ │ │ ├── Dossier.class │ │ │ │ │ ├── Fichier.class │ │ │ │ │ ├── Document.class │ │ │ │ │ └── otherVersions │ │ │ │ │ ├── Main.class │ │ │ │ │ ├── Main2.class │ │ │ │ │ ├── Document.class │ │ │ │ │ ├── Dossier.class │ │ │ │ │ ├── Fichier.class │ │ │ │ │ └── Repertoire.class │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── question2 │ │ │ │ ├── otherVersions │ │ │ │ ├── Main2.java │ │ │ │ └── Main.java │ │ │ │ └── Main3.java │ │ ├── video │ │ │ ├── target │ │ │ │ └── classes │ │ │ │ │ ├── formatif1 │ │ │ │ │ ├── question1 │ │ │ │ │ │ ├── Main.class │ │ │ │ │ │ ├── Compte.class │ │ │ │ │ │ ├── Transaction.class │ │ │ │ │ │ ├── CompteEpargne.class │ │ │ │ │ │ └── TypeTransaction.class │ │ │ │ │ └── question2 │ │ │ │ │ │ ├── Main.class │ │ │ │ │ │ ├── Contact.class │ │ │ │ │ │ ├── Entreprise.class │ │ │ │ │ │ ├── Individu.class │ │ │ │ │ │ └── OutilGestion.class │ │ │ │ │ └── formatif2 │ │ │ │ │ ├── question1 │ │ │ │ │ ├── Main.class │ │ │ │ │ ├── Cuisine.class │ │ │ │ │ ├── Commande.class │ │ │ │ │ ├── EtatCommande.class │ │ │ │ │ └── CommandeAvecLimite.class │ │ │ │ │ └── question2 │ │ │ │ │ ├── Main.class │ │ │ │ │ ├── Employe.class │ │ │ │ │ ├── Entreprise.class │ │ │ │ │ └── MainDiff.class │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── formatif2 │ │ │ │ └── question2 │ │ │ │ ├── MainDiff.java │ │ │ │ └── Main.java │ │ └── formatif2 │ │ │ └── question2 │ │ │ ├── q2V1.java │ │ │ ├── rgv1.drawio │ │ │ └── q2V2.java │ │ ├── serie1 │ │ ├── Exo002.java │ │ ├── Exo026.java │ │ ├── Exo001.java │ │ ├── Exo046.java │ │ ├── Exo007.java │ │ ├── Exo030.java │ │ ├── Exo008.java │ │ ├── Exo028.java │ │ ├── Exo055.java │ │ ├── Exo051.java │ │ ├── Exo037.java │ │ ├── Exo036.java │ │ ├── Exo042.java │ │ ├── Exo004.java │ │ ├── Exo009.java │ │ ├── Exo053.java │ │ ├── Exo049.java │ │ ├── Exo005.java │ │ ├── Exo016.java │ │ ├── Exo017.java │ │ ├── Exo012.java │ │ ├── Exo018.java │ │ ├── Exo014.java │ │ ├── Exo011.java │ │ ├── Exo050.java │ │ ├── Exo027.java │ │ ├── Exo048.java │ │ ├── Exo033.java │ │ ├── Exo010.java │ │ ├── Exo015.java │ │ ├── Exo056V1.java │ │ ├── Exo025.java │ │ ├── Exo006.java │ │ ├── Exo020.java │ │ ├── Exo021.java │ │ ├── Exo013v2.java │ │ ├── Exo013.java │ │ ├── Exo019.java │ │ ├── Exo003.java │ │ ├── Exo013v3.java │ │ └── Exo022.java │ │ ├── serie3 │ │ ├── Exo1.png │ │ ├── Exo2.png │ │ ├── Exo3.png │ │ ├── Exo4.png │ │ ├── Cursor.java │ │ ├── Exo5.java │ │ ├── Exo0.java │ │ ├── Exo6.java │ │ └── Exo9.java │ │ ├── serie2 │ │ ├── exo031 │ │ │ ├── target │ │ │ │ └── classes │ │ │ │ │ ├── exo0 │ │ │ │ │ └── Main.class │ │ │ │ │ └── utils │ │ │ │ │ └── math │ │ │ │ │ └── Pythagore.class │ │ │ ├── src │ │ │ │ └── main │ │ │ │ │ └── java │ │ │ │ │ ├── utils │ │ │ │ │ └── math │ │ │ │ │ │ └── Pythagore.java │ │ │ │ │ └── exo0 │ │ │ │ │ └── Main.java │ │ │ └── pom.xml │ │ ├── exo029 │ │ │ ├── target │ │ │ │ └── classes │ │ │ │ │ └── cours │ │ │ │ │ ├── a │ │ │ │ │ ├── Main.class │ │ │ │ │ └── b │ │ │ │ │ │ ├── Main.class │ │ │ │ │ │ └── Voiture.class │ │ │ │ │ └── c │ │ │ │ │ ├── Main.class │ │ │ │ │ ├── d │ │ │ │ │ └── Main.class │ │ │ │ │ └── Vehicule.class │ │ │ ├── src │ │ │ │ └── main │ │ │ │ │ └── java │ │ │ │ │ └── cours │ │ │ │ │ ├── c │ │ │ │ │ ├── Main.java │ │ │ │ │ ├── d │ │ │ │ │ │ └── Main.java │ │ │ │ │ └── Vehicule.java │ │ │ │ │ └── a │ │ │ │ │ ├── Main.java │ │ │ │ │ └── b │ │ │ │ │ ├── Main.java │ │ │ │ │ └── Voiture.java │ │ │ └── pom.xml │ │ ├── tictactoe │ │ │ ├── target │ │ │ │ └── classes │ │ │ │ │ ├── chatgpt │ │ │ │ │ ├── Main.class │ │ │ │ │ ├── Vendeur.class │ │ │ │ │ ├── VendeurEnLigne.class │ │ │ │ │ └── VendeurMagasin.class │ │ │ │ │ ├── vendeur │ │ │ │ │ ├── Main.class │ │ │ │ │ ├── Maison.class │ │ │ │ │ ├── Produit.class │ │ │ │ │ ├── Vendeur.class │ │ │ │ │ ├── Nourriture.class │ │ │ │ │ └── TypeVente.class │ │ │ │ │ └── games │ │ │ │ │ └── tictactoe │ │ │ │ │ ├── Box.class │ │ │ │ │ └── TicTacToe.class │ │ │ └── pom.xml │ │ ├── Exo015.java │ │ ├── Sudoku │ │ │ ├── Coordonne.java │ │ │ ├── Problemes.java │ │ │ └── Case.java │ │ ├── Exo006.java │ │ ├── Exo018.java │ │ ├── Exo001.java │ │ ├── Exo005.java │ │ ├── Exo008.java │ │ ├── cours │ │ │ └── Main.java │ │ ├── Exo026.java │ │ ├── Exo002.java │ │ ├── Exo004.java │ │ ├── Exo030.java │ │ ├── Exo003.java │ │ ├── Exo019.java │ │ ├── Exo009.java │ │ ├── Exo016.java │ │ ├── Exo016V2.java │ │ ├── Exo021.java │ │ └── Exo028.java │ │ ├── examen1 │ │ ├── formatif │ │ │ ├── Test.java │ │ │ ├── correction.java │ │ │ ├── Alphabet.java │ │ │ ├── AlphabetV2.java │ │ │ ├── Trie.java │ │ │ ├── TrieV2.java │ │ │ ├── CompteBancaire.java │ │ │ ├── ToDoList.java │ │ │ └── ToDoListV2.java │ │ ├── Q1Examen1.java │ │ ├── Q1Examen1V2.java │ │ ├── Q3Examen1.java │ │ └── Q2Examen2.java │ │ ├── examen2 │ │ ├── formatif │ │ │ ├── question2 │ │ │ │ ├── Main.java │ │ │ │ └── Animal.java │ │ │ ├── question1 │ │ │ │ ├── Evaluation.java │ │ │ │ └── Etudiant.java │ │ │ └── théorie │ │ │ │ └── corrThE2.txt │ │ ├── question3 │ │ │ └── Main.java │ │ ├── question1 │ │ │ └── Personne.java │ │ └── question2 │ │ │ └── Menu.java │ │ ├── serie4 │ │ └── Golf.java │ │ └── examen3 │ │ ├── formatif │ │ └── Rg.java │ │ └── question2 │ │ └── Main2.java ├── .vscode │ └── settings.json └── pom.xml ├── 420-210-MV Programmation orientée objet-MF.docx └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | cours/src/test/* 2 | cours/target/* -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 420210 2 | Cours de programmation orientée objet 3 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.debug.settings.onBuildFailureProceed": true 3 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo002.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | //Pas de code, si ça fonctionne alors c'est bon! 3 | -------------------------------------------------------------------------------- /420-210-MV Programmation orientée objet-MF.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/420-210-MV Programmation orientée objet-MF.docx -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie3/Exo1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie3/Exo1.png -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie3/Exo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie3/Exo2.png -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie3/Exo3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie3/Exo3.png -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie3/Exo4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie3/Exo4.png -------------------------------------------------------------------------------- /cours/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.debug.settings.onBuildFailureProceed": true, 3 | "java.configuration.updateBuildConfiguration": "interactive" 4 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/exo031/target/classes/exo0/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/exo031/target/classes/exo0/Main.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/exo029/target/classes/cours/a/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/exo029/target/classes/cours/a/Main.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/exo029/target/classes/cours/a/b/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/exo029/target/classes/cours/a/b/Main.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/exo029/target/classes/cours/c/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/exo029/target/classes/cours/c/Main.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/exo029/target/classes/cours/c/d/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/exo029/target/classes/cours/c/d/Main.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/exo029/target/classes/cours/c/Vehicule.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/exo029/target/classes/cours/c/Vehicule.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/chatgpt/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/chatgpt/Main.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/vendeur/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/vendeur/Main.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/Etat.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/Etat.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/Main4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/Main4.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/Tache.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/Tache.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/Main3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/Main3.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/exo029/target/classes/cours/a/b/Voiture.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/exo029/target/classes/cours/a/b/Voiture.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/chatgpt/Vendeur.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/chatgpt/Vendeur.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/vendeur/Maison.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/vendeur/Maison.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/vendeur/Produit.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/vendeur/Produit.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/vendeur/Vendeur.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/vendeur/Vendeur.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/Tableau.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/Tableau.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/Dossier.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/Dossier.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/Fichier.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/Fichier.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/exo031/target/classes/utils/math/Pythagore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/exo031/target/classes/utils/math/Pythagore.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/vendeur/Nourriture.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/vendeur/Nourriture.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/vendeur/TypeVente.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/vendeur/TypeVente.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/Document.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/Document.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/games/tictactoe/Box.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/games/tictactoe/Box.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/chatgpt/VendeurEnLigne.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/chatgpt/VendeurEnLigne.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/chatgpt/VendeurMagasin.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/chatgpt/VendeurMagasin.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/TacheAvecDate.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/TacheAvecDate.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question1/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question1/Main.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question2/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question2/Main.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif2/question1/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif2/question1/Main.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif2/question2/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif2/question2/Main.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/games/tictactoe/TicTacToe.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/serie2/tictactoe/target/classes/games/tictactoe/TicTacToe.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question1/Compte.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question1/Compte.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question2/Contact.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question2/Contact.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif2/question1/Cuisine.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif2/question1/Cuisine.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif2/question2/Employe.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif2/question2/Employe.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/otherVersions/Etat.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/otherVersions/Etat.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/otherVersions/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/otherVersions/Main.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/otherVersions/Main3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/otherVersions/Main3.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/otherVersions/Tache.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/otherVersions/Tache.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/otherVersions/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/otherVersions/Main.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/otherVersions/Main2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/otherVersions/Main2.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question2/Entreprise.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question2/Entreprise.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question2/Individu.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question2/Individu.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif2/question1/Commande.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif2/question1/Commande.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif2/question2/Entreprise.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif2/question2/Entreprise.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif2/question2/MainDiff.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif2/question2/MainDiff.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/otherVersions/Tableau.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/otherVersions/Tableau.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/otherVersions/Document.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/otherVersions/Document.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/otherVersions/Dossier.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/otherVersions/Dossier.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/otherVersions/Fichier.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/otherVersions/Fichier.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question1/Transaction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question1/Transaction.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question2/OutilGestion.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question2/OutilGestion.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif2/question1/EtatCommande.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif2/question1/EtatCommande.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/otherVersions/Repertoire.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question2/otherVersions/Repertoire.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question1/CompteEpargne.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question1/CompteEpargne.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question1/TypeTransaction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif1/question1/TypeTransaction.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/otherVersions/TacheAvecDate.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/final/target/classes/question1/otherVersions/TacheAvecDate.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif2/question1/CommandeAvecLimite.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MFournier88/420210/HEAD/cours/src/main/java/solution_exo/examenFinal/video/target/classes/formatif2/question1/CommandeAvecLimite.class -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/exo031/src/main/java/utils/math/Pythagore.java: -------------------------------------------------------------------------------- 1 | package utils.math; 2 | 3 | public class Pythagore { 4 | public static double calculTHMPythagore(double a, double b){ 5 | return Math.abs(Math.sqrt(Math.pow(a,2) + Math.pow(b,2))); 6 | } 7 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo026.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | public class Exo026 { 3 | public static void main(String[] args) { 4 | // Affiche les deux phrases avec un seul System.out.println 5 | System.out.println("L'apostrophe peut briser le code.\nLes guillemets \"Sont dangereux\"."); 6 | } 7 | } 8 | 9 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen1/formatif/Test.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examen1.formatif; 2 | 3 | import java.util.Scanner; 4 | public class Test { 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | String choix = scanner.nextLine(); 8 | System.out.println(choix); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen1/formatif/correction.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examen1.formatif; 2 | 3 | public class correction { 4 | public static void main(String[] args) { 5 | int[] tab1 = {1 , 2 , 3}; 6 | int somme = 0; 7 | for(int i = 0 ; i < tab1.length ; i++ ){ 8 | somme += tab1[i]; 9 | } 10 | System.out.println(somme); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/exo031/src/main/java/exo0/Main.java: -------------------------------------------------------------------------------- 1 | package exo0; 2 | import utils.math.Pythagore; 3 | public class Main { 4 | 5 | //Calculer l'hypothénuse d'un triangle carré avec les cathètes 3 & 4 6 | 7 | public static void main(String[] args) { 8 | System.out.println("l'hypothénuse d'un triangle carré avec les cathètes 3 & 4 : " + Pythagore.calculTHMPythagore(3, 4)); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen1/formatif/Alphabet.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examen1.formatif; 2 | 3 | public class Alphabet { 4 | 5 | public static void main(String[] args){ 6 | int n = Integer.parseInt(args[0]); 7 | n %= 26; 8 | char lettre = 'a'; 9 | for(int i = 0 ; i < n ; i++){ 10 | System.out.print((char)(lettre + i)); 11 | } 12 | System.out.println(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen1/formatif/AlphabetV2.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examen1.formatif; 2 | 3 | public class AlphabetV2 { 4 | public static void main(String[] args) { 5 | int n = Integer.parseInt(args[0]); 6 | 7 | n %= 26; 8 | 9 | char lettre = 'a'; 10 | 11 | for(int i = 0 ; i < n ; i++){ 12 | System.out.print((char)(lettre + i)); 13 | } 14 | System.out.println(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo001.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | // Exo_1.1 3 | // Faites un programme qui prend prénom et nom de famille en argument et affiche bonjour <>. 4 | public class Exo001 { 5 | public static void main(String[] args){ 6 | if( args.length != 2){ 7 | System.err.println("Entrez le prénom et le nom en argument"); 8 | System.exit(0); 9 | } 10 | System.out.println("bonjour " + args[0] + " " + args[1]); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen2/formatif/question2/Main.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examen2.formatif.question2; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Animal ani = new Animal("a",2,"ss"); 6 | System.out.println(ani.nom); 7 | Chien chien = new Chien("Rex", 3, "Berger Allemand"); 8 | Chat chat = new Chat("Matou", 12, "Sphinx"); 9 | 10 | 11 | chien.sePresenter(); 12 | chien.parler(); 13 | 14 | chat.sePresenter(); 15 | chat.parler(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen1/Q1Examen1.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examen1; 2 | //2 3 | public class Q1Examen1 { 4 | public static void main(String[] args) { 5 | //4 6 | int n = Integer.parseInt(args[0]); 7 | //4 8 | int[] tab = new int[n]; 9 | 10 | //Affichage /5 11 | //Assignation /5 12 | System.out.print("["); 13 | for(int i = 0 ; i < tab.length - 1; i++){ 14 | tab[i] = (int)(Math.random() * 101); 15 | System.out.print(tab[i] + ","); 16 | } 17 | System.out.println(tab[tab.length - 1] + "]"); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo046.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | public class Exo046 { 3 | 4 | public static void main(String[] args) { 5 | // Créer une variable de type double 6 | double valeurDouble = 9.78; 7 | 8 | // Convertir la valeur en int en utilisant un cast explicite 9 | int valeurInt = (int) valeurDouble; 10 | 11 | // Afficher les deux valeurs avant et après la conversion 12 | System.out.println("Valeur initiale (double) : " + valeurDouble); 13 | System.out.println("Valeur convertie (int) : " + valeurInt); 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen1/Q1Examen1V2.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examen1; 2 | 3 | //2 4 | public class Q1Examen1V2 { 5 | public static void main(String[] args) { 6 | //4 7 | int n = Integer.parseInt(args[0]); 8 | //4 9 | int[] tab = new int[n]; 10 | 11 | //Assignation /4 12 | //Calcul somme /3 13 | int somme = 0; 14 | for(int i = 0 ; i < tab.length - 1; i++){ 15 | tab[i] = (int)(Math.random() * (72 - 51 + 1) + 51); 16 | somme += tab[i]; 17 | } 18 | //Affichage /3 19 | System.out.println(somme); 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /cours/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | solution_exo 8 | cours 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 17 13 | 17 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/exo029/src/main/java/cours/c/Main.java: -------------------------------------------------------------------------------- 1 | package cours.c; 2 | 3 | import cours.a.b.Voiture; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | Vehicule vehicule = new Vehicule("Toyota", 2022); 8 | Voiture voiture = new Voiture("Toyota", 2022, 4); 9 | 10 | vehicule.afficherInfo(); 11 | vehicule.salutation(); 12 | vehicule.afficherPrix(); 13 | 14 | voiture.afficherInfo(); 15 | voiture.afficherInfoVoiture(); 16 | voiture.salutation(); 17 | voiture.afficherPrixVoiture(); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo007.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | // - Créez un tableau d'entiers de taille 5. Remplissez le de 5 nombres aléatoires entre 0 et 100. (Voir [Math.random](1_basics/#mathrandom) dans les notes de cours) 3 | // - Affichez chaque valeur du tableau. 4 | 5 | public class Exo007 { 6 | public static void main(String[] args) { 7 | int[] tableau = new int[5]; 8 | 9 | for(int i = 0; i < tableau.length; i++){ 10 | tableau[i] = (int)(Math.random() * 101); 11 | } 12 | 13 | for (int i : tableau) { 14 | System.out.println(i); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/exo029/src/main/java/cours/a/Main.java: -------------------------------------------------------------------------------- 1 | package cours.a; 2 | 3 | import cours.a.b.Voiture; 4 | import cours.c.Vehicule; 5 | 6 | public class Main { 7 | public static void main(String[] args) { 8 | Vehicule vehicule = new Vehicule("Toyota", 2022); 9 | Voiture voiture = new Voiture("Toyota", 2022, 4); 10 | 11 | vehicule.afficherInfo(); 12 | vehicule.salutation(); 13 | vehicule.afficherPrix(); 14 | 15 | voiture.afficherInfo(); 16 | voiture.afficherInfoVoiture(); 17 | voiture.salutation(); 18 | voiture.afficherPrix(); 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | final 8 | final 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 17 13 | 17 14 | 15 | 16 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/exo029/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | serie2.exo026 8 | poo 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 17 13 | 17 14 | 15 | 16 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/exo031/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | utils.math 8 | exo031 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 17 13 | 17 14 | 15 | 16 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/tictactoe/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | games 8 | exo035 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 17 13 | 17 14 | 15 | 16 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | formatif1.question1 8 | video 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 17 13 | 17 14 | 15 | 16 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/exo029/src/main/java/cours/a/b/Main.java: -------------------------------------------------------------------------------- 1 | package cours.a.b; 2 | import cours.a.b.Voiture; 3 | import cours.c.Vehicule; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | Vehicule vehicule = new Vehicule("Toyota", 2022); 8 | Voiture voiture = new Voiture("Toyota", 2022, 4); 9 | 10 | vehicule.afficherInfo(); 11 | vehicule.salutation(); 12 | vehicule.afficherPrix(); 13 | 14 | voiture.afficherInfo(); 15 | voiture.afficherInfoVoiture(); 16 | voiture.salutation(); 17 | voiture.afficherPrixVoiture(); 18 | 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/exo029/src/main/java/cours/c/d/Main.java: -------------------------------------------------------------------------------- 1 | package cours.c.d; 2 | import cours.c.Vehicule; 3 | import cours.a.b.Voiture; 4 | public class Main { 5 | public static void main(String[] args) { 6 | Vehicule vehicule = new Vehicule("Toyota", 2022); 7 | Voiture voiture = new Voiture("Toyota", 2022, 4); 8 | vehicule.afficherInfo();//protected 9 | vehicule.salutation(); //public 10 | vehicule.afficherPrix();//private 11 | 12 | 13 | voiture.afficherInfo(); 14 | voiture.afficherInfoVoiture(); 15 | voiture.salutation(); 16 | voiture.afficherPrix(); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo030.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | public class Exo030 { 3 | 4 | // Méthode pour supprimer tous les espaces d'une chaîne 5 | public static String supprimerEspaces(String chaine) { 6 | // Utilisation de la méthode replaceAll pour supprimer tous les espaces 7 | return chaine.replaceAll(" ", ""); 8 | } 9 | 10 | public static void main(String[] args) { 11 | String chaine = "Hello World"; 12 | 13 | // Appel de la méthode pour supprimer les espaces 14 | String chaineSansEspaces = supprimerEspaces(chaine); 15 | System.out.println("La chaîne sans espaces est : " + chaineSansEspaces); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Exo015.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie2; 2 | import java.util.InputMismatchException; 3 | import java.util.Scanner; 4 | 5 | public class Exo015 { 6 | public static void main(String[] args) { 7 | try{ 8 | System.out.println("Prénom :" + args[0] + " Nom :" + args[1]); 9 | }catch(ArrayIndexOutOfBoundsException e){ 10 | System.out.print("Vous deviez mettre votre prénom et nom en argument, mais vous pouvez encore le faire ici : "); 11 | Scanner scan = new Scanner(System.in); 12 | String prenom = scan.next(); 13 | String nom = scan.next(); 14 | System.out.println("Prénom :" + prenom + " Nom :" + nom); 15 | 16 | 17 | 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo008.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | 3 | // Afficher le tableau généré à la question précédente sous un format plus esthétique 4 | 5 | // **Exemple de sortie attendue** : 6 | // ``` 7 | // [45,30,56,77,34] 8 | // ``` 9 | public class Exo008 { 10 | public static void main(String[] args) { 11 | int[] tableau = new int[5]; 12 | 13 | for(int i = 0; i < tableau.length; i++){ 14 | tableau[i] = (int)(Math.random() * 101); 15 | } 16 | 17 | System.out.print("["); 18 | for(int i = 0; i < tableau.length-1; i++){ 19 | System.out.print(tableau[i] + ","); 20 | } 21 | System.out.print(tableau[tableau.length - 1]); 22 | 23 | System.out.println("]"); 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo028.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | public class Exo028 { 3 | 4 | // Méthode pour inverser une chaîne de caractères 5 | public static String inverserChaine(String chaine) { 6 | String inverse = ""; 7 | 8 | // Boucle qui parcourt la chaîne de la fin vers le début 9 | for (int i = chaine.length() - 1; i >= 0; i--) { 10 | inverse += chaine.charAt(i); // Ajoute chaque caractère au début de la chaîne inversée 11 | } 12 | 13 | return inverse; 14 | } 15 | 16 | public static void main(String[] args) { 17 | String chaine = "Java"; 18 | String resultat = inverserChaine(chaine); 19 | System.out.println(chaine + " inversée donne : " + resultat); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Sudoku/Coordonne.java: -------------------------------------------------------------------------------- 1 | package Sudoku; 2 | /* 3 | * Crée une classe Coordonne avec deux attributs de type int : x et y. 4 | * Le constructeur prend en paramètre les valeurs de x et y, et les assigne aux attributs correspondants. 5 | */ 6 | 7 | 8 | public class Coordonne{ 9 | 10 | int x; 11 | int y; 12 | public Coordonne(int x, int y){ 13 | this.x = x; 14 | this.y = y; 15 | } 16 | 17 | public static void main(String[] args) { 18 | 19 | Coordonne test = new Coordonne(3,7); 20 | 21 | if(test.y == 7 && test.x == 3){ 22 | System.out.println("Réussi, passe à l'exo suivant"); 23 | } 24 | else{ 25 | System.out.println("Meilleure chance la prochaine fois"); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo055.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | import java.util.Scanner; 3 | 4 | public class Exo055 { 5 | 6 | public static void main(String[] args) { 7 | // Créer un objet Scanner pour saisir une année 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | // Demander à l'utilisateur d'entrer une année 11 | System.out.print("Entrez une année : "); 12 | int annee = scanner.nextInt(); 13 | 14 | // Vérification de l'année bissextile 15 | if ((annee % 4 == 0 && annee % 100 != 0) || (annee % 400 == 0)) { 16 | System.out.println("Année bissextile"); 17 | } else { 18 | System.out.println("Année non bissextile"); 19 | } 20 | 21 | // Fermer le scanner 22 | scanner.close(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo051.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | import java.util.ArrayList; 3 | import java.util.Collections; 4 | 5 | public class Exo051 { 6 | 7 | public static void main(String[] args) { 8 | // Créer un ArrayList d'entiers avec des valeurs non triées 9 | ArrayList nombres = new ArrayList<>(); 10 | nombres.add(50); 11 | nombres.add(30); 12 | nombres.add(20); 13 | nombres.add(40); 14 | nombres.add(10); 15 | 16 | // Afficher l'ArrayList avant le tri 17 | System.out.println("ArrayList avant le tri : " + nombres); 18 | 19 | // Trier l'ArrayList dans l'ordre croissant 20 | Collections.sort(nombres); 21 | 22 | // Afficher l'ArrayList après le tri 23 | System.out.println("ArrayList après le tri : " + nombres); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo037.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | public class Exo037 { 3 | 4 | // Méthode pour comparer deux chaînes sans tenir compte de la casse 5 | public static void comparerChaines(String chaine1, String chaine2) { 6 | // Utilisation de la méthode equalsIgnoreCase pour comparer les chaînes 7 | if (chaine1.equalsIgnoreCase(chaine2)) { 8 | System.out.println("Les chaînes sont égales (en ignorant la casse)."); 9 | } else { 10 | System.out.println("Les chaînes ne sont pas égales."); 11 | } 12 | } 13 | 14 | public static void main(String[] args) { 15 | // Chaînes de caractères à comparer 16 | String chaine1 = "Hello"; 17 | String chaine2 = "hello"; 18 | 19 | // Appeler la méthode pour comparer les chaînes 20 | comparerChaines(chaine1, chaine2); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo036.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | public class Exo036 { 3 | 4 | // Méthode pour extraire une sous-chaîne d'une chaîne donnée 5 | public static String extraireSousChaine(String chaine, int debut, int fin) { 6 | // Utilisation de la méthode substring pour extraire la sous-chaîne 7 | return chaine.substring(debut, fin); 8 | } 9 | 10 | public static void main(String[] args) { 11 | // Chaîne donnée 12 | String chaine = "Hello World"; 13 | 14 | // Indices de début et de fin 15 | int debut = 0; // Indice de début (inclus) 16 | int fin = 5; // Indice de fin (exclu) 17 | 18 | // Appeler la méthode pour extraire la sous-chaîne 19 | String sousChaine = extraireSousChaine(chaine, debut, fin); 20 | 21 | // Afficher la sous-chaîne extraite 22 | System.out.println("La sous-chaîne extraite est : " + sousChaine); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo042.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | public class Exo042 { 3 | 4 | // Méthode pour calculer la somme des valeurs ASCII des caractères dans un tableau 5 | public static int sommeASCII(char[] tableau) { 6 | int somme = 0; 7 | 8 | // Parcours du tableau pour additionner les valeurs ASCII de chaque caractère 9 | for (char c : tableau) { 10 | somme += (int) c; // Convertir chaque caractère en valeur ASCII et l'ajouter à la somme 11 | } 12 | 13 | return somme; 14 | } 15 | 16 | public static void main(String[] args) { 17 | // Déclaration du tableau de caractères 18 | char[] tableau = {'A', 'B', 'C', 'D'}; 19 | 20 | // Calcul de la somme des valeurs ASCII 21 | int resultat = sommeASCII(tableau); 22 | 23 | // Affichage du résultat 24 | System.out.println("La somme des valeurs ASCII est : " + resultat); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo004.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | 3 | public class Exo004 { 4 | public static void main(String args[]){ 5 | //-------------------------------------------------------------------- 6 | // Afficher le résulat de ces opérations sans l'écrire explicitement 7 | //-------------------------------------------------------------------- 8 | 9 | // Additionne 50 et 34 10 | System.out.println(50 + 34); 11 | 12 | // Soustrait 50 à 34 13 | System.out.println(50 - 34); 14 | 15 | // Mutiplie 4 par 80 16 | System.out.println( 4 * 80); 17 | 18 | // Divise 80 par 4 19 | System.out.println( 80 / 4); 20 | 21 | // 50 modulo 3 22 | 23 | System.out.println( 50 % 3 ); 24 | 25 | int i = 9; 26 | // Ajoute 1 à la variable i 27 | System.out.println(i = i + 1); 28 | 29 | 30 | // Retire 2 à la variable i 31 | System.out.println( i = i - 2); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen2/formatif/question1/Evaluation.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examen2.formatif.question1; 2 | 3 | class Evaluation{ 4 | private String nom; 5 | private float ponderation; 6 | private byte noteSur100 = 0; 7 | 8 | public Evaluation(String nom,float ponderation){ 9 | this.nom = nom; 10 | this.ponderation = ponderation; 11 | } 12 | public byte notePonderee(){ 13 | return (byte) (this.ponderation * this.noteSur100); 14 | } 15 | public String getNom() { 16 | return nom; 17 | } 18 | public void setNom(String nom) { 19 | this.nom = nom; 20 | } 21 | public float getPonderation() { 22 | return ponderation; 23 | } 24 | public void setPonderation(float ponderation) { 25 | this.ponderation = ponderation; 26 | } 27 | public byte getNoteSur100() { 28 | return noteSur100; 29 | } 30 | public void setNoteSur100(byte noteSur100) { 31 | this.noteSur100 = noteSur100; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo009.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | 3 | // Ajouter la somme des élément du tableau après l'affichage de celui-ci à l'exo 8. 4 | 5 | // **Exemple de sortie attendue** : 6 | // ``` 7 | // [45,30,56,77,34] 8 | // La somme des éléments du tableau : 242 9 | // ``` 10 | 11 | public class Exo009 { 12 | public static void main(String[] args) { 13 | int[] tableau = new int[5]; 14 | 15 | for(int i = 0; i < tableau.length; i++){ 16 | tableau[i] = (int)(Math.random() * 101); 17 | } 18 | 19 | int somme = 0; 20 | 21 | System.out.print("["); 22 | for(int i = 0; i < tableau.length-1; i++){ 23 | System.out.print(tableau[i] + ","); 24 | somme += tableau[i]; 25 | } 26 | System.out.print(tableau[tableau.length-1]); 27 | 28 | somme += tableau[tableau.length-1]; 29 | 30 | System.out.println("]"); 31 | System.out.println("La somme des éléments du tableau : " + somme); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo053.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | import java.util.ArrayList; 3 | import java.text.DecimalFormat; 4 | 5 | public class Exo053 { 6 | 7 | public static void main(String[] args) { 8 | // Créer un ArrayList d'entiers avec les valeurs des notes 9 | ArrayList notes = new ArrayList<>(); 10 | notes.add(80); 11 | notes.add(90); 12 | notes.add(70); 13 | notes.add(85); 14 | notes.add(100); 15 | 16 | // Calculer la somme des notes 17 | int somme = 0; 18 | for (int note : notes) { 19 | somme += note; 20 | } 21 | 22 | // Calculer la moyenne 23 | double moyenne = (double) somme / notes.size(); 24 | 25 | // Utiliser DecimalFormat pour afficher la moyenne avec deux décimales 26 | DecimalFormat df = new DecimalFormat("#.00"); 27 | 28 | // Afficher la moyenne 29 | System.out.println("La moyenne des notes est : " + df.format(moyenne)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Sudoku/Problemes.java: -------------------------------------------------------------------------------- 1 | package Sudoku; 2 | 3 | public class Problemes { 4 | public static int[][] probleme1(){ 5 | int[][] sudoku = { 6 | {8,0,0, 0,1,0, 0,0,0}, 7 | {4,0,0, 7,0,2, 9,0,0}, 8 | {0,9,2, 3,0,0, 0,0,0}, 9 | 10 | {0,0,0, 0,4,0, 8,0,0}, 11 | {0,4,1, 8,0,0, 7,9,0}, 12 | {0,0,8, 0,0,0, 0,6,3}, 13 | 14 | {2,3,0, 0,7,0, 0,0,0}, 15 | {0,0,0, 0,0,0, 0,7,5}, 16 | {0,0,0, 1,9,0, 0,4,0}, 17 | }; 18 | return sudoku; 19 | } 20 | public static int[][] probleme2(){ 21 | int[][] sudoku = { 22 | {0,6,0, 7,0,0, 0,0,0}, 23 | {0,0,0, 4,9,0, 0,0,0}, 24 | {9,0,3, 0,1,0, 0,0,6}, 25 | 26 | {0,0,8, 0,5,7, 4,0,1}, 27 | {3,0,0, 8,0,1, 7,6,0}, 28 | {0,0,0, 0,3,0, 0,0,0}, 29 | 30 | {0,0,0, 0,0,0, 0,4,0}, 31 | {0,0,0, 0,0,0, 5,0,0}, 32 | {0,0,0, 0,7,2, 1,8,0}, 33 | }; 34 | return sudoku; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 MFournier88 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in PreExam1 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo049.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | public class Exo049 { 6 | 7 | public static void main(String[] args) { 8 | // Créer un ArrayList de fruits 9 | ArrayList fruits = new ArrayList<>(); 10 | fruits.add("apple"); 11 | fruits.add("banana"); 12 | fruits.add("cherry"); 13 | fruits.add("date"); 14 | 15 | // Demander à l'utilisateur de saisir un fruit 16 | Scanner scanner = new Scanner(System.in); 17 | System.out.print("Entrez un fruit : "); 18 | String fruitSaisi = scanner.nextLine(); 19 | 20 | // Vérifier si le fruit saisi est dans l'ArrayList 21 | if (fruits.contains(fruitSaisi)) { 22 | System.out.println("Le fruit '" + fruitSaisi + "' a été trouvé dans l'ArrayList."); 23 | } else { 24 | System.out.println("Le fruit '" + fruitSaisi + "' n'a pas été trouvé dans l'ArrayList."); 25 | } 26 | 27 | // Fermer le scanner 28 | scanner.close(); 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen1/formatif/Trie.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examen1.formatif; 2 | 3 | public class Trie { 4 | public static void main(String[] args) { 5 | int[] tab = new int[10]; 6 | for( int i = 0; i < tab.length ; i++){ 7 | tab[i] = (int)(Math.random() * 101); 8 | } 9 | 10 | System.out.print("["); 11 | afficheTableau(tab); 12 | int indiceMin; 13 | int mem; 14 | for( int i = 0; i < tab.length ; i++){ 15 | indiceMin = i; 16 | for(int j = i + 1; j < tab.length; j++){ 17 | if(tab[j] < tab[indiceMin]){ 18 | indiceMin = j; 19 | } 20 | } 21 | mem = tab[indiceMin]; 22 | tab[indiceMin] = tab[i]; 23 | tab[i] = mem; 24 | 25 | } 26 | afficheTableau(tab); 27 | } 28 | public static void afficheTableau(int[] tab){ 29 | for( int i = 0; i < tab.length - 1 ; i++){ 30 | System.out.print(tab[i] + ", "); 31 | } 32 | System.out.println( tab[tab.length - 1] + "]"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo005.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | 3 | public class Exo005 { 4 | public static void main(String args[]){ 5 | int demo = 0; 6 | //-------------------------------------------------------------------- 7 | // Afficher le résulat de ces opérations sans l'écrire explicitement 8 | //-------------------------------------------------------------------- 9 | 10 | // Assigne 8 à demo 11 | demo = 8; 12 | System.out.println(demo); 13 | 14 | 15 | // Augmente la valeur de demo de 100 16 | demo += 100; 17 | System.out.println(demo); 18 | 19 | 20 | // Reduit la valeur de demo de 46 21 | demo -= 46; 22 | System.out.println(demo); 23 | 24 | 25 | // Multiplie la valeur actuel de demo par 5 26 | demo *= 5; 27 | System.out.println(demo); 28 | 29 | 30 | // Divise la valeur actuel de demo par 2 31 | demo /= 2; 32 | System.out.println(demo); 33 | 34 | 35 | // Assigne à demo le modulo 4 de sa valeur actuelle 36 | demo %= 4; 37 | System.out.println(demo); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo016.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | // # Exo_16 3 | 4 | // Niveau : 3 ⭐ 5 | 6 | // **Exercice** : 7 | 8 | // Écrivez un programme qui initialise 2 tableaux d’entiers. Il affiche les 2 tableaux. Il affiche ensuite identique si les 2 tableaux ont le même nombre d’éléments et que tous 9 | // les éléments au même index sont égaux, sinon il affiche différent. 10 | 11 | // ``` 12 | // [5,1,2,2,1,4,5,6,6,7] 13 | // [5,1,2,2,1,4,5,6,6,7] 14 | // Identique 15 | // ``` 16 | // ``` 17 | // [5,1,2,2,1,4,5,6,6,7] 18 | // [5,1,2,2,0,4,5,6,6,7] 19 | // Différent 20 | // ``` 21 | public class Exo016 { 22 | public static void main(String[] args) { 23 | int[] tab1 = {5,1,2,2,1,4,5,6,6,7}; 24 | int[] tab2 = {5,1,2,2,0,4,5,6,6,7}; 25 | boolean isEqual = true; 26 | for(int i = 0 ; i < tab1.length; i++){ 27 | if(tab1[i] != tab2[i]){ 28 | isEqual = false; 29 | break; 30 | } 31 | } 32 | if (isEqual) { 33 | System.out.println("Identique"); 34 | }else{ 35 | System.out.println("Différent"); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo017.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | // # Exo_17 3 | 4 | // Niveau : 3 ⭐ 5 | 6 | // **Exercice** : 7 | 8 | // Compter combien de voyelles (`a, e, i, o, u, y`) il y a dans un tableau de caractères. 9 | 10 | // - Créez un tableau de caractères : `['a', 'b', 'e', 'f', 'i', 'o', 'u', 'p']`. 11 | // - Utilisez une boucle pour compter combien de voyelles il y a dans le tableau et affichez le résultat. 12 | 13 | // **Exemple de sortie attendue** : 14 | // ``` 15 | // Il y a 5 voyelles dans le tableau. 16 | // ``` 17 | public class Exo017 { 18 | public static void main(String[] args) { 19 | char[] tableau = {'a', 'b', 'e', 'f', 'i', 'o', 'u', 'p'}; 20 | char[] voyelles = {'a', 'e', 'i', 'o', 'u', 'y'}; 21 | 22 | int nbVoyelles = 0; 23 | for(int i = 0 ; i < tableau.length ; i++){ 24 | for( int j = 0 ; j < voyelles.length ; j++){ 25 | if(tableau[i] == voyelles[j]){ 26 | nbVoyelles += 1; 27 | break; 28 | } 29 | } 30 | } 31 | 32 | System.out.printf("Il y a %d voyelles dans le tableau\n", nbVoyelles); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo012.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | // - Créez un tableau d'entiers de taille 5. Remplissez le de 5 nombres aléatoires entre 0 et 100. 3 | // - Affichez le 4 | // - Calculez la moyenne des éléments du tableau et affichez-la. 5 | 6 | // **Exemple de sortie attendue** : 7 | 8 | // ``` 9 | // [45,30,56,77,34] 10 | // La moyenne des éléments du tableau est : 48.4 11 | // ``` 12 | public class Exo012 { 13 | public static void main(String[] args) { 14 | int[] tableau = new int[5]; 15 | double somme = 0; 16 | for(int i = 0; i < tableau.length; i++){ 17 | tableau[i] = (int)(Math.random() * 101); 18 | somme += tableau[i]; 19 | } 20 | 21 | afficherTableau(tableau); 22 | System.out.println("La moyenne est de : " + somme/tableau.length); 23 | 24 | 25 | } 26 | public static void afficherTableau(int[] tableau){ 27 | System.out.print("["); 28 | for(int i = 0; i < tableau.length-1; i++){ 29 | System.out.print(tableau[i] + ","); 30 | } 31 | System.out.print(tableau[tableau.length-1]); 32 | 33 | System.out.println("]"); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Exo006.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie2; 2 | 3 | public class Exo006 { 4 | public static void main(String[] args) { 5 | Cercle cercle = new Cercle(10); 6 | cercle.afficherInfos(); 7 | } 8 | } 9 | class Cercle{ 10 | //Attributs 11 | private double rayon; 12 | 13 | //Setter & Getter 14 | public double getRayon() { 15 | return rayon; 16 | } 17 | 18 | public void setRayon(double rayon) { 19 | this.rayon = rayon; 20 | } 21 | 22 | //Constructeur 23 | public Cercle(double rayon) { 24 | this.rayon = rayon; 25 | } 26 | 27 | //Méthodes 28 | public double calculerAire(){ 29 | return Math.PI * this.rayon * this.rayon; 30 | } 31 | public double calculerPerimetre(){ 32 | return 2 * Math.PI * this.rayon; 33 | } 34 | public void afficherInfos(){ 35 | System.out.println("Je suis un cercle avec les caractéristiques suivantes :"); 36 | System.out.printf("%-10s:%10.2f\n","Rayon ", this.rayon); 37 | System.out.printf("%-10s:%10.2f\n","Périmètre ", this.calculerPerimetre()); 38 | System.out.printf("%-10s:%10.2f\n","Aire ", this.calculerAire()); 39 | } 40 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo018.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | // # Exo_18 3 | 4 | // Niveau : 4 ⭐ 5 | 6 | // Compter combien de fois un élément apparaît dans un tableau. 7 | 8 | // **Exercice** : 9 | // - Créez un tableau de 10000 nombre aléatoire. 10 | // - Sachant que les chiffres sont entre 0 et 10 inclusivement, comptez le nombre d'occurence de chaque chiffre. 11 | 12 | // **Exemple de sortie attendue** : 13 | // ``` 14 | // [5,1,2,2,1,4,5,6,6,7,8] 15 | // 1 : 2 16 | // 2 : 2 17 | // 3 : 0 18 | // 4 : 1 19 | // 5 : 2 20 | // 6 : 2 21 | // 7 : 1 22 | // 8 : 1 23 | // 9 : 0 24 | // 10 : 0 25 | // ``` 26 | // --- 27 | 28 | public class Exo018 { 29 | public static void main(String[] args) { 30 | 31 | int[] tableau = new int[10000]; 32 | 33 | for(int i = 0; i < tableau.length; i++){ 34 | tableau[i] = (int)(Math.random() * 11); 35 | } 36 | 37 | int[] occurence = new int[11]; 38 | 39 | for(int i = 0; i < tableau.length; i++){ 40 | occurence[tableau[i]] += 1; 41 | } 42 | 43 | for(int i = 0; i < occurence.length; i++){ 44 | 45 | System.out.printf("%d : %d\n", i , occurence[i]); 46 | 47 | } 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo014.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | // Niveau : 3 ⭐ 3 | 4 | // **Exercice** : 5 | 6 | // Fusionner deux tableaux dans un seul tableau. 7 | 8 | // - Créez deux tableaux : un tableau d'entiers `[1, 2, 3]` et un autre `[4, 5, 6]`. 9 | // - Fusionnez ces deux tableaux pour créer un tableau unique et affichez le résultat. 10 | 11 | // **Exemple de sortie attendue** : 12 | // ``` 13 | // Tableau fusionné : [1, 2, 3, 4, 5, 6] 14 | // ``` 15 | public class Exo014 { 16 | public static void main(String[] args) { 17 | int[] tab1 = {1 , 2 , 3}; 18 | int[] tab2 = {4 , 5 , 6}; 19 | 20 | int[] tab3 = new int[tab1.length + tab2.length]; 21 | 22 | for(int i = 0 ; i < tab1.length ; i++){ 23 | tab3[i] = tab1[i]; 24 | } 25 | for(int i = 0 ; i < tab1.length ; i++){ 26 | tab3[i + tab1.length] = tab2[i]; 27 | } 28 | 29 | afficherTableau(tab3); 30 | 31 | } 32 | public static void afficherTableau(int[] tableau){ 33 | System.out.print("["); 34 | for(int i = 0; i < tableau.length-1; i++){ 35 | System.out.print(tableau[i] + ","); 36 | } 37 | System.out.print(tableau[tableau.length-1]); 38 | 39 | System.out.println("]"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo011.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | // - Créez un tableau d'entiers de taille 5. Remplissez le de 5 nombres aléatoires entre 0 et 100. 3 | // - Affichez le 4 | // - Inverser l'ordre des éléments du tableau. 5 | // - Affichez le 6 | 7 | // **Exemple de sortie attendue** : 8 | // ``` 9 | // [45,30,56,77,34] 10 | // [34,77,56,30,45] 11 | // ``` 12 | public class Exo011 { 13 | public static void main(String[] args) { 14 | int[] tableau = new int[5]; 15 | 16 | for(int i = 0; i < tableau.length; i++){ 17 | tableau[i] = (int)(Math.random() * 101); 18 | } 19 | 20 | afficherTableau(tableau); 21 | 22 | int mem; 23 | for(int i = 0; i < tableau.length; i++){ 24 | mem = tableau[i]; 25 | tableau[i] = tableau[tableau.length - 1 - i]; 26 | tableau[tableau.length - 1 - i] = mem; 27 | } 28 | 29 | afficherTableau(tableau); 30 | 31 | } 32 | public static void afficherTableau(int[] tableau){ 33 | System.out.print("["); 34 | for(int i = 0; i < tableau.length-1; i++){ 35 | System.out.print(tableau[i] + ","); 36 | } 37 | System.out.print(tableau[tableau.length-1]); 38 | 39 | System.out.println("]"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Exo018.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie2; 2 | // - Créez un tableau d'entiers de taille 5. Remplissez le de 5 nombres aléatoires entre 0 et 100. 3 | // - Affichez le 4 | // - Inverser l'ordre des éléments du tableau. 5 | // - Affichez le 6 | 7 | // **Exemple de sortie attendue** : 8 | // ``` 9 | // [45,30,56,77,34] 10 | // [34,77,56,30,45] 11 | // ``` 12 | public class Exo018 { 13 | public static void main(String[] args) { 14 | int[] tableau = new int[5]; 15 | 16 | for(int i = 0; i < tableau.length; i++){ 17 | tableau[i] = (int)(Math.random() * 101); 18 | } 19 | 20 | afficherTableau(tableau); 21 | 22 | int mem; 23 | for(int i = 0; i < tableau.length; i++){ 24 | mem = tableau[i]; 25 | tableau[i] = tableau[tableau.length - 1 - i]; 26 | tableau[tableau.length - 1 - i] = mem; 27 | } 28 | 29 | afficherTableau(tableau); 30 | 31 | } 32 | public static void afficherTableau(int[] tableau){ 33 | System.out.print("["); 34 | for(int i = 0; i < tableau.length-1; i++){ 35 | System.out.print(tableau[i] + ","); 36 | } 37 | System.out.print(tableau[tableau.length-1]); 38 | 39 | System.out.println("]"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo050.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | // Exo_50 5 | // Niveau : 3 ⭐ 6 | 7 | // Exercice : 8 | 9 | // Supprimer un élément d'un ArrayList 10 | 11 | // Créez un ArrayList d'entiers avec les valeurs suivantes : [1, 2, 3, 4, 5]. 12 | // Demandez à l'utilisateur de saisir un nombre à supprimer. 13 | // Supprimez ce nombre de l'ArrayList et affichez l'ArrayList après suppression. 14 | // Exemple de sortie attendue : 15 | 16 | // Entrez un nombre à supprimer : 3 17 | // ArrayList après suppression : [1, 2, 4, 5] 18 | public class Exo050 { 19 | public static void main(String[] args) { 20 | ArrayList liste = new ArrayList<>(); 21 | liste.add(1); 22 | liste.add(2); 23 | liste.add(3); 24 | liste.add(4); 25 | liste.add(5); 26 | 27 | Scanner scanner = new Scanner(System.in); 28 | System.out.print("Entrez un nombre à supprimer : "); 29 | String nombre = scanner.next(); 30 | 31 | liste.remove(Integer.parseInt(nombre)); 32 | for(int i = 0 ; i < liste.size() ; i++){ 33 | if(liste.get(i) == Integer.parseInt(nombre)){ 34 | liste.remove(i); 35 | } 36 | } 37 | System.out.println(liste); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo027.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | public class Exo027 { 3 | 4 | // Méthode pour compter le nombre de voyelles dans une chaîne 5 | public static int compterVoyelles(String chaine) { 6 | // Initialisation du compteur de voyelles 7 | int compteur = 0; 8 | 9 | // Convertir la chaîne en minuscule pour ne pas faire de distinction entre majuscules et minuscules 10 | chaine = chaine.toLowerCase(); 11 | 12 | // Parcours de chaque caractère de la chaîne 13 | for (int i = 0; i < chaine.length(); i++) { 14 | char c = chaine.charAt(i); 15 | // Vérification si le caractère est une voyelle 16 | if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') { 17 | compteur++; 18 | } 19 | } 20 | 21 | // Retourner le nombre de voyelles 22 | return compteur; 23 | } 24 | 25 | public static void main(String[] args) { 26 | String chaine = "Hello World"; 27 | 28 | // Appeler la méthode et afficher le résultat 29 | int nombreVoyelles = compterVoyelles(chaine); 30 | System.out.println(chaine); 31 | System.out.println("Le nombre de voyelles dans la chaîne est : " + nombreVoyelles); 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo048.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | public class Exo048 { 6 | 7 | public static void main(String[] args) { 8 | // Créer un ArrayList de type String et ajouter des valeurs 9 | ArrayList langages = new ArrayList<>(); 10 | langages.add("Java"); 11 | langages.add("Python"); 12 | langages.add("C++"); 13 | langages.add("Ruby"); 14 | 15 | // Afficher la taille de l'ArrayList 16 | System.out.println("La taille de l'ArrayList est : " + langages.size()); 17 | 18 | // Demander à l'utilisateur de saisir un nouveau langage 19 | Scanner scanner = new Scanner(System.in); 20 | System.out.print("Entrez un nouveau langage à ajouter : "); 21 | String nouveauLangage = scanner.nextLine(); 22 | 23 | // Ajouter la nouvelle valeur à l'ArrayList 24 | langages.add(nouveauLangage); 25 | 26 | // Afficher tous les éléments de l'ArrayList 27 | System.out.println("Les langages de programmation dans l'ArrayList sont :"); 28 | for (String langage : langages) { 29 | System.out.println(langage); 30 | } 31 | 32 | // Fermer le scanner 33 | scanner.close(); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo033.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | import java.util.Scanner; 3 | 4 | public class Exo033 { 5 | 6 | // Méthode pour afficher toutes les positions d'un caractère dans une chaîne 7 | public static void afficherPositions(String mot, char lettre) { 8 | // Parcours du mot pour trouver la lettre et afficher ses indices 9 | for (int i = 0; i < mot.length(); i++) { 10 | if (mot.charAt(i) == lettre) { 11 | System.out.println("Le caractère '" + lettre + "' se trouve à l'indice : " + i); 12 | } 13 | } 14 | } 15 | 16 | public static void main(String[] args) { 17 | // Créer un objet Scanner pour lire les entrées de l'utilisateur 18 | Scanner scanner = new Scanner(System.in); 19 | 20 | // Demander à l'utilisateur de saisir un mot 21 | System.out.print("Entrez un mot : "); 22 | String mot = scanner.nextLine(); 23 | 24 | // Demander à l'utilisateur de saisir une lettre 25 | System.out.print("Entrez une lettre : "); 26 | char lettre = scanner.nextLine().charAt(0); // Prendre le premier caractère de la chaîne 27 | 28 | // Appeler la méthode pour afficher les positions 29 | afficherPositions(mot, lettre); 30 | 31 | // Fermer le scanner 32 | scanner.close(); 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo010.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | // Trouver la valeur maximale et minimale d'un tableau. 3 | 4 | // - Créez un tableau d'entiers de taille 5. Remplissez le de 5 nombres aléatoires entre 0 et 100. 5 | // - Affichez le 6 | // - Trouvez le maximum et le minimum du tableau, puis affichez-les. 7 | 8 | // **Exemple de sortie attendue** : 9 | // ``` 10 | // [45,30,56,77,34] 11 | // Le maximum est : 77 12 | // Le minimum est : 30 13 | // ``` 14 | 15 | public class Exo010 { 16 | public static void main(String[] args) { 17 | int[] tableau = new int[5]; 18 | 19 | for(int i = 0; i < tableau.length; i++){ 20 | tableau[i] = (int)(Math.random() * 101); 21 | } 22 | 23 | int min = tableau[0]; 24 | int max = tableau[0]; 25 | 26 | System.out.print("["); 27 | for(int i = 0; i < tableau.length-1; i++){ 28 | System.out.print(tableau[i] + ","); 29 | if(min > tableau[i]){ 30 | min = tableau[i]; 31 | } 32 | if(max < tableau[i]){ 33 | max = tableau[i]; 34 | } 35 | } 36 | System.out.print(tableau[tableau.length-1]); 37 | System.out.println("]"); 38 | 39 | System.out.println("Le maximum est : " + max); 40 | System.out.println("Le minimum est : " + min); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo015.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | // # Exo_15 3 | 4 | // Niveau : 3 ⭐ 5 | 6 | // **Exercice** : 7 | 8 | // - Créez un tableau d'entiers de taille 10. Remplissez le de 10 nombres aléatoires entre 0 et 100. 9 | // - Affichez le 10 | // - Affichez le nombre de nombres pairs dans le 11 | // tableau. 12 | 13 | // **Exemple de sortie attendue** : 14 | // ``` 15 | // [5,1,2,2,1,4,5,6,6,7] 16 | // Il y a 5 nombres pairs dans ce tableau 17 | // ``` 18 | 19 | public class Exo015 { 20 | public static void main(String[] args) { 21 | int[] tableau = new int[10]; 22 | 23 | for(int i = 0; i < tableau.length; i++){ 24 | tableau[i] = (int)(Math.random() * 101); 25 | } 26 | 27 | afficherTableau(tableau); 28 | 29 | int nbPair = 0; 30 | for(int i = 0; i < tableau.length; i++){ 31 | if(tableau[i] % 2 == 0){ 32 | nbPair += 1; 33 | } 34 | } 35 | 36 | System.out.printf("Il y a %d nombres pairs dans ce tableau\n" , nbPair); 37 | 38 | 39 | } 40 | public static void afficherTableau(int[] tableau){ 41 | System.out.print("["); 42 | for(int i = 0; i < tableau.length-1; i++){ 43 | System.out.print(tableau[i] + ","); 44 | } 45 | System.out.print(tableau[tableau.length-1]); 46 | 47 | System.out.println("]"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo056V1.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | import java.time.LocalDate; 3 | import java.time.format.DateTimeFormatter; 4 | import java.time.temporal.ChronoUnit; 5 | 6 | public class Exo056V1 { 7 | 8 | // Fonction pour calculer le nombre de jours entre deux dates 9 | public static long calculerJoursEntreDates(String date1, String date2) { 10 | // Format de la date 11 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); 12 | 13 | // Convertir les chaînes de caractères en LocalDate 14 | LocalDate dateDébut = LocalDate.parse(date1, formatter); 15 | LocalDate dateFin = LocalDate.parse(date2, formatter); 16 | 17 | // Calculer le nombre de jours entre les deux dates, exclusives 18 | return ChronoUnit.DAYS.between(dateDébut, dateFin) - 1; 19 | } 20 | 21 | public static void main(String[] args) { 22 | // Exemple 1 23 | String date1 = "2024-02-04"; 24 | String date2 = "2024-02-06"; 25 | System.out.println("Il y a " + calculerJoursEntreDates(date1, date2) + " jour entre le " + date1 + " et le " + date2 + " (exclusivement)"); 26 | 27 | // Exemple 2 28 | date1 = "2024-02-04"; 29 | date2 = "2024-03-05"; 30 | System.out.println("Il y a " + calculerJoursEntreDates(date1, date2) + " jours entre le " + date1 + " et le " + date2 + " (exclusivement)"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo025.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | // # Exo_25 3 | 4 | // Niveau : 2 ⭐ 5 | 6 | // **Exercice** : 7 | 8 | // ```java 9 | // // Enregistre l'alphabet en minuscule dans une variable 10 | 11 | 12 | // // Affiche la longeur de la varibale alphabet 13 | 14 | 15 | // // Affiche l'alphabet en majuscule 16 | 17 | 18 | 19 | // // Trouve la position du f dans l'alphabet 20 | 21 | 22 | // ``` 23 | 24 | // **Exemple de sortie attendue** : 25 | 26 | // ``` 27 | // L'alphabet a 26 lettres 28 | // ABCDEFGHIJKLMNOPQRSTUVWXYZ 29 | // Le f est à la 6e position dans l'alphabet 30 | // ``` 31 | 32 | public class Exo025 { 33 | public static void main(String[] args) { 34 | // Enregistre l'alphabet en minuscule dans une variable 35 | String alphabet = "abcdefghijklmnopqrstuvwxyz"; 36 | 37 | // Affiche la longueur de la variable alphabet 38 | System.out.println("L'alphabet a " + alphabet.length() + " lettres"); 39 | 40 | // Affiche l'alphabet en majuscule 41 | System.out.println(alphabet.toUpperCase()); 42 | 43 | // Trouve la position du 'f' dans l'alphabet 44 | // L'indice de 'f' dans l'alphabet est 5 (en partant de 0) 45 | int positionF = alphabet.indexOf('f') + 1; // +1 pour obtenir la position en commençant à 1 46 | System.out.println("Le f est à la " + positionF + "e position dans l'alphabet"); 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen1/Q3Examen1.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examen1; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | public class Q3Examen1 { 6 | public static void main(String[] args) { 7 | int[] tab = new int[10]; 8 | 9 | for(int i = 0; i < tab.length; i++){ 10 | tab[i] = (int) (Math.random() * 101); 11 | } 12 | afficheTableau(tab); 13 | 14 | int indiceMin; 15 | int mem; 16 | for(int i = 0; i < tab.length; i++){ 17 | indiceMin = i; 18 | for(int j = i; j < tab.length; j++){ 19 | if(tab[j] < tab[indiceMin]){ 20 | indiceMin = j; 21 | } 22 | } 23 | mem = tab[indiceMin]; 24 | tab[indiceMin] = tab[i]; 25 | tab[i] = mem; 26 | } 27 | afficheTableau(tab); 28 | // ArrayList tab = new ArrayList(); 29 | // for(int i = 0; i < 10; i++){ 30 | // tab.add((int) (Math.random() * 11)); 31 | // } 32 | // System.out.println(tab); 33 | // Collections.sort(tab); 34 | // System.out.println(tab); 35 | } 36 | public static void afficheTableau(int[] tab){ 37 | System.out.print("["); 38 | for(int i = 0 ; i < tab.length - 1; i++){ 39 | System.out.print(tab[i] + ","); 40 | } 41 | System.out.println(tab[tab.length - 1] + "]"); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Exo001.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie2; 2 | import java.util.ArrayList; 3 | 4 | class Personne { 5 | //Attributs 6 | private String nom; 7 | private int age; 8 | 9 | 10 | //Setter & Getter 11 | public String getNom() { 12 | return nom; 13 | } 14 | public void setNom(String nom) { 15 | this.nom = nom; 16 | } 17 | public int getAge() { 18 | return age; 19 | } 20 | public void setAge(int age) { 21 | this.age = age; 22 | } 23 | 24 | 25 | //Constructeur 26 | public Personne(String nom, int age) { 27 | this.nom = nom; 28 | this.age = age; 29 | } 30 | 31 | 32 | //Méthodes 33 | @Override 34 | public String toString(){ 35 | return "Nom : " + this.nom + ", Âge : " + this.age; 36 | } 37 | } 38 | 39 | //Main 40 | public class Exo001 { 41 | public static void main(String[] args) { 42 | // Création d'un ArrayList de Personne 43 | ArrayList personnes = new ArrayList<>(); 44 | 45 | // Ajout de plusieurs objets Personne 46 | personnes.add(new Personne("John", 30)); 47 | personnes.add(new Personne("Sarah", 25)); 48 | personnes.add(new Personne("Marc", 35)); 49 | 50 | // Parcours de l'ArrayList et affichage des informations 51 | for (int i = 0 ; i < personnes.size() ; i++) { 52 | System.out.println(personnes.get(i)); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/exo029/src/main/java/cours/c/Vehicule.java: -------------------------------------------------------------------------------- 1 | package cours.c; 2 | 3 | import cours.a.b.Voiture; 4 | 5 | public class Vehicule { 6 | private String marque; 7 | private int annee; 8 | 9 | 10 | public Vehicule(String marque, int annee){ 11 | this.setMarque(marque); 12 | this.setAnnee(annee); 13 | } 14 | 15 | public void setMarque(String marque){ 16 | this.marque = marque; 17 | } 18 | 19 | public String getMarque(){ 20 | return this.marque; 21 | } 22 | 23 | public void setAnnee(int annee){ 24 | this.annee = annee; 25 | } 26 | 27 | public int getAnnee(){ 28 | return this.annee; 29 | } 30 | 31 | protected void afficherInfo() { 32 | System.out.println("Marque: " + marque + ", Année: " + annee); 33 | } 34 | 35 | public void salutation(){ 36 | System.out.println("Bonjour, je suis un véhicule."); 37 | } 38 | 39 | private void afficherPrix(){ 40 | System.out.println("1000000"); 41 | } 42 | public static void main(String[] args) { 43 | Vehicule vehicule = new Vehicule("Toyota", 2022); 44 | Voiture voiture = new Voiture("Toyota", 2022, 4); 45 | 46 | vehicule.afficherInfo(); 47 | vehicule.salutation(); 48 | vehicule.afficherPrix(); 49 | 50 | voiture.afficherInfo(); 51 | voiture.afficherInfoVoiture(); 52 | voiture.salutation(); 53 | voiture.afficherPrix(); 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen1/formatif/TrieV2.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examen1.formatif; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | public class TrieV2 { 6 | public static void main(String[] args) { 7 | // ArrayList liste = new ArrayList(); 8 | // for(int i = 0 ; i < 10 ; i++){ 9 | // liste.add((int)(Math.random() * 101)); 10 | // } 11 | // System.out.println(liste); 12 | // Collections.sort(liste); 13 | // System.out.println(liste); 14 | int[] tab = new int[10]; 15 | for(int i = 0 ; i < tab.length ; i++){ 16 | tab[i] = (int)(Math.random() * 101); 17 | } 18 | afficheTableau(tab); 19 | 20 | int indiceMin = 0; 21 | int mem; 22 | for(int i = 0 ; i < tab.length ; i++){ 23 | indiceMin = i; 24 | for(int j = i; j < tab.length ; j++){ 25 | if(tab[j] < tab[indiceMin]){ 26 | indiceMin = j; 27 | } 28 | } 29 | mem = tab[i]; 30 | tab[i] = tab[indiceMin]; 31 | tab[indiceMin] = mem; 32 | } 33 | afficheTableau(tab); 34 | 35 | } 36 | public static void afficheTableau(int[] tab){ 37 | System.out.print("["); 38 | for(int i = 0 ; i < tab.length - 1 ; i++){ 39 | System.out.print(tab[i] + ", "); 40 | } 41 | System.out.print(tab[tab.length - 1]); 42 | System.out.println("]"); 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen1/formatif/CompteBancaire.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examen1.formatif; 2 | 3 | public class CompteBancaire{ 4 | String titulaire; 5 | double solde; 6 | public CompteBancaire(String titulaire, double solde){ 7 | this.titulaire = titulaire; 8 | this.solde = solde; 9 | } 10 | public void deposer(double montant){ 11 | if(montant > 0){ 12 | this.solde += montant; 13 | System.out.printf("%.02f$ déposé. Nouveau solde : %.02f$\n",montant,this.solde); 14 | } 15 | else{ 16 | System.out.println("Montant invalide"); 17 | } 18 | } 19 | public void retirer(double montant){ 20 | if(montant > 0){ 21 | if(montant <= this.solde){ 22 | this.solde -= montant; 23 | System.out.printf("%.02f$ retiré. Nouveau solde : %.02f$\n",montant,this.solde); 24 | 25 | } 26 | else{ 27 | System.out.println("Solde insuffisant"); 28 | } 29 | } 30 | else{ 31 | System.out.println("Montant invalide"); 32 | } 33 | } 34 | public void afficherInfo(){ 35 | System.out.printf("Titulaire : %s | Solde : %.02f$\n", this.titulaire, this.solde); 36 | } 37 | public static void main(String[] args) { 38 | CompteBancaire Alice = new CompteBancaire("Alice Dupont", 500.75); 39 | Alice.afficherInfo(); 40 | Alice.deposer(150); 41 | Alice.retirer(200); 42 | Alice.retirer(500); 43 | 44 | } 45 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Exo005.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie2; 2 | 3 | public class Exo005 { 4 | public static void main(String[] args) { 5 | 6 | Etudiant etudiant1 = new Etudiant("Jean Dupont", 10, 10); 7 | Etudiant etudiant2 = new Etudiant("Jean Gauthier", 30, 0); 8 | 9 | etudiant1.afficherResultat(); 10 | etudiant2.afficherResultat(); 11 | } 12 | } 13 | class Etudiant{ 14 | //Attributs 15 | private String nom; 16 | private int age; 17 | private double moyenne; 18 | 19 | //Setter & Getter 20 | public String getNom() { 21 | return nom; 22 | } 23 | public void setNom(String nom) { 24 | this.nom = nom; 25 | } 26 | public int getAge() { 27 | return age; 28 | } 29 | public void setAge(int age) { 30 | this.age = age; 31 | } 32 | public double getMoyenne() { 33 | return moyenne; 34 | } 35 | public void setMoyenne(double moyenne) { 36 | this.moyenne = moyenne; 37 | } 38 | 39 | 40 | //Constructeur 41 | public Etudiant(String nom, int age, double moyenne) { 42 | this.setNom(nom); 43 | this.setAge(age); 44 | this.setMoyenne(moyenne); 45 | } 46 | 47 | 48 | //Méthodes 49 | public boolean estAdmis(){ 50 | return this.moyenne >= 10 ? true : false; 51 | } 52 | 53 | public void afficherResultat(){ 54 | 55 | System.out.println(this.getNom() + (this.estAdmis() ? " est " : " n'est pas ") + "admis"); 56 | 57 | } 58 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Exo008.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie2; 2 | 3 | public class Exo008 { 4 | public static void main(String[] args) { 5 | Evaluation eval1 = new Evaluation("Examen 1", 0.3f); 6 | eval1.setNoteSur100((byte)50); 7 | eval1.afficheEvaluation(); 8 | eval1.setNoteSur100((byte)75); 9 | eval1.afficheEvaluation(); 10 | } 11 | } 12 | class Evaluation{ 13 | //Attributs 14 | private String nom; 15 | private float ponderation; 16 | private byte noteSur100; 17 | 18 | //Getter & Setter 19 | public String getNom() { 20 | return nom; 21 | } 22 | 23 | public void setNom(String nom) { 24 | this.nom = nom; 25 | } 26 | 27 | public float getPonderation() { 28 | return ponderation; 29 | } 30 | 31 | public void setPonderation(float ponderation) { 32 | this.ponderation = ponderation; 33 | } 34 | 35 | public byte getNoteSur100() { 36 | return noteSur100; 37 | } 38 | 39 | public void setNoteSur100(byte noteSur100) { 40 | this.noteSur100 = noteSur100; 41 | } 42 | 43 | //Constructeur 44 | public Evaluation(String nom,float ponderation){ 45 | this.nom = nom; 46 | this.ponderation = ponderation; 47 | } 48 | 49 | //Méthodes 50 | public byte notePonderee(){ 51 | return (byte) (this.noteSur100 * this.ponderation); 52 | } 53 | public void afficheEvaluation(){ 54 | System.out.println(this.nom + " " + this.ponderation + " " + this.notePonderee()); 55 | } 56 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/exo029/src/main/java/cours/a/b/Voiture.java: -------------------------------------------------------------------------------- 1 | package cours.a.b; 2 | import cours.c.Vehicule; 3 | public class Voiture extends Vehicule { 4 | 5 | private int nombreDePortes; 6 | 7 | public Voiture(String marque, int annee, int nombreDePortes){ 8 | super(marque, annee); 9 | this.setNombreDePortes(nombreDePortes); 10 | } 11 | 12 | public void setNombreDePortes(int nombreDePortes){ 13 | this.nombreDePortes = nombreDePortes; 14 | } 15 | 16 | public int getNombreDePortes(){ 17 | return this.nombreDePortes; 18 | } 19 | 20 | 21 | protected void afficherInfoVoiture() { 22 | super.afficherInfo(); // Appel de la méthode de la superclasse 23 | 24 | System.out.println("Nombre de portes: " + nombreDePortes); 25 | } 26 | 27 | 28 | 29 | public void salutationVoiture(){ 30 | System.out.println("Bonjour, je suis un véhicule."); 31 | } 32 | 33 | private void afficherPrixVoiture(){ 34 | System.out.println("1000000"); 35 | } 36 | 37 | public static void main(String[] args) { 38 | Vehicule vehicule = new Vehicule("Toyota", 2022); 39 | Voiture voiture = new Voiture("Toyota", 2022, 4); 40 | 41 | vehicule.afficherInfo(); 42 | vehicule.salutation(); 43 | vehicule.afficherPrix(); 44 | 45 | voiture.afficherInfo(); 46 | voiture.afficherInfoVoiture(); 47 | voiture.salutation(); 48 | voiture.afficherPrixVoiture(); 49 | 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo006.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | 3 | public class Exo006 { 4 | public static void main(String args[]){ 5 | //-------------------------------------------------------------------- 6 | // Afficher le résulat de ces comparaisons sans l'écrire explicitement 7 | //-------------------------------------------------------------------- 8 | boolean reponse; 9 | // Enregistre dans une variable si 44 est égal à 66 10 | reponse = 44 == 66; 11 | System.out.println(reponse); 12 | 13 | // Enregistre dans une varible si 44 n'est pas égal a 66 14 | reponse = 44 != 66; 15 | System.out.println(reponse); 16 | 17 | // Enregistre dans une variable si 44 est plus grand que 66 18 | reponse = 44 > 66; 19 | System.out.println(reponse); 20 | 21 | // Enregistre dans une varible si 44 est plus petit ou égal à 66 22 | reponse = 44 <= 66; 23 | System.out.println(reponse); 24 | 25 | boolean estSante = true; 26 | boolean estAbordable = false; 27 | 28 | // Affiche true si les variable estSante et estAbordable sont toutes les 2 true, false sinon 29 | System.out.println(estSante & estAbordable); 30 | 31 | // Affiche true si estSante est fausse et estAbordable est true, false sinon 32 | System.out.println(!estSante & estAbordable); 33 | 34 | 35 | 36 | // Affiche true si estSante ou estAbordable est true, false sinon 37 | System.out.println(estSante | estAbordable); 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo020.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | public class Exo020{ 3 | public static void main(String args[]){ 4 | int[] tableau = new int[10000]; 5 | for (int i = 0; i < tableau.length ; i++){ 6 | tableau[i] = (int)(Math.random()*65536) + 1; 7 | } 8 | // afficheTableau(tableau); 9 | quickSort(tableau, 0, tableau.length - 1); 10 | afficheTableau(tableau); 11 | 12 | } 13 | public static void quickSort(int[] tableau, int start, int end){ 14 | int indicePivot = end; 15 | int mem = 0; 16 | for(int i = end - 1 ; i >= start ; i--){ 17 | if(tableau[i] > tableau[indicePivot]){ 18 | mem = tableau[i]; 19 | tableau[i] = tableau[indicePivot - 1]; 20 | tableau[indicePivot - 1] = tableau[indicePivot]; 21 | tableau[indicePivot] = mem; 22 | indicePivot--; 23 | } 24 | } 25 | if(indicePivot > 1){ 26 | quickSort(tableau, start, indicePivot-1); 27 | } 28 | if(indicePivot + 1 0){ 40 | System.out.print(tableau[tableau.length-1]); 41 | } 42 | System.out.print("]\n"); 43 | } 44 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie4/Golf.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie4; 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | /*Chantier */ 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | /* 27 | Aller à la ligne X, colonne Y \u001B[;H ou f 28 | Déplacer le curseur vers le haut N \u001B[A 29 | Vers le bas \u001B[B 30 | À droite \u001B[C 31 | À gauche \u001B[D 32 | Effacer l’écran \u001B[2J 33 | Effacer la ligne \u001B[2K 34 | Revenir au début de la ligne \r 35 | */ 36 | public class Golf{ 37 | final static int ARENA_WIDTH = 128; 38 | final static int ARENA_HIGHT = 16; 39 | public static void main(String[] args) throws InterruptedException{ 40 | System.out.print("\033[H\033[2J"); 41 | System.out.flush(); 42 | loadArena(); 43 | } 44 | static void loadArena() throws InterruptedException{ 45 | for(int i = 0 ; i < ARENA_HIGHT; i++){ 46 | System.out.println("|"); 47 | Thread.sleep(15); 48 | } 49 | for(int i = 0 ; i < ARENA_WIDTH; i++){ 50 | System.out.print("-"); 51 | Thread.sleep(5); 52 | } 53 | 54 | for(int i = 0 ; i < ARENA_HIGHT; i++){ 55 | System.out.print("\u001B[1D\u001B[1A"); 56 | System.out.print("|"); 57 | Thread.sleep(15); 58 | } 59 | System.out.print("\u001B[1D\u001B[1A"); 60 | 61 | for(int i = 0 ; i < ARENA_WIDTH; i++){ 62 | System.out.print("-\u001B[2D"); 63 | Thread.sleep(5); 64 | } 65 | 66 | 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen3/formatif/Rg.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examen3.formatif; 2 | 3 | public class Rg { 4 | public static void main(String[] args) { 5 | Jeu test = new Jeu("null", 0, false); 6 | 7 | } 8 | } 9 | 10 | 11 | abstract class Article{ 12 | String nom; 13 | float prix; 14 | boolean enStock; 15 | public Article(String nom, float prix, boolean enStock){ 16 | this.nom = nom; 17 | this.prix = prix; 18 | this.enStock = enStock; 19 | } 20 | 21 | abstract void imprimerEtiquette(); 22 | 23 | abstract void imprimerEtiquette(float rabais); 24 | 25 | public float calculPrixEnGroupe(int nb){ 26 | return prix * nb; 27 | } 28 | public float calculPrixEnGroupe(int nb, float rabaisDeGroupe){ 29 | return prix * nb * (1- rabaisDeGroupe); 30 | } 31 | } 32 | 33 | class Jeu extends Article{ 34 | public Jeu(String nom, float prix, boolean enStock){ 35 | super(nom, prix, enStock); 36 | } 37 | public void imprimerEtiquette() { 38 | System.out.println("Jeu: " + nom + ", Prix: " + prix + "€" + (enStock ? " (En stock)" : " (Rupture)")); 39 | } 40 | 41 | public void imprimerEtiquette(float rabais) { 42 | float prixAvecRabais = prix * (1 - rabais); 43 | System.out.println("Jeu: " + nom + ", Prix après rabais: " + prixAvecRabais + "€" + (enStock ? " (En stock)" : " (Rupture)")); 44 | } 45 | 46 | 47 | public float calculPrixEnGroupe(int nb, float rabaisDeGroupe, float rabaisPromotionnel){ 48 | return prix * nb * (1 - rabaisDeGroupe) * (1 - rabaisPromotionnel); 49 | } 50 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen2/formatif/question2/Animal.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examen2.formatif.question2; 2 | 3 | public class Animal { 4 | private String nom; 5 | private int age; 6 | private String race; 7 | 8 | public void setNom(String nom){ 9 | this.nom = nom; 10 | } 11 | public void setAge(int age){ 12 | this.age = age; 13 | } 14 | public void setRace(String race){ 15 | this.race = race; 16 | } 17 | 18 | public String getNom(){ 19 | return this.nom; 20 | } 21 | public int getAge(){ 22 | return this.age; 23 | } 24 | public String getRace(){ 25 | return this.race; 26 | } 27 | 28 | public Animal(String nom, int age, String race){ 29 | this.setNom(nom); 30 | this.setAge(age); 31 | this.setRace(race); 32 | } 33 | } 34 | 35 | class Chat extends Animal{ 36 | public Chat(String nom, int age, String race){ 37 | super(nom, age, race); 38 | 39 | } 40 | public String parler(){ 41 | return "Meow!"; 42 | } 43 | public void sePresenter(){ 44 | System.out.println("Je suis un " + this.getRace() + ", mon nom est " + this.getNom() + ", j'ai " + this.getAge() + " ans (" + this.parler() + ")" ); 45 | } 46 | } 47 | 48 | class Chien extends Animal{ 49 | public Chien(String nom, int age, String race){ 50 | super(nom, age, race); 51 | 52 | } 53 | public String parler(){ 54 | return "Wouf!"; 55 | } 56 | public void sePresenter(){ 57 | System.out.println("Je suis un " + this.getRace() + ", mon nom est " + this.getNom() + ", j'ai " + this.getAge() + " ans (" + this.parler() + ")" ); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen2/formatif/théorie/corrThE2.txt: -------------------------------------------------------------------------------- 1 | 1 2 | A:2 B:4 C:5 D:3 E:1 3 | 4 | 2: 5 | 6 | private -> protected -> public 7 | 8 | 3: 9 | int -> car 200000 > 32000(short) et < 2_000_000(int) 10 | 11 | 4: 12 | Faux 13 | 14 | class CompteBancaire{ 15 | private String titulaire; 16 | private double solde; //1 17 | 18 | public String getTitulaire(){ 19 | return this.titulaire; //2 20 | } 21 | 22 | public void setTitulaire(String titulaire){ //3 23 | this.titulaire = titulaire; //4 24 | } 25 | 26 | public double getSolde(){ //5 27 | return this.solde; 28 | } 29 | public void setSolde(double solde){ 30 | this.solde = solde; 31 | } 32 | 33 | public CompteBancaire(String titulaire, double solde){ //6 34 | this.setTitulaire(titulaire); 35 | this.setSolde(solde); //7 36 | } 37 | 38 | public void deposer(double montant){ 39 | if(montant > 0){ 40 | this.solde += montant;//8 41 | System.out.println("Montant déposé : " + montant); 42 | } else { 43 | System.out.println("Le montant doit être positif"); 44 | } 45 | } 46 | 47 | public void retirer(double montant){ 48 | if(montant > 0 && montant <= this.solde){ 49 | this.solde -= montant; 50 | System.out.println("Montant retiré : " + montant); 51 | } else if(montant > this.solde){ 52 | System.out.println("Solde insuffisant");//9 53 | } else{ 54 | System.out.println("Lemontant doit être positif."); 55 | } 56 | } 57 | 58 | public void afficherSolde(){//10 59 | System.out.println("Solde actuel : " + this.solde); 60 | } 61 | 62 | public void afficherInfo(){ 63 | System.out.println("Titulaire : " + this.titulaire + ", Solde : " + this.solde + " $"); 64 | } 65 | }//11 66 | 67 | 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/cours/Main.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie2.cours; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Vehicule vehicule = new Vehicule("Toyota Echo",2001); 6 | Voiture voiture = new Voiture("Toyota Echo",2001); 7 | 8 | vehicule.afficherInfo(); 9 | 10 | voiture.afficherInfoVoiture(); 11 | } 12 | } 13 | class Vehicule { 14 | private String marque; 15 | private int annee; 16 | 17 | public Vehicule(String marque, int annee){ 18 | this.setMarque(marque); 19 | this.setAnnee(annee); 20 | } 21 | 22 | public void setMarque(String marque){ 23 | this.marque = marque; 24 | } 25 | 26 | public String getMarque(){ 27 | return this.marque; 28 | } 29 | 30 | public void setAnnee(int annee){ 31 | this.annee = annee; 32 | } 33 | 34 | public int getAnnee(){ 35 | return this.annee; 36 | } 37 | 38 | public void afficherInfo() { 39 | System.out.println("Marque: " + marque + ", Année: " + annee); 40 | } 41 | } 42 | 43 | 44 | 45 | class Voiture extends Vehicule { 46 | private int nombreDePortes = 4; 47 | 48 | public Voiture(String marque, int annee){ 49 | super(marque,annee); 50 | } 51 | 52 | 53 | public void setNombreDePortes(int nombreDePortes){ 54 | this.nombreDePortes = nombreDePortes; 55 | } 56 | 57 | public int getNombreDePortes(){ 58 | return this.nombreDePortes; 59 | } 60 | 61 | 62 | public void afficherInfoVoiture() { 63 | afficherInfo(); // Appel de la méthode de la superclasse 64 | System.out.println("Nombre de portes: " + nombreDePortes); 65 | } 66 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo021.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | // Niveau : 1 ⭐ 3 | 4 | // **Exercice** : 5 | 6 | // Ajoutez à la classe calculatrice : une méthode pour calculer un rabais sur un prix qui seront tous les 2 donnés en paramètre. 7 | 8 | // **Exemple de sortie attendue** : 9 | // ``` 10 | // Le rabais de 20% sur 100$ est de 20$ 11 | // ``` 12 | public class Exo021 { 13 | // Déclaration d'une constante pour le taux de taxe 14 | public static final double TAUX_DE_TAXE = 0.70; 15 | 16 | // Méthode principale qui sera exécutée lors du lancement du programme 17 | public static void main(String[] args) { 18 | // Déclaration de variables locales 19 | double prixInitial = 100.0; // Prix initial d'un produit 20 | double prixFinal = calculerPrixAvecTaxe(prixInitial); // Calcul du prix après taxe 21 | 22 | // Affichage du résultat 23 | System.out.println("Prix initial : " + prixInitial + "€"); 24 | System.out.println("Prix final après application de la taxe : " + prixFinal + "€"); 25 | 26 | System.out.printf("Le rabais est de %d%% sur %.2f$ est de %.2f$\n",20,prixInitial, calculerRabaisPrix(0.2, prixInitial)); 27 | 28 | } 29 | 30 | // Méthode pour calculer le prix final avec taxe 31 | // Cette méthode prend le prix initial comme paramètre et retourne le prix après ajout de la taxe 32 | public static double calculerPrixAvecTaxe(double prix) { 33 | // Calcul du prix final en ajoutant la taxe 34 | double taxe = prix * TAUX_DE_TAXE; // Calcul de la taxe 35 | double prixAvecTaxe = prix + taxe; // Calcul du prix total avec taxe 36 | 37 | return prixAvecTaxe; // Retourne le prix final 38 | } 39 | public static double calculerRabaisPrix(double rabais, double prix){ 40 | return rabais * prix; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/formatif2/question2/q2V1.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examenFinal.formatif2.question2; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class q2V1 { 6 | public static void main(String[] args) { 7 | 8 | Employe alice = new Employe("Directrice Marketing", "Alice Tremblay", null); 9 | ArrayList listeJean = new ArrayList<>(); 10 | listeJean.add(alice); 11 | Employe jean = new Employe("PDG", "Jean Dupuis", listeJean); 12 | 13 | 14 | jean.affiche(0); 15 | } 16 | } 17 | 18 | 19 | class Employe{ 20 | private String titre; 21 | private String nom; 22 | private ArrayList employes; 23 | 24 | 25 | public Employe(String titre, String nom, ArrayList employes) { 26 | this.titre = titre; 27 | this.nom = nom; 28 | this.employes = employes; 29 | } 30 | public String getTitre() { 31 | return titre; 32 | } 33 | public void setTitre(String titre) { 34 | this.titre = titre; 35 | } 36 | public String getNom() { 37 | return nom; 38 | } 39 | public void setNom(String nom) { 40 | this.nom = nom; 41 | } 42 | public ArrayList getEmployes() { 43 | return employes; 44 | } 45 | public void setEmployes(ArrayList employes) { 46 | this.employes = employes; 47 | } 48 | 49 | public void affiche(int nivIndent){ 50 | String msg = ""; 51 | msg += "\t".repeat(nivIndent); 52 | msg += String.format("%s - %s\n",this.nom, this.titre); 53 | System.out.print(msg); 54 | if(this.employes != null){ 55 | 56 | for (Employe employe : employes) { 57 | employe.affiche(nivIndent + 1); 58 | } 59 | } 60 | } 61 | 62 | 63 | 64 | } 65 | 66 | 67 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo013v2.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | // Niveau : 6 ⭐ 3 | 4 | // **Exercice** : 5 | 6 | // - Supprimer les doublons du tableau suivant en supposant que vous ne savez pas d'avance les valeur dans le tableau: `[5,1,2,2,1,4,5,6,6,7,8]`. 7 | // - Affichez le nouveau tableau 8 | // **Exemple de sortie attendue** : 9 | // ``` 10 | // [5,1,2,4,6,7,8] 11 | // ``` 12 | public class Exo013v2 { 13 | public static void main(String[] args) { 14 | int[] tableau = new int[100000]; 15 | 16 | for(int i = 0; i < tableau.length; i++){ 17 | tableau[i] = (int)(Math.random() * 100000); 18 | } 19 | 20 | afficherTableau(tableau); 21 | 22 | int[] tableauSansDoublon = new int[tableau.length]; 23 | int nbDoublons = 0; 24 | boolean isUnique = true; 25 | int k = 0; 26 | for (int i = 0; i < tableau.length; i++) { 27 | for (int j = 0; j < i; j++) { 28 | if(tableau[i] == tableau[j]){ 29 | nbDoublons += 1; 30 | isUnique = false; 31 | break; 32 | } 33 | } 34 | 35 | if(!isUnique){ 36 | isUnique = true; 37 | continue; 38 | } 39 | tableauSansDoublon[k] = tableau[i]; 40 | k++; 41 | } 42 | int[] goodSize = new int[tableau.length - nbDoublons]; 43 | for (int i = 0; i < goodSize.length; i++) { 44 | goodSize[i] = tableauSansDoublon[i]; 45 | } 46 | 47 | afficherTableau(goodSize); 48 | } 49 | public static void afficherTableau(int[] tableau){ 50 | System.out.print("["); 51 | for(int i = 0; i < tableau.length-1; i++){ 52 | System.out.print(tableau[i] + ","); 53 | } 54 | System.out.print(tableau[tableau.length-1]); 55 | 56 | System.out.println("]"); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Exo026.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie2; 2 | 3 | public class Exo026 { 4 | public static void main(String[] args) { 5 | Chien chien = new Chien("Rex", 3, "Berger Allemand"); 6 | Chat chat = new Chat("Matou", 12, "Sphinx"); 7 | 8 | chien.sePresenter(); 9 | System.out.println(chien.parler()); 10 | 11 | chat.sePresenter(); 12 | System.out.println(chat.parler()); 13 | 14 | } 15 | } 16 | class Animal{ 17 | protected String nom; 18 | protected int age; 19 | protected String race; 20 | 21 | public void setNom(String nom){ 22 | this.nom = nom; 23 | } 24 | public String getNom(){ 25 | return this.nom; 26 | } 27 | public void setAge(int age){ 28 | this.age = age; 29 | } 30 | public int getAge(){ 31 | return this.age; 32 | } 33 | public void setRace(String race){ 34 | this.race = race; 35 | } 36 | public String getRace(){ 37 | return this.race; 38 | } 39 | 40 | public Animal(String nom, int age, String race){ 41 | this.setNom(nom); 42 | this.setAge(age); 43 | this.setRace(race); 44 | } 45 | } 46 | class Chien extends Animal{ 47 | 48 | public Chien(String nom, int age, String race){ 49 | super(nom, age, race); 50 | } 51 | public String parler(){ 52 | return "Woof!"; 53 | } 54 | public void sePresenter(){ 55 | System.out.printf("Je suis un %s, mon nom est %s, j'ai %d ans (%s).\n", this.getRace(), this.getNom(), this.getAge(), this.parler()); 56 | } 57 | } 58 | class Chat extends Animal{ 59 | public Chat(String nom, int age, String race){ 60 | super(nom, age, race); 61 | } 62 | public String parler(){ 63 | return "Meow!"; 64 | } 65 | public void sePresenter(){ 66 | System.out.printf("Je suis un %s, mon nom est %s, j'ai %d ans (%s).\n", this.getRace(), this.getNom(), this.getAge(), this.parler()); 67 | } 68 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Exo002.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie2; 2 | public class Exo002 { 3 | public static void main(String[] args) { 4 | // Création de plusieurs instances de la classe Examen 5 | Examen etudiant1 = new Examen("Jean Dupont", (byte) 95); 6 | Examen etudiant2 = new Examen("Marie Curie", (byte) 85); 7 | Examen etudiant3 = new Examen("Paul Martin", (byte) 72); 8 | Examen etudiant4 = new Examen("Sophie Lefevre", (byte) 65); 9 | Examen etudiant5 = new Examen("Lucie Durand", (byte) 55); 10 | 11 | // Affichage des résultats 12 | etudiant1.afficheResultat(); 13 | etudiant2.afficheResultat(); 14 | etudiant3.afficheResultat(); 15 | etudiant4.afficheResultat(); 16 | etudiant5.afficheResultat(); 17 | } 18 | } 19 | 20 | class Examen{ 21 | // Attributs 22 | private String nomEtudiant; 23 | private byte note; 24 | 25 | 26 | //Getter & Setter 27 | public String getNomEtudiant() { 28 | return nomEtudiant; 29 | } 30 | public void setNomEtudiant(String nomEtudiant) { 31 | this.nomEtudiant = nomEtudiant; 32 | } 33 | public byte getNote() { 34 | return note; 35 | } 36 | public void setNote(byte note) { 37 | this.note = note; 38 | } 39 | 40 | 41 | 42 | // Constructeur 43 | public Examen(String nomEtudiant, byte note) { 44 | this.nomEtudiant = nomEtudiant; 45 | this.note = note; 46 | } 47 | 48 | 49 | // Méthodes 50 | public void afficheResultat() { 51 | System.out.println(nomEtudiant + " : " + convertNote()); 52 | } 53 | 54 | public String convertNote() { 55 | if (note > 90) { 56 | return "A"; 57 | } else if (note > 80) { 58 | return "B"; 59 | } else if (note > 70) { 60 | return "C"; 61 | } else if (note > 60) { 62 | return "D"; 63 | } else { 64 | return "E"; 65 | } 66 | } 67 | 68 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Exo004.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie2; 2 | 3 | public class Exo004 { 4 | public static void main(String[] args) { 5 | Livre livre = new Livre("Eragon","Christopher Paolini", 20.99, true); 6 | livre.afficherDetails(); 7 | livre.setDisponible(false); 8 | livre.afficherDetails(); 9 | } 10 | } 11 | class Livre{ 12 | //Attributs 13 | private String titre; 14 | private String auteur; 15 | private double prix; 16 | private boolean disponible; 17 | 18 | 19 | //Setter & Getter 20 | public String getTitre() { 21 | return titre; 22 | } 23 | public void setTitre(String titre) { 24 | this.titre = titre; 25 | } 26 | public String getAuteur() { 27 | return auteur; 28 | } 29 | public void setAuteur(String auteur) { 30 | this.auteur = auteur; 31 | } 32 | public double getPrix() { 33 | return prix; 34 | } 35 | public void setPrix(double prix) { 36 | this.prix = prix; 37 | } 38 | public boolean isDisponible() { 39 | return disponible; 40 | } 41 | public void setDisponible(boolean disponible) { 42 | this.disponible = disponible; 43 | } 44 | 45 | 46 | //Constructeur 47 | public Livre(String titre, String auteur, double prix, boolean disponible) { 48 | this.setTitre(titre); 49 | this.setAuteur(auteur); 50 | this.setPrix(prix); 51 | this.setDisponible(disponible); 52 | } 53 | 54 | //Méthodes 55 | public void afficherDetails(){ 56 | System.out.printf("%-40s%-25s%10.2f$ %s\n",this.titre, this.auteur,this.prix,this.disponible ? "Disponible" : "Déjà loué"); 57 | } 58 | 59 | public void emprunter(){ 60 | if(this.disponible){ 61 | this.disponible = false; 62 | } 63 | else{ 64 | System.out.println("Le livre n'est pas disponible"); 65 | } 66 | } 67 | 68 | public void retourner(){ 69 | this.disponible = true; 70 | } 71 | 72 | 73 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo013.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | // Niveau : 6 ⭐ 3 | 4 | // **Exercice** : 5 | 6 | // - Supprimer les doublons du tableau suivant en supposant que vous ne savez pas d'avance les valeur dans le tableau: `[5,1,2,2,1,4,5,6,6,7,8]`. 7 | // - Affichez le nouveau tableau 8 | // **Exemple de sortie attendue** : 9 | // ``` 10 | // [5,1,2,4,6,7,8] 11 | // ``` 12 | public class Exo013 { 13 | public static void main(String[] args) { 14 | int[] tableau = new int[100000]; 15 | 16 | for(int i = 0; i < tableau.length; i++){ 17 | tableau[i] = (int)(Math.random() * 100000); 18 | } 19 | 20 | afficherTableau(tableau); 21 | 22 | int nbDoublon = 0; 23 | for(int i = 0; i < tableau.length; i++){ 24 | for(int j = 0; j < i; j++){ 25 | if(tableau[i] == tableau[j]){ 26 | nbDoublon += 1; 27 | break; 28 | } 29 | } 30 | } 31 | 32 | int[] tableauSansDoublon = new int[tableau.length - nbDoublon]; 33 | boolean isDoublon = false; 34 | int k = 0; 35 | for(int i = 0; i < tableau.length; i++){ 36 | for(int j = 0; j < i; j++){ 37 | if(tableau[i] == tableau[j]){ 38 | nbDoublon += 1; 39 | isDoublon = true; 40 | break; 41 | } 42 | 43 | } 44 | if(!isDoublon){ 45 | tableauSansDoublon[k] = tableau[i]; 46 | k++; 47 | 48 | } 49 | isDoublon = false; 50 | } 51 | tableau = tableauSansDoublon; 52 | afficherTableau(tableau); 53 | 54 | } 55 | public static void afficherTableau(int[] tableau){ 56 | System.out.print("["); 57 | for(int i = 0; i < tableau.length-1; i++){ 58 | System.out.print(tableau[i] + ","); 59 | } 60 | System.out.print(tableau[tableau.length-1]); 61 | 62 | System.out.println("]"); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo019.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | // # Exo_19 3 | 4 | // Niveau : 7 ⭐ 5 | 6 | // **Exercice** : 7 | 8 | // - Créez un tableau d'entiers de taille 10. Remplissez le de nombres aléatoires entre 0 et 100. 9 | 10 | // - Affichez le 11 | 12 | // - Trier le 13 | // - Le principe est de parcourir le tableau et, pour chaque position i, trouver l'élément minimum parmi les éléments restants (à partir de l'indice i jusqu'à la fin du tableau). 14 | 15 | // - Pour ce faire, une boucle interne compare les éléments du tableau et conserve l'indice de l'élément minimum trouvé. 16 | 17 | // - Ensuite, l'élément minimum est échangé avec l'élément à la position i. Cette opération est répétée pour chaque élément du tableau. 18 | 19 | // - Afficher le tableau trié 20 | 21 | // **Exemple de sortie attendue** : 22 | // ``` 23 | // [54,23,78,4,73,88,43,22,75,77] 24 | // [4,22,23,43,54,73,75,77,78,88] 25 | 26 | // ``` 27 | public class Exo019 { 28 | public static void main(String[] args) { 29 | int[] tableau = new int[10]; 30 | 31 | for(int i = 0; i < tableau.length; i++){ 32 | tableau[i] = (int)(Math.random() * 101); 33 | } 34 | 35 | afficherTableau(tableau); 36 | 37 | 38 | 39 | int minimum; 40 | int indiceMin = 0; 41 | for(int i = 0 ; i < tableau.length ; i++){ 42 | minimum = Integer.MAX_VALUE; 43 | for(int j = i ; j < tableau.length ; j++){ 44 | if(tableau[j] < minimum){ 45 | minimum = tableau[j]; 46 | indiceMin = j; 47 | } 48 | } 49 | tableau[indiceMin] = tableau[i]; 50 | tableau[i] = minimum; 51 | } 52 | afficherTableau(tableau); 53 | } 54 | public static void afficherTableau(int[] tableau){ 55 | System.out.print("["); 56 | for(int i = 0; i < tableau.length-1; i++){ 57 | System.out.print(tableau[i] + ","); 58 | } 59 | System.out.print(tableau[tableau.length-1]); 60 | 61 | System.out.println("]"); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo003.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | //-------------------------------------------------------------------- 3 | // Créer et afficher les variables avec le meilleur type possible 4 | //-------------------------------------------------------------------- 5 | 6 | // Variable contenant l'âge d'une personne 7 | 8 | // Population du cégep Marie-Victorin 9 | 10 | // Variable comptant la population au Qc 11 | 12 | // Variable pour calculer le revenu d'un individu 13 | 14 | // Nombre de gouttes d'eau dans une piscine. 15 | 16 | // Une variable qui se rappelle si le prof était bon ou pas 17 | 18 | // Note en lettre qu'un étudiant obtient au cours 19 | 20 | // Les mois de l'année sous format texte 21 | public class Exo003 { 22 | public static void main(String[] args) { 23 | byte age = 42; 24 | System.out.println("L'âge est une valeur < 128, donc j'utilise un byte : " + age); 25 | 26 | short populationMV = 5000; 27 | System.out.println("La population de Marie-Victorin est plus de 127 individus et moins de 32 768, donc j'utilise un short : " + populationMV); 28 | 29 | float salaire = 1000000.01f; 30 | System.out.println("Un float suffi largement pour le revenu d'un individu : " + salaire); 31 | 32 | int nbGoutteEau = 960_000_000; 33 | System.out.println("Le nombre de goutte d'eau serait dans les alentour de 1_000_000, alors j'utilise un int, si vous voulez être certain d'avoir assez d'espace, un long pourrait être plus adéquat. :" + nbGoutteEau); 34 | 35 | boolean isProfBon = true; 36 | System.out.println("Puisque c'est une variable dichotomique, j'utilise le boolean : " + isProfBon); 37 | 38 | char noteLettre = 'A'; 39 | System.out.println("J'utilise le char pour des lettres seules : " + noteLettre); 40 | 41 | enum mois{ 42 | JANVIER, 43 | FEVRIER, 44 | MARS, 45 | AVRIL, 46 | MAI, 47 | JUIN, 48 | JUILLET, 49 | AOUT, 50 | SEPTEMBRE, 51 | OCTOBRE, 52 | NOVEMBRE, 53 | DECEMBRE 54 | } 55 | 56 | System.out.println("Nous sommes en " + mois.JANVIER); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie3/Cursor.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie3; 2 | 3 | public class Cursor { 4 | public static void main(String[] args) throws InterruptedException { 5 | System.out.print("Hi my dear, I would like to buy a cofe"); 6 | // Wait a little for the output to be visible 7 | Thread.sleep(1000); 8 | 9 | // Move the cursor 12 positions to the left 10 | System.out.print("\033[12D"); // Moves cursor 12 positions left 11 | 12 | // Overwrite the last 12 characters with spaces 13 | System.out.print(" "); 14 | 15 | System.out.print("\033[20C"); // Moves cursor 10 positions to the right 16 | System.out.println("bouh!"); 17 | // Print some initial lines to simulate output 18 | System.out.println("Line 1"); 19 | System.out.println("Line 2"); 20 | System.out.println("Line 3--------------------------------------------"); 21 | 22 | // Wait a little for the output to be visible 23 | Thread.sleep(1000); 24 | 25 | // Move the cursor up one line 26 | System.out.print("\033[A"); // Moves cursor up one line 27 | 28 | // Print a new line after moving the cursor 29 | System.out.print("This is a new line after moving up."); 30 | System.out.print("\033[B\r"); // Moves cursor down one line 31 | 32 | 33 | // Print some initial lines to simulate output 34 | System.out.println("Line 1"); 35 | System.out.println("Line 2"); 36 | System.out.println("Line 3"); 37 | 38 | // Wait a little to let the user see the output 39 | Thread.sleep(1000); 40 | 41 | // Save the cursor position 42 | System.out.print("\033[s"); 43 | 44 | // Move the cursor to another position and print something 45 | System.out.print("\033[10;10H"); // Move the cursor to line 10, column 10 46 | System.out.println("This is at (10, 10)"); 47 | 48 | // Wait a moment to let the new text be visible 49 | Thread.sleep(1000); 50 | 51 | // Restore the cursor position to where it was saved 52 | System.out.print("\033[u"); 53 | 54 | // Print some more lines to show the cursor is back in its original position 55 | System.out.println("Back to the original position."); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/src/main/java/formatif2/question2/MainDiff.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examenFinal.video.src.main.java.formatif2.question2; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | public class MainDiff { 8 | public static void main(String[] args) { 9 | Employe hugo = new Employe("Hugo Chartrand", "Stagiaire", null); 10 | Employe alex = new Employe("Alex Gagnon", "Développeur frontend", new ArrayList<>(Arrays.asList(hugo))); 11 | Employe nadia = new Employe("Nadia Belhumeur", "Développeuse backend", null); 12 | Employe marc = new Employe("Marc Boivin", "Directeur TI", new ArrayList<>(Arrays.asList(nadia,alex))); 13 | Employe kevin = new Employe("Kevin Lemoine", "Designer graphique", null); 14 | Employe sarah = new Employe("Sarah Lefebvre", "Analyste marketing", null); 15 | Employe alice = new Employe("Alice Tremblay", "Directrice Marketing", new ArrayList<>(Arrays.asList(sarah,kevin))); 16 | Employe jean = new Employe("Jean Dupuis", "PDG", new ArrayList<>(Arrays.asList(alice, marc))); 17 | 18 | jean.afficheOrganigramme(0); 19 | } 20 | } 21 | 22 | 23 | class Employe{ 24 | private String nom; 25 | private String poste; 26 | private ArrayList employes; 27 | 28 | 29 | public Employe(String nom, String poste, ArrayList employes) { 30 | this.nom = nom; 31 | this.poste = poste; 32 | this.employes = employes; 33 | } 34 | 35 | 36 | public String getNom() { 37 | return nom; 38 | } 39 | 40 | 41 | public void setNom(String nom) { 42 | this.nom = nom; 43 | } 44 | 45 | 46 | public String getPoste() { 47 | return poste; 48 | } 49 | 50 | 51 | public void setPoste(String poste) { 52 | this.poste = poste; 53 | } 54 | 55 | public void afficheOrganigramme(int indent){ 56 | System.out.println(" ".repeat(indent) + this.toString()); 57 | if(this.employes ==null){ 58 | return; 59 | } 60 | for (Employe employe : employes) { 61 | employe.afficheOrganigramme(indent + 1); 62 | } 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | 68 | return String.format("%s - %s", this.getNom(), this.getPoste()); 69 | } 70 | 71 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie3/Exo5.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie3; 2 | 3 | public class Exo5 { 4 | public static void main(String[] args) { 5 | additionner(7.0, 7.0); 6 | additionner(7, 7); 7 | additionner(7.0, 7); 8 | additionner(7, 7.0); 9 | 10 | } 11 | public static void additionner(double a, double b){System.out.println( a + b + 1);} 12 | public static void additionner(int a, int b){System.out.println( a + b - 1 );} 13 | public static void additionner(double a, int b){System.out.println( a + b + 4);} 14 | public static void additionner(int a, double b){System.out.println( a + b - 6);} 15 | } 16 | 17 | // public static void main(String[] args) { 18 | // Chat[] arrayChats = new Chat[200]; 19 | // Chien[] arrayChiens = new Chien[300]; 20 | 21 | // // for(int i = 0 ; i < 200 ; i++){ 22 | // // arrayChats[i] = new Chat(); 23 | // // } 24 | // for(int i = 0 ; i < 300 ; i++){ 25 | // arrayChiens[i] = new Chien(); 26 | 27 | // } 28 | 29 | // Animal[] arrayAnimaux = new Animal[500]; 30 | 31 | // for(int i = 0 ; i < 200 ; i++){ 32 | // arrayAnimaux[i] = new Chat(); 33 | // } 34 | // for(int i = 200 ; i < 500 ; i++){ 35 | // arrayAnimaux[i] = arrayChiens[i - 200]; 36 | 37 | // } 38 | // int somme = 0; 39 | // for( Animal ani : arrayAnimaux){ 40 | // ani.parler(); 41 | // somme += ani.getAge(); 42 | // } 43 | 44 | // System.out.println(somme / arrayAnimaux.length); 45 | 46 | // } 47 | // } 48 | 49 | // class Animal{ 50 | // protected int age; 51 | 52 | // public Animal(){ 53 | 54 | // } 55 | // public int getAge(){ 56 | // return age; 57 | // } 58 | 59 | // public void parler(){ 60 | // System.out.println(""); 61 | // } 62 | 63 | // } 64 | 65 | // class Chien extends Animal{ 66 | // public Chien(){ 67 | // super(); 68 | // this.age = (int)(Math.random() * 11); 69 | // } 70 | // @Override 71 | // public void parler(){ 72 | // System.out.println("Woof"); 73 | // } 74 | // } 75 | // class Chat extends Animal{ 76 | // public Chat(){ 77 | // super(); 78 | // this.age = (int)(Math.random() * 21); 79 | // } 80 | // @Override 81 | // public void parler(){ 82 | // System.out.println("Miaou"); 83 | // } 84 | // } 85 | 86 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen2/question3/Main.java: -------------------------------------------------------------------------------- 1 | package question3; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | // Création d'un vendeur en magasin 6 | Vendeur vendeur = new Vendeur("Jean Dupont", 1500, 0.05, 10000); 7 | 8 | System.out.println(vendeur); 9 | 10 | // Création d'un vendeur en ligne 11 | VendeurEnLigne vendeurEnLigne = new VendeurEnLigne("Marie Dubois", 1200, 0.008, 50000, 1500); 12 | 13 | 14 | System.out.println(vendeurEnLigne); 15 | } 16 | } 17 | 18 | //2 19 | class Vendeur{ 20 | //4 21 | protected String nom; 22 | protected double salaireDeBase; 23 | protected double tauxCommission; 24 | protected double montantTotalDesVentes; 25 | 26 | //3 27 | public Vendeur(String nom, double salaireDeBase, double tauxCommission, double montantTotalDesVentes){ 28 | this.nom = nom; 29 | this.salaireDeBase = salaireDeBase; 30 | this.tauxCommission = tauxCommission; 31 | this.montantTotalDesVentes = montantTotalDesVentes; 32 | } 33 | 34 | //3 35 | @Override 36 | public String toString(){ 37 | String msg = "Nom : " + this.nom + "\n" + 38 | "Salaire de base : " + String.format("%.2f",this.salaireDeBase) + " €\n" + 39 | "Total des commissions: " + String.format("%.2f",(this.montantTotalDesVentes * this.tauxCommission)) + " €\n" + 40 | "Salaire total: " + String.format("%.2f",(this.montantTotalDesVentes * this.tauxCommission + this.salaireDeBase)) + " €\n"; 41 | return msg; 42 | } 43 | } 44 | 45 | //3 46 | class VendeurEnLigne extends Vendeur{ 47 | //1 48 | private int nbClics; 49 | 50 | //4 51 | public VendeurEnLigne(String nom, double salaireDeBase, double tauxCommission, double montantTotalDesVentes, int nbClics){ 52 | super(nom, salaireDeBase, tauxCommission, montantTotalDesVentes); 53 | this.nbClics = nbClics; 54 | 55 | } 56 | 57 | //5 58 | @Override 59 | public String toString(){ 60 | String msg = "Nom : " + this.nom + "\n" + 61 | "Salaire de base : " + String.format("%.2f",this.salaireDeBase) + " €\n" + 62 | "Total des commissions: " + String.format("%.2f",(this.montantTotalDesVentes * this.tauxCommission + this.nbClics * 0.5)) + " €\n" + 63 | "Salaire total: " + String.format("%.2f",(this.montantTotalDesVentes * this.tauxCommission + this.nbClics * 0.5 + this.salaireDeBase)) + " €\n"; 64 | return msg; 65 | } 66 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo013v3.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | // Niveau : 6 ⭐ 3 | 4 | // **Exercice** : 5 | 6 | // - Supprimer les doublons du tableau suivant en supposant que vous ne savez pas d'avance les valeur dans le tableau: `[5,1,2,2,1,4,5,6,6,7,8]`. 7 | // - Affichez le nouveau tableau 8 | // **Exemple de sortie attendue** : 9 | // ``` 10 | // [5,1,2,4,6,7,8] 11 | // ``` 12 | public class Exo013v3 { 13 | public static void main(String[] args) { 14 | int[] tableau = new int[10000]; 15 | 16 | for(int i = 0; i < tableau.length; i++){ 17 | tableau[i] = (int)(Math.random() * 1000); 18 | } 19 | 20 | afficherTableau(tableau); 21 | 22 | quickSort(tableau, 0, tableau.length-1); 23 | 24 | afficherTableau(tableau); 25 | 26 | int nbDoublons = 0; 27 | for(int i = 1 ; i < tableau.length; i++){ 28 | if(tableau[i] == tableau[i-1]){ 29 | nbDoublons += 1; 30 | } 31 | } 32 | int[] tableauSansDoublon = new int[tableau.length - nbDoublons]; 33 | 34 | tableauSansDoublon[0] = tableau[0]; 35 | int k = 1; 36 | for(int i = 1; i < tableau.length; i++){ 37 | if(tableau[i] != tableau[i-1]){ 38 | tableauSansDoublon[k] = tableau[i]; 39 | k += 1; 40 | } 41 | } 42 | tableau = tableauSansDoublon; 43 | afficherTableau(tableau); 44 | 45 | } 46 | public static void afficherTableau(int[] tableau){ 47 | System.out.print("["); 48 | for(int i = 0; i < tableau.length-1; i++){ 49 | System.out.print(tableau[i] + ","); 50 | } 51 | System.out.print(tableau[tableau.length-1]); 52 | 53 | System.out.println("]"); 54 | } 55 | public static void quickSort(int[] tableau, int start, int end){ 56 | int indicePivot = end; 57 | int mem = 0; 58 | for(int i = end - 1 ; i >= start ; i--){ 59 | if(tableau[i] < tableau[indicePivot]){ 60 | ; 61 | } 62 | else{ 63 | mem = tableau[i]; 64 | tableau[i] = tableau[indicePivot - 1]; 65 | tableau[indicePivot - 1] = tableau[indicePivot]; 66 | tableau[indicePivot] = mem; 67 | indicePivot--; 68 | } 69 | } 70 | if(indicePivot > 1){ 71 | quickSort(tableau, start, indicePivot-1); 72 | } 73 | if(indicePivot + 1() { 17 | @Override 18 | public int compare(Animal animal1, Animal animal2) { 19 | return animal1.getAge() - animal2.getAge(); 20 | } 21 | }); 22 | 23 | for( Animal animal : ferme){ 24 | System.out.println(animal.parole()); 25 | } 26 | 27 | } 28 | 29 | } 30 | class Animal{ 31 | String nom; 32 | int age; 33 | 34 | 35 | public String getNom() { 36 | return nom; 37 | } 38 | 39 | public int getAge() { 40 | return age; 41 | } 42 | 43 | public Animal(String nom, int age) { 44 | this.nom = nom; 45 | this.age = age; 46 | } 47 | public String parole(){ 48 | return ""; 49 | } 50 | } 51 | 52 | class Chien extends Animal{ 53 | 54 | public Chien(String nom, int age) { 55 | super(nom, age); 56 | } 57 | 58 | @Override 59 | public String parole(){ 60 | return "Woof"; 61 | } 62 | 63 | } 64 | 65 | class Chat extends Animal{ 66 | 67 | public Chat(String nom, int age) { 68 | super(nom, age); 69 | } 70 | 71 | @Override 72 | public String parole(){ 73 | return "Meow!"; 74 | } 75 | 76 | } 77 | class Poule extends Animal{ 78 | 79 | public Poule(String nom, int age) { 80 | super(nom, age); 81 | } 82 | 83 | @Override 84 | public String parole(){ 85 | return "Bekayyy"; 86 | } 87 | 88 | } 89 | 90 | class Vache extends Animal{ 91 | 92 | public Vache(String nom, int age) { 93 | super(nom, age); 94 | } 95 | 96 | @Override 97 | public String parole(){ 98 | return "Meeuuuuuu"; 99 | } 100 | 101 | } 102 | 103 | class Mouton extends Animal{ 104 | 105 | public Mouton(String nom, int age) { 106 | super(nom, age); 107 | } 108 | 109 | @Override 110 | public String parole(){ 111 | return "Behehehehehe"; 112 | } 113 | 114 | } 115 | 116 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Exo030.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie2; 2 | 3 | 4 | import java.util.Scanner; 5 | import java.util.ArrayList; 6 | public class Exo030{ 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | ArrayList facture = new ArrayList<>(); 10 | 11 | 12 | String[] plats = {"Crevette", "Salade", "Frite", "Hamburger", "Gâteau"}; 13 | float[] prix = {8.99f, 5.60f, 6.40f, 10.99f, 7.99f}; 14 | while(true){ 15 | System.out.println(""); 16 | 17 | System.out.println("1. Ajouter un item"); 18 | System.out.println("2. Retirer un item"); 19 | System.out.println("3. Afficher le reçu"); 20 | System.out.println("4. Terminer la transaction"); 21 | String choix = scanner.nextLine(); 22 | System.out.println("Vous avez choisi : " + choix); 23 | System.out.println("Appuyer sur enter pour continuer"); 24 | System.out.println(""); 25 | if(choix.equals("1")){ 26 | for(int i = 0 ; i < plats.length ; i++){ 27 | System.out.printf("%d. %-14s%10.02f$\n",(i+1) , plats[i], prix[i]); 28 | } 29 | 30 | System.out.print("Entrez le numéro de l'item : "); 31 | choix = scanner.nextLine(); 32 | facture.add(plats[Integer.parseInt(choix) - 1]); 33 | } 34 | else if(choix.equals("2")){ 35 | 36 | afficherReçu(facture, prix); 37 | 38 | System.out.print("Quel item voulez-vous retirer : "); 39 | choix = scanner.nextLine(); 40 | facture.remove(Integer.parseInt(choix)); 41 | } 42 | else if(choix.equals("3")){ 43 | afficherReçu(facture, prix); 44 | } 45 | else if(choix.equals("4")){ 46 | afficherReçu(facture, prix); 47 | System.out.println(); 48 | System.out.println("Merci pour votre visite!"); 49 | break; 50 | } 51 | scanner.nextLine(); 52 | } 53 | } 54 | public static void afficherReçu(ArrayList facture, float[] prix){ 55 | double total = 0; 56 | for(int i = 0 ; i < facture.size() ; i++){ 57 | total += prix[i]; 58 | String prixFormatter = String.format("%.02f$", prix[i]); 59 | System.out.printf("%d. %-13s%10.02f$\n",(i+1) , facture.get(i), prix[i]); 60 | } 61 | System.out.println("-".repeat(27)); 62 | System.out.printf("%-16s%10.2f$\n","Total", total); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Exo003.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie2; 2 | class CompteBancaire { 3 | //Attributs 4 | private String titulaire; 5 | private double solde; 6 | 7 | //Getter & Setter 8 | public String getTitulaire() { 9 | return titulaire; 10 | } 11 | 12 | public void setTitulaire(String titulaire) { 13 | this.titulaire = titulaire; 14 | } 15 | 16 | public double getSolde() { 17 | return this.solde; 18 | } 19 | 20 | public void setSolde(double solde) { 21 | this.solde = solde; 22 | } 23 | 24 | // Constructeur 25 | public CompteBancaire(String titulaire, double solde) { 26 | this.titulaire = titulaire; 27 | this.solde = solde; 28 | } 29 | 30 | // Méthodes 31 | public void deposer(double montant) { 32 | if (montant > 0) { 33 | this.solde += montant; 34 | System.out.println("Montant déposé : " + montant + "€"); 35 | } else { 36 | System.out.println("Le montant à déposer doit être positif."); 37 | } 38 | } 39 | 40 | public void retirer(double montant) { 41 | if (montant > 0 && montant <= this.solde) { 42 | this.solde -= montant; 43 | System.out.println("Montant retiré : " + montant + "€"); 44 | } else if (montant > this.solde) { 45 | System.out.println("Solde insuffisant. Retrait impossible."); 46 | } else { 47 | System.out.println("Le montant à retirer doit être positif."); 48 | } 49 | } 50 | 51 | public void afficherSolde() { 52 | System.out.println("Solde actuel : " + this.solde + "€"); 53 | } 54 | 55 | public void afficherInfo() { 56 | System.out.println("Titulaire : " + this.titulaire + ", Solde : " + this.solde + "€"); 57 | } 58 | // 59 | } 60 | 61 | public class Exo003 { 62 | public static void main(String[] args) { 63 | // Création de plusieurs instances de la classe CompteBancaire 64 | CompteBancaire compte1 = new CompteBancaire("Alice", 1000); 65 | CompteBancaire compte2 = new CompteBancaire("Bob", 500); 66 | 67 | // Effectuer des dépôts 68 | compte1.deposer(200); // Déposer 200€ sur le compte d'Alice 69 | compte2.deposer(50); // Déposer 50€ sur le compte de Bob 70 | 71 | // Effectuer des retraits 72 | compte1.retirer(300); // Retirer 300€ du compte d'Alice 73 | compte2.retirer(600); // Essayer de retirer 600€, mais solde insuffisant 74 | 75 | // Afficher les résultats 76 | compte1.afficherInfo(); // Afficher les informations du compte d'Alice 77 | compte2.afficherInfo(); // Afficher les informations du compte de Bob 78 | } 79 | } 80 | 81 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/video/src/main/java/formatif2/question2/Main.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examenFinal.video.src.main.java.formatif2.question2; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | 8 | Employe jean = new Employe("Jean Dupuis", "PDG", 0); 9 | Employe alice = new Employe("Alice Tremblay", "Directrice Marketing", 1); 10 | Employe sarah = new Employe("Sarah Lefebvre", "Analyste marketing", 2); 11 | Employe kevin = new Employe("Kevin Lemoine", "Designer graphique", 2); 12 | Employe marc = new Employe("Marc Boivin", "Directeur TI", 1); 13 | Employe nadia = new Employe("Nadia Belhumeur", "Développeuse backend", 2); 14 | Employe alex = new Employe("Alex Gagnon", "Développeur frontend", 2); 15 | Employe hugo = new Employe("Hugo Chartrand", "Stagiaire", 3); 16 | 17 | Entreprise enterprise = new Entreprise(); 18 | 19 | enterprise.ajouterEmployeALaFin(jean); 20 | enterprise.ajouterEmployeALaFin(alice); 21 | enterprise.ajouterEmployeALaFin(sarah); 22 | enterprise.ajouterEmployeALaFin(kevin); 23 | enterprise.ajouterEmployeALaFin(marc); 24 | enterprise.ajouterEmployeALaFin(nadia); 25 | enterprise.ajouterEmployeALaFin(alex); 26 | enterprise.ajouterEmployeALaFin(hugo); 27 | 28 | enterprise.afficheOrganigramme(); 29 | } 30 | } 31 | 32 | class Entreprise{ 33 | private ArrayList employes = new ArrayList<>(); 34 | 35 | public void ajouterEmployeALaFin(Employe emp){ 36 | employes.add(emp); 37 | } 38 | 39 | public void afficheOrganigramme(){ 40 | for (Employe employe : employes) { 41 | System.out.println(employe); 42 | } 43 | } 44 | } 45 | 46 | class Employe{ 47 | private String nom; 48 | private String poste; 49 | private int nbIndent; 50 | 51 | public Employe(String nom, String poste, int nbIndent) { 52 | this.nom = nom; 53 | this.poste = poste; 54 | this.nbIndent = nbIndent; 55 | } 56 | public String getNom() { 57 | return nom; 58 | } 59 | public void setNom(String nom) { 60 | this.nom = nom; 61 | } 62 | public String getPoste() { 63 | return poste; 64 | } 65 | public void setPoste(String poste) { 66 | this.poste = poste; 67 | } 68 | public int getNbIndent() { 69 | return nbIndent; 70 | } 71 | public void setNbIndent(int nbIndent) { 72 | this.nbIndent = nbIndent; 73 | } 74 | @Override 75 | public String toString() { 76 | return String.format(" ".repeat(nbIndent) + "%s - %s", this.getNom(), this.getPoste()); 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie3/Exo6.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie3; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.HashMap; 6 | 7 | public class Exo6 { 8 | public static void main(String[] args) { 9 | ArrayList liste = new ArrayList<>(); 10 | liste.add(new Cercle(new HashMap() {{ put(Dimensions.RAYON, 4.5);}})); 11 | liste.add(new Triangle(new HashMap() {{ put(Dimensions.BASE, 4.0);put(Dimensions.HAUTEUR, 5.0);}})); 12 | liste.add(new Rectangle(new HashMap() {{ put(Dimensions.BASE, 4.0);put(Dimensions.HAUTEUR, 5.0);}})); 13 | liste.add(new Cercle(new HashMap() {{ put(Dimensions.RAYON, 8.0);}})); 14 | 15 | afficherAire(liste); 16 | 17 | System.out.println(); 18 | 19 | Collections.sort(liste, (forme1, forme2) -> Double.compare(forme1.getArea(), forme2.getArea())); 20 | 21 | afficherAire(liste); 22 | } 23 | public static void afficherAire(ArrayList liste){ 24 | for( Forme forme : liste){ 25 | System.out.println(forme.getArea()); 26 | } 27 | } 28 | } 29 | 30 | 31 | enum Dimensions { 32 | BASE, 33 | HAUTEUR, 34 | RAYON 35 | } 36 | class Forme { 37 | 38 | HashMap dimensions = new HashMap<>(); 39 | 40 | 41 | public HashMap getDimensions() { 42 | return dimensions; 43 | } 44 | 45 | public void setDimensions(HashMap dimensions) { 46 | this.setDimensions(dimensions); 47 | } 48 | 49 | public Forme(HashMap dimensions) { 50 | this.dimensions = dimensions; 51 | } 52 | 53 | public double getArea(){ 54 | return 0; 55 | }; 56 | } 57 | 58 | class Triangle extends Forme{ 59 | public Triangle(HashMap dimensions){ 60 | super(dimensions); 61 | } 62 | 63 | @Override 64 | public double getArea(){ 65 | return (getDimensions().get(Dimensions.BASE) * getDimensions().get(Dimensions.HAUTEUR)) / 2; 66 | } 67 | } 68 | 69 | class Rectangle extends Forme{ 70 | public Rectangle(HashMap dimensions){ 71 | super(dimensions); 72 | } 73 | 74 | @Override 75 | public double getArea(){ 76 | return getDimensions().get(Dimensions.BASE) * getDimensions().get(Dimensions.HAUTEUR); 77 | } 78 | } 79 | 80 | class Cercle extends Forme{ 81 | public Cercle(HashMap dimensions){ 82 | super(dimensions); 83 | } 84 | 85 | @Override 86 | public double getArea(){ 87 | return Math.PI * Math.pow(getDimensions().get(Dimensions.RAYON),2); 88 | } 89 | } 90 | 91 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen1/formatif/ToDoList.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examen1.formatif; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Scanner; 5 | public class ToDoList { 6 | public static String repetition(String mot, int nombre){ 7 | String somme = ""; 8 | for( int i = 0; i < nombre; i++){ 9 | somme += mot; 10 | } 11 | return somme; 12 | } 13 | 14 | public static void main(String[] args) { 15 | Scanner scanner = new Scanner(System.in); 16 | ArrayList taches = new ArrayList(); 17 | ArrayList isDone = new ArrayList(); 18 | String choix; 19 | while(true){ 20 | System.out.println("1.Ajouter une tâche"); 21 | System.out.println("2.Marquer une tâche comme terminée"); 22 | System.out.println("3.Afficher les tâches"); 23 | System.out.println("4.Terminer le programme"); 24 | System.out.println("-".repeat(40)); 25 | System.out.println("Nombre de tâche : " + taches.size()); 26 | System.out.println("-".repeat(60) + "\n"); 27 | 28 | 29 | System.out.print("Entrez votre choix : "); 30 | choix = scanner.nextLine(); 31 | 32 | if(choix.equals("1")){ 33 | System.out.print("Entrez la tâche à ajouter : "); 34 | choix = scanner.nextLine(); 35 | 36 | taches.add(choix); 37 | isDone.add(false); 38 | System.out.println("Tâche ajoutée : " + choix); 39 | } 40 | else if(choix.equals("2")){ 41 | System.out.print("Entrez le numéro de la tâche à marquer comme terminée : "); 42 | choix = scanner.nextLine(); 43 | isDone.set(Integer.parseInt(choix),true); 44 | System.out.println("Tâche terminée : " + taches.get(Integer.parseInt(choix))); 45 | } 46 | else if(choix.equals("3")){ 47 | afficherTaches(taches, isDone); 48 | } 49 | else if(choix.equals("4")){ 50 | afficherTaches(taches, isDone); 51 | System.out.println("\nMerci d'avoir utilisé le gestionnaire de tâches!"); 52 | break; 53 | } 54 | scanner.nextLine(); 55 | 56 | 57 | System.out.println("\n" + "-".repeat(60) + "\n"); 58 | 59 | } 60 | } 61 | public static void afficherTaches(ArrayList taches, ArrayList isDone){ 62 | System.out.println("\n\nTâches : \n"); 63 | for(int i = 0; i < taches.size(); i++){ 64 | System.out.printf("%d.%s %s\n",i ,taches.get(i) , isDone.get(i) ? " (Complété)" : " (Non complété)"); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen2/formatif/question1/Etudiant.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examen2.formatif.question1; 2 | 3 | public class Etudiant { 4 | private int da; 5 | private String nomComplet; 6 | private Evaluation[] evaluations = { 7 | new Evaluation("Examen 1", 0.2f), 8 | new Evaluation("Examen 2", 0.3f), 9 | new Evaluation("Examen Final", 0.5f) 10 | }; 11 | public void setDa(int da){ 12 | this.da = da; 13 | } 14 | public int getDa(){ 15 | return this.da; 16 | } 17 | public void setNomComplet(String nomComplet){ 18 | this.nomComplet = nomComplet; 19 | } 20 | 21 | public String getNomComplet(){ 22 | return this.nomComplet; 23 | } 24 | public Evaluation getEvaluation(int index){ 25 | return this.evaluations[index]; 26 | } 27 | 28 | public int getNbEvaluations(){ 29 | return this.evaluations.length; 30 | } 31 | public Etudiant(int da, String nomComplet){ 32 | this.setDa(da); 33 | this.setNomComplet(nomComplet); 34 | } 35 | 36 | public byte noteFinale(){ 37 | byte somme = 0; 38 | for(int i = 0; i < this.evaluations.length; i++){ 39 | somme += this.getEvaluation(i).notePonderee(); 40 | } 41 | return somme; 42 | } 43 | 44 | 45 | public void afficheResultat(){ 46 | System.out.printf("%d %-15s %2d %2d %2d | %2d\n", 47 | this.da, 48 | this.nomComplet, 49 | this.getEvaluation(0).notePonderee(), 50 | this.getEvaluation(1).notePonderee(), 51 | this.getEvaluation(2).notePonderee(), 52 | this.noteFinale() 53 | ); 54 | } 55 | 56 | 57 | public static void main(String[] args) { 58 | // Créer un étudiant 59 | Etudiant etudiant = new Etudiant(1234567, "Jean Dupont"); 60 | 61 | // Définir les notes obtenues pour chaque examen 62 | etudiant.getEvaluation(0).setNoteSur100((byte)80); // Examen 1 63 | 64 | etudiant.getEvaluation(1).setNoteSur100((byte)90); // Examen 2 65 | 66 | etudiant.getEvaluation(2).setNoteSur100((byte)75); // Examen Final 67 | 68 | 69 | // Afficher les résultats 70 | etudiant.afficheResultat(); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Exo019.java: -------------------------------------------------------------------------------- 1 | // package solution_exo.serie2; 2 | // class CompteBancaire { 3 | // String titulaire; // 4 | // double solde // 1 5 | 6 | // // Constructeur pour initialiser le titulaire et le solde 7 | // public CompteBancaire(Byte titulaire, double solde) { //2 8 | // this.titulaire = titulaire; 9 | // this.solde; //3 10 | // } 11 | 12 | // // Méthode pour déposer un montant sur le compte 13 | // public void deposer(double montant) { 14 | // if (montant > 0) { 15 | // solde = montant; //4 16 | // System.out.println("Montant déposé : " + montant + "€"); 17 | // } else { 18 | // System.println("Le montant à déposer doit être positif."); //5 19 | // } 20 | // } 21 | 22 | // // Méthode pour retirer un montant du compte 23 | // public static void retirer(double montant) {//6 24 | // if (montant > 0 && montant <= solde) { 25 | // solde -= montant; 26 | // System.out.println("Montant retiré : " + montant + "€"); 27 | // } else if (montant < solde) { //7 28 | // System.out.println("Solde insuffisant. Retrait impossible."); 29 | // } else { 30 | // System.out.println("Le montant à retirer doit être positif."); 31 | // } 32 | // } 33 | 34 | // // Méthode pour afficher le solde du compte 35 | // public void afficherSolde() { 36 | // System.out.println("Solde actuel : " solde "€");//7 37 | // } 38 | 39 | // // Méthode pour afficher les informations du titulaire et son solde 40 | // public void afficherInfo() { 41 | // System.out.println("Titulaire : " + titulaire + ", Solde : " + solde + "€"); 42 | // } 43 | // } 44 | // //8 this. 45 | 46 | 47 | // /* 48 | // * Il n'y a pas d'erreur dans la partie ci-dessous 49 | // * 50 | // */ 51 | // public class Exo019 { 52 | // public static void main(String[] args) { 53 | // // Création de plusieurs instances de la classe CompteBancaire 54 | // CompteBancaire compte1 = new CompteBancaire("Alice", 1000); 55 | // CompteBancaire compte2 = new CompteBancaire("Bob", 500); 56 | 57 | // // Effectuer des dépôts 58 | // compte1.deposer(200); // Déposer 200€ sur le compte d'Alice 59 | // compte2.deposer(50); // Déposer 50€ sur le compte de Bob 60 | 61 | // // Effectuer des retraits 62 | // compte1.retirer(300); // Retirer 300€ du compte d'Alice 63 | // compte2.retirer(600); // Essayer de retirer 600€, mais solde insuffisant 64 | 65 | // // Afficher les résultats 66 | // compte1.afficherInfo(); // Afficher les informations du compte d'Alice 67 | // compte2.afficherInfo(); // Afficher les informations du compte de Bob 68 | // } 69 | // } 70 | 71 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen1/formatif/ToDoListV2.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examen1.formatif; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Scanner; 5 | public class ToDoListV2 { 6 | public static void main(String[] args) { 7 | ArrayList taches = new ArrayList<>(); 8 | ArrayList isDone = new ArrayList<>(); 9 | Scanner scanner = new Scanner(System.in); 10 | String choix; 11 | while(true){ 12 | System.out.println(); 13 | System.out.println("-".repeat(60)); 14 | System.out.println("\nMenu : "); 15 | System.out.println("1.Ajouter une tâche"); 16 | System.out.println("2.Marquer une tâche comme terminée"); 17 | System.out.println("3.Afficher les tâches"); 18 | System.out.println("4.Terminer le programme"); 19 | System.out.println(repeat("-",40)); 20 | System.out.println("Nombre de tâche : " + taches.size()); 21 | System.out.println("-".repeat(60) + "\n"); 22 | 23 | System.out.print("Entrez votre choix : "); 24 | choix = scanner.nextLine(); 25 | 26 | if(choix.equals("1")){ 27 | System.out.print("Entrez la tâche à ajouter : "); 28 | choix = scanner.nextLine(); 29 | taches.add(choix); 30 | isDone.add(false); 31 | System.out.printf("Tâche ajoutée : %s\n", choix); 32 | } 33 | else if(choix.equals("2")){ 34 | System.out.print("Entrez le numéro de la tâche à marquer comme terminée : "); 35 | choix = scanner.nextLine(); 36 | isDone.set(Integer.parseInt(choix) - 1 , true); 37 | System.out.printf("Tâche terminée : %s\n", taches.get(Integer.parseInt(choix) - 1)); 38 | } 39 | else if(choix.equals("3")){ 40 | afficheTableau(taches, isDone); 41 | } 42 | else if(choix.equals("4")){ 43 | afficheTableau(taches, isDone); 44 | 45 | System.out.println("Merci d'avoir utilisé le gestionnaire de tâches! "); 46 | break; 47 | } 48 | scanner.nextLine(); 49 | 50 | 51 | } 52 | } 53 | public static void afficheTableau(ArrayList taches, ArrayList isDone){ 54 | String statut; 55 | for(int i = 0 ; i < taches.size() ; i++){ 56 | statut = isDone.get(i) ? "Terminée" : "Non Terminée"; 57 | System.out.printf("%d.%s (%s)\n",i+1 , taches.get(i), statut); 58 | } 59 | } 60 | public static String repeat(String mot, int nombreRepetition){ 61 | String somme = ""; 62 | for(int i = 0 ; i < nombreRepetition ; i++){ 63 | somme = somme.concat(mot); 64 | } 65 | return somme; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie1/Exo022.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie1; 2 | // Niveau : 5 ⭐ si vous respectez le format de la réponse 3 | // Niveau : 3 ⭐ sinon 4 | 5 | // Ajoutez à la classe calculatrice : Ajouter un méthode pour afficher un reçu en prenant en paramètre le nom de l'item, le prix, le rabais, le taux de taxation. 6 | 7 | // **Exemple de sortie attendue** : 8 | // ``` 9 | // xbox 500.00$ 10 | // rabais(20%) -100.00$ 11 | // prix avant taxes 400.00$ 12 | // taxe(16%) 64.00$ 13 | // ------------------------------ 14 | // Total 464.00$ 15 | 16 | 17 | public class Exo022 { 18 | // Déclaration d'une constante pour le taux de taxe 19 | public static final double TAUX_DE_TAXE = 0.70; 20 | 21 | // Méthode principale qui sera exécutée lors du lancement du programme 22 | public static void main(String[] args) { 23 | // Déclaration de variables locales 24 | double prixInitial = 100.0; // Prix initial d'un produit 25 | double prixFinal = calculerPrixAvecTaxe(prixInitial); // Calcul du prix après taxe 26 | 27 | // Affichage du résultat 28 | System.out.println("Prix initial : " + prixInitial + "€"); 29 | System.out.println("Prix final après application de la taxe : " + prixFinal + "€"); 30 | 31 | System.out.printf("Le rabais est de %d%% sur %.2f$ est de %.2f$\n",20,prixInitial, calculerRabaisPrix(0.2, prixInitial)); 32 | recu("xbox", 500, 0.2, 0.16); 33 | } 34 | 35 | // Méthode pour calculer le prix final avec taxe 36 | // Cette méthode prend le prix initial comme paramètre et retourne le prix après ajout de la taxe 37 | public static double calculerPrixAvecTaxe(double prix) { 38 | // Calcul du prix final en ajoutant la taxe 39 | double taxe = prix * TAUX_DE_TAXE; // Calcul de la taxe 40 | double prixAvecTaxe = prix + taxe; // Calcul du prix total avec taxe 41 | 42 | return prixAvecTaxe; // Retourne le prix final 43 | } 44 | public static double calculerRabaisPrix(double rabais, double prix){ 45 | return rabais * prix; 46 | } 47 | public static void recu(String nom, double prix, double rabais, double tauxTaxe){ 48 | 49 | afficheLigneRecu(nom, false, prix); 50 | afficheLigneRecu(String.format("rabais(%.0f%%)",rabais*100), true, prix * rabais); 51 | afficheLigneRecu("Prix avant taxes", false, prix * (1 - rabais)); 52 | afficheLigneRecu(String.format("taxes(%.0f%%)",tauxTaxe * 100), false, prix * (1 - rabais) * tauxTaxe); 53 | System.out.println("-".repeat(30)); 54 | afficheLigneRecu("Total", false, prix * (1 - rabais) * (1 + tauxTaxe)); 55 | System.out.println(); 56 | } 57 | public static void afficheLigneRecu(String nom, boolean isNeg, double prix){ 58 | String prixFormat = String.format("%.2f$",prix); 59 | System.out.println(nom + " ".repeat(30 - nom.length() - prixFormat.length()) + prixFormat); 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen2/question1/Personne.java: -------------------------------------------------------------------------------- 1 | package question1; 2 | import java.time.LocalDate; 3 | public class Personne { 4 | 5 | //2, indent 6 | //2 7 | private String nom = "Inconnu"; 8 | private String ville = "Non renseignée"; 9 | private String dateNaissance = "0000-00-00"; 10 | 11 | //1 12 | public void setNom(String nom){ 13 | this.nom = nom; 14 | } 15 | 16 | //1 17 | public String getNom(){ 18 | return this.nom; 19 | } 20 | 21 | //5 22 | public int getAge(){ 23 | LocalDate auj = LocalDate.now(); 24 | String[] dateSplit = dateNaissance.split("-"); 25 | 26 | LocalDate dateNais = LocalDate.of(Integer.parseInt(dateSplit[0]), Integer.parseInt(dateSplit[1]),Integer.parseInt(dateSplit[2])); 27 | 28 | return auj.getYear() - dateNais.getYear() - ((dateNais.getDayOfYear() > auj.getDayOfYear()) ? 1 : 0); 29 | 30 | } 31 | //1 32 | public void setVille(String ville){ 33 | this.ville = ville; 34 | } 35 | //1 36 | public String getVille(){ 37 | return this.ville; 38 | } 39 | //10 40 | public void setDateNaissance(String dateNaissance){ 41 | String[] dateSplit = dateNaissance.split("-"); 42 | LocalDate auj = LocalDate.now(); 43 | LocalDate dateNais; 44 | try{ 45 | if(dateSplit.length !=3 || dateSplit[0].length() != 4 || dateSplit[1].length() != 2 || dateSplit[2].length() != 2){ 46 | throw new IllegalArgumentException(); 47 | } 48 | dateNais = LocalDate.of(Integer.parseInt(dateSplit[0]), Integer.parseInt(dateSplit[1]),Integer.parseInt(dateSplit[2])); 49 | } 50 | catch(Exception e){ 51 | System.err.println("Format de la date incorrecte"); 52 | return; 53 | } 54 | if(auj.compareTo(dateNais) < 0){ 55 | System.err.println("La date de naissance est dans le futur..."); 56 | return; 57 | } 58 | this.dateNaissance = dateNaissance; 59 | 60 | } 61 | //2 62 | public String getDateNaissance(){ 63 | return this.dateNaissance; 64 | } 65 | 66 | //3 67 | public Personne(String nom, String ville, String dateNaissance){ 68 | this.setNom(nom); 69 | this.setVille(ville); 70 | this.setDateNaissance(dateNaissance); 71 | } 72 | 73 | //4 74 | public String sePresenter(){ 75 | return String.format("Je m'appelle %s et j'ai %d ans.", this.getNom(), this.getAge()); 76 | } 77 | //3 78 | public static boolean compare(Personne personne1, Personne personne2){ 79 | return (personne1.getNom().equals(personne2.getNom()) && personne1.getVille().equals(personne2.getVille())); 80 | } 81 | public static void main(String[] args) { 82 | Personne bob = new Personne("Bob", "Chicoutimi", "1997-04-20"); 83 | System.out.println(bob.getAge()); 84 | //27 85 | System.out.println(bob.sePresenter()); 86 | // Je m'appelle Bob et j'ai 27 ans 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/src/main/java/question2/otherVersions/Main2.java: -------------------------------------------------------------------------------- 1 | package question2; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Main2 { 6 | public static void main(String[] args) { 7 | Document cv = new Document("CV.pdf", 300); 8 | Document budget = new Document("budget.xlsx", 150); 9 | Document montagne = new Document("montagne.pdf", 450000); 10 | Document plage = new Document("plage.png", 500000); 11 | Dossier photoVacances = new Dossier("PhotosVacances"); 12 | photoVacances.ajouterFichier(plage); 13 | photoVacances.ajouterFichier(montagne); 14 | Dossier personnel = new Dossier("Personnel"); 15 | personnel.ajouterFichier(photoVacances); 16 | personnel.ajouterFichier(budget); 17 | Document presentation = new Document("presentation.pptx",850); 18 | Document rapport = new Document("rapport.docs", 1200); 19 | Document readMe = new Document("README.md", 300); 20 | Dossier projetJava = new Dossier("ProjetJava"); 21 | projetJava.ajouterFichier(readMe); 22 | projetJava.ajouterFichier(rapport); 23 | Dossier projets = new Dossier("Projets"); 24 | projets.ajouterFichier(projetJava); 25 | projets.ajouterFichier(presentation); 26 | Dossier documents = new Dossier("Documents"); 27 | documents.ajouterFichier(projets); 28 | documents.ajouterFichier(personnel); 29 | documents.ajouterFichier(cv); 30 | 31 | documents.affiche(0); 32 | } 33 | } 34 | abstract class Fichier{ 35 | private String nom; 36 | 37 | 38 | public Fichier(String nom) { 39 | this.nom = nom; 40 | } 41 | 42 | public void affiche(int indent) { 43 | System.out.printf("%-60s%30d octets\n"," ".repeat(indent) + this.getNom(), this.getTaille()); 44 | } 45 | 46 | abstract int getTaille(); 47 | 48 | public String getNom() { 49 | return nom; 50 | } 51 | 52 | public void setNom(String nom) { 53 | this.nom = nom; 54 | } 55 | } 56 | 57 | 58 | class Document extends Fichier{ 59 | private int taille; 60 | 61 | public Document(String nom, int taille) { 62 | super(nom); 63 | this.taille = taille; 64 | } 65 | 66 | 67 | 68 | @Override 69 | public int getTaille(){ 70 | return taille; 71 | } 72 | } 73 | class Dossier extends Fichier{ 74 | private ArrayList fichiers = new ArrayList<>(); 75 | 76 | public Dossier(String nom) { 77 | super(nom); 78 | } 79 | @Override 80 | public void affiche(int indent) { 81 | super.affiche(indent); 82 | for (Fichier fichier : fichiers) { 83 | fichier.affiche(indent + 1); 84 | } 85 | } 86 | 87 | public void ajouterFichier(Fichier fichier){ 88 | this.fichiers.add(fichier); 89 | } 90 | @Override 91 | public int getTaille(){ 92 | int somme = 0; 93 | for (Fichier fichier : fichiers) { 94 | somme += fichier.getTaille(); 95 | } 96 | return somme; 97 | } 98 | 99 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Sudoku/Case.java: -------------------------------------------------------------------------------- 1 | package Sudoku; 2 | public class Case { 3 | /* 4 | * Voici les attributs 5 | */ 6 | 7 | // Les coordonnées dans le sudoku qui correspondent au (x,y) le coin en haut à gauche est (0,0) et en bas à droite (8,8) 8 | Coordonne coord; 9 | 10 | //La valeur de cette case. Elle sera 0 si la case est non-assignée et entre 1 et 9 sinon. 11 | int value; 12 | 13 | //Tableau qui mémorise les valeurs possibles. Si à un moment, nous déterminons que le chiffre 5 ne peux pas être dans cette 14 | //case, alors valeurPossibles[4] sera false. IMPORTANT: lorsqu'une valeur différente de 0 est assignée à la case, il n'y a plus de 15 | //valeur possibles, donc toutes les possibilitées doivent être à false. 16 | Boolean[] valeurPossibles = {true,true,true,true,true,true,true,true,true}; 17 | 18 | /* 19 | * Le constructeur va prendre en paramètre les positions x et y et la valeur initiale de la case [0,9]. 20 | */ 21 | public Case(Coordonne coord){ 22 | this.coord = coord; 23 | 24 | 25 | } 26 | 27 | public boolean setValue(int val){ 28 | this.value = val; 29 | if(val != 0){ 30 | this.valeurPossibles = new Boolean[]{false, false, false, false, false, false, false, false, false}; 31 | return true; 32 | } 33 | return false; 34 | } 35 | public boolean isLastPossible(int val){ 36 | int somme = 0; 37 | for( int i = 0; i < 9 ; i++){ 38 | if(this.valeurPossibles[i]){ 39 | somme+=1; 40 | } 41 | } 42 | if(somme == 1 && this.valeurPossibles[val - 1]){ 43 | return true; 44 | } 45 | return false; 46 | } 47 | @Override 48 | public String toString() { 49 | return "(" + this.coord.x + "," + this.coord.y + ") : " + this.value + " 1:" + valeurPossibles[0] + " 2:" + valeurPossibles[1]+ " 3:" + valeurPossibles[2]+ " 4:" + valeurPossibles[3]+ " 5:" + valeurPossibles[4]+ " 6:" + valeurPossibles[5]+ " 7:" + valeurPossibles[6]+ " 8:" + valeurPossibles[7]+ " 9:" + valeurPossibles[8]; 50 | } 51 | 52 | 53 | public static void main(String[] args) { 54 | // Créer une case à la position (2,3) 55 | Case case1 = new Case(new Coordonne(2, 3)); 56 | 57 | // Afficher les informations de la case 58 | System.out.println(case1); 59 | 60 | // Retirer une valeur possible 61 | case1.valeurPossibles[3] = false; 62 | 63 | // Afficher les informations de la case 64 | System.out.println(case1); 65 | 66 | // Affecter une valeur à la case 67 | case1.setValue(5); 68 | 69 | // Afficher les informations de la case 70 | System.out.println(case1); 71 | 72 | // Vérifier si une valeur est la dernière possibilité 73 | if(case1.isLastPossible(7)){ 74 | System.out.println("Erreur isLastPossible-1"); 75 | } 76 | case1.valeurPossibles = new Boolean[]{false,false,true,false,false,false,false,false,false}; 77 | if(!case1.isLastPossible(3) || case1.isLastPossible(1)){ 78 | System.out.println("Erreur isLastPossible-2"); 79 | 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen1/Q2Examen2.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examen1; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Scanner; 5 | 6 | // Général /6 7 | // Menu /6 8 | // c1 /6 9 | // c2 /6 10 | // c3 /6 11 | public class Q2Examen2 { 12 | public static void main(String[] args) { 13 | ArrayList noms = new ArrayList(); 14 | ArrayList notes = new ArrayList(); 15 | Scanner scanner = new Scanner(System.in); 16 | String choix; 17 | String nom; 18 | String note; 19 | String noteFormat; 20 | String moyenneFormat; 21 | while(true){ 22 | System.out.println("Menu :"); 23 | System.out.println("1. Ajouter le résultat d'un étudiant"); 24 | System.out.println("2. Afficher la liste des résultats"); 25 | System.out.println("3. Terminer le programme"); 26 | System.out.println("------------------------------------"); 27 | System.out.println("Moyenne du groupe : " + moyenne(notes)); 28 | System.out.println("-------------------------------------------------------------------------------------------- "); 29 | System.out.println(); 30 | 31 | System.out.print("Entrez votre choix : "); 32 | choix = scanner.nextLine(); 33 | 34 | if(choix.equals("1")){ 35 | System.out.print("Entrez le nom complet de l'étudiant : "); 36 | nom = scanner.nextLine(); 37 | noms.add(nom); 38 | System.out.print("Entrez la note de cet étudiant : "); 39 | note = scanner.nextLine(); 40 | notes.add(Integer.parseInt(note)); 41 | 42 | System.out.println("Résultat pour " + nom + " : " + note + " ajouté\n"); 43 | } 44 | else if(choix.equals("2")){ 45 | System.out.println("Liste :"); 46 | for(int i = 0 ; i < noms.size() ; i++){ 47 | noteFormat= String.format("%d",notes.get(i)); 48 | System.out.printf("%-30s %s",noms.get(i), noteFormat); 49 | System.out.println(noms.get(i) + " ".repeat(35 - noms.get(i).length() - noteFormat.length()) + noteFormat); 50 | } 51 | System.out.println("------------------------------------"); 52 | 53 | moyenneFormat = String.format("%s", moyenne(notes)); 54 | // System.out.printf("%-30s %d", "Moyenne", moyenneFormat); 55 | System.out.println("Moyenne :" + " ".repeat(35 - 9 - moyenneFormat.length()) + moyenneFormat); 56 | System.out.println("--------------------------------------------------------------------------------------------\n"); 57 | 58 | } 59 | else if(choix.equals("3")){ 60 | System.out.println("\nAurevoir!"); 61 | break; 62 | } 63 | } 64 | } 65 | public static int moyenne(ArrayList notes){ 66 | int somme = 0; 67 | for(int i = 0; i < notes.size() ; i++){ 68 | somme += notes.get(i); 69 | } 70 | if(somme ==0){ 71 | return 0; 72 | } 73 | return somme / notes.size(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/src/main/java/question2/Main3.java: -------------------------------------------------------------------------------- 1 | package question2; 2 | //30min 3 | import java.util.ArrayList; 4 | 5 | public class Main3 { 6 | public static void main(String[] args) { 7 | 8 | Document cv = new Document("CV.pdf", 300); 9 | Document budget = new Document("budget.xlsx", 150); 10 | Document montagne = new Document("montagne.pdf", 450000); 11 | Document plage = new Document("plage.png", 500000); 12 | 13 | Dossier photoVacances = new Dossier("PhotosVacances"); 14 | photoVacances.ajouterFichier(plage); 15 | photoVacances.ajouterFichier(montagne); 16 | 17 | Dossier personnel = new Dossier("Personnel"); 18 | personnel.ajouterFichier(photoVacances); 19 | personnel.ajouterFichier(budget); 20 | 21 | Document presentation = new Document("presentation.pptx", 850); 22 | Document rapport = new Document("rapport.docs", 1200); 23 | Document readMe = new Document("README.md", 300); 24 | 25 | Dossier projetJava = new Dossier("ProjetJava"); 26 | projetJava.ajouterFichier(readMe); 27 | projetJava.ajouterFichier(rapport); 28 | 29 | Dossier projets = new Dossier("Projets"); 30 | projets.ajouterFichier(projetJava); 31 | projets.ajouterFichier(presentation); 32 | 33 | Dossier documents = new Dossier("Documents"); 34 | documents.ajouterFichier(projets); 35 | documents.ajouterFichier(personnel); 36 | documents.ajouterFichier(cv); 37 | 38 | documents.affiche(0); 39 | } 40 | } 41 | abstract class Fichier{ 42 | private String nom; 43 | 44 | public Fichier(String nom) { 45 | this.nom = nom; 46 | } 47 | 48 | public String getNom() { 49 | return nom; 50 | } 51 | 52 | public void setNom(String nom) { 53 | this.nom = nom; 54 | } 55 | 56 | abstract int getTaille(); 57 | 58 | public void affiche(int indent){ 59 | System.out.printf("%-70s%15d octets\n"," ".repeat(indent) + this.getNom(), this.getTaille()); 60 | } 61 | } 62 | 63 | class Document extends Fichier{ 64 | private int taille; 65 | 66 | public Document(String nom, int taille) { 67 | super(nom); 68 | this.taille = taille; 69 | } 70 | 71 | @Override 72 | public int getTaille() { 73 | return taille; 74 | } 75 | 76 | public void setTaille(int taille) { 77 | this.taille = taille; 78 | } 79 | 80 | 81 | } 82 | 83 | class Dossier extends Fichier{ 84 | private ArrayList fichiers = new ArrayList<>(); 85 | 86 | public Dossier(String nom) { 87 | super(nom); 88 | } 89 | 90 | public void ajouterFichier(Fichier fichier){ 91 | this.fichiers.add(fichier); 92 | } 93 | 94 | @Override 95 | public int getTaille() { 96 | int somme = 0; 97 | for (Fichier fichier : fichiers) { 98 | somme += fichier.getTaille(); 99 | } 100 | return somme; 101 | } 102 | 103 | @Override 104 | public void affiche(int indent) { 105 | super.affiche(indent); 106 | for (Fichier fichier : fichiers) { 107 | fichier.affiche(indent + 1); 108 | } 109 | } 110 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Exo009.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie2; 2 | 3 | public class Exo009 { 4 | public static void main(String[] args) { 5 | Etudiant etudiant1 = new Etudiant(12345, "Bob"); 6 | etudiant1.getEvaluations()[0].setNoteSur100((byte)50); 7 | etudiant1.getEvaluations()[1].setNoteSur100((byte)67); 8 | etudiant1.getEvaluations()[2].setNoteSur100((byte)100); 9 | 10 | etudiant1.afficheResultat(); 11 | } 12 | } 13 | 14 | class Etudiant{ 15 | //Attributs 16 | private int da; 17 | private String nomComplet; 18 | private Evaluation[] evaluations = { 19 | new Evaluation("Examen 1", 0.2f), 20 | new Evaluation("Examen 2", 0.3f), 21 | new Evaluation("Examen Final", 0.5f) 22 | }; 23 | 24 | //Getter & Setter 25 | public int getDa() { 26 | return da; 27 | } 28 | 29 | public void setDa(int da) { 30 | this.da = da; 31 | } 32 | 33 | public String getNomComplet() { 34 | return nomComplet; 35 | } 36 | 37 | public void setNomComplet(String nomComplet) { 38 | this.nomComplet = nomComplet; 39 | } 40 | 41 | public Evaluation[] getEvaluations() { 42 | return evaluations; 43 | } 44 | 45 | public void setEvaluations(Evaluation[] evaluations) { 46 | this.evaluations = evaluations; 47 | } 48 | 49 | //Constructeur 50 | public Etudiant(int da, String nomComplet){ 51 | this.da = da; 52 | this.nomComplet = nomComplet; 53 | } 54 | 55 | //Méthodes 56 | public byte noteFinal(){ 57 | byte noteFinale = 0; 58 | for(int i = 0 ; i < this.evaluations.length ; i++){ 59 | noteFinale += this.evaluations[i].notePonderee(); 60 | } 61 | return noteFinale; 62 | } 63 | 64 | public void afficheResultat(){ 65 | System.out.print(this.da + " " + this.nomComplet + " "); 66 | for(int i = 0 ; i < this.evaluations.length ; i++){ 67 | System.out.print(this.evaluations[i].notePonderee() + " "); 68 | } 69 | System.out.println("| " + this.noteFinal()); 70 | } 71 | 72 | } 73 | 74 | class Evaluation{ 75 | //Attributs 76 | private String nom; 77 | private float ponderation; 78 | private byte noteSur100; 79 | 80 | //Stter & Getter 81 | public String getNom() { 82 | return nom; 83 | } 84 | 85 | public void setNom(String nom) { 86 | this.nom = nom; 87 | } 88 | 89 | public float getPonderation() { 90 | return ponderation; 91 | } 92 | 93 | public void setPonderation(float ponderation) { 94 | this.ponderation = ponderation; 95 | } 96 | 97 | public byte getNoteSur100() { 98 | return noteSur100; 99 | } 100 | 101 | public void setNoteSur100(byte noteSur100) { 102 | this.noteSur100 = noteSur100; 103 | } 104 | 105 | //Constructeur 106 | public Evaluation(String nom,float ponderation){ 107 | this.nom = nom; 108 | this.ponderation = ponderation; 109 | } 110 | 111 | //Méthodes 112 | public byte notePonderee(){ 113 | return (byte) (this.noteSur100 * this.ponderation); 114 | } 115 | public void afficheEvaluation(){ 116 | System.out.println(this.nom + " " + this.ponderation + " " + this.notePonderee()); 117 | } 118 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Exo016.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie2; 2 | import java.util.Scanner; 3 | import java.util.ArrayList; 4 | public class Exo016{ 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | ArrayList facture = new ArrayList<>(); 8 | 9 | 10 | String[] plats = {"Crevette", "Salade", "Frite", "Hamburger", "Gâteau"}; 11 | float[] prix = {8.99f, 5.60f, 6.40f, 10.99f, 7.99f}; 12 | while(true){ 13 | System.out.println(""); 14 | 15 | System.out.println("1. Ajouter un item"); 16 | System.out.println("2. Retirer un item"); 17 | System.out.println("3. Afficher le reçu"); 18 | System.out.println("4. Terminer la transaction"); 19 | String choix = scanner.nextLine(); 20 | System.out.println("Vous avez choisi : " + choix); 21 | System.out.println("Appuyer sur enter pour continuer"); 22 | System.out.println(""); 23 | if(choix.equals("1")){ 24 | for(int i = 0 ; i < plats.length ; i++){ 25 | String prixFormatter = String.format("%.02f$", prix[i]); 26 | System.out.println((i+1) + ". " + plats[i] + 27 | " ".repeat(24 - plats[i].length() - prixFormatter.length()) + prixFormatter); 28 | } 29 | 30 | for(int i = 0; i < 3; i++){ 31 | System.out.print("Entrez le numéro de l'item : "); 32 | 33 | choix = scanner.nextLine(); 34 | try{ 35 | facture.add(plats[Integer.parseInt(choix) - 1]); 36 | break; 37 | }catch(NumberFormatException e){ 38 | System.out.println("\nVous avez entrée un choix invalide\n"); 39 | } 40 | } 41 | } 42 | else if(choix.equals("2")){ 43 | 44 | afficherReçu(facture, prix); 45 | 46 | System.out.print("Quel item voulez-vous retirer : "); 47 | choix = scanner.nextLine(); 48 | facture.remove(Integer.parseInt(choix)); 49 | } 50 | else if(choix.equals("3")){ 51 | afficherReçu(facture, prix); 52 | } 53 | else if(choix.equals("4")){ 54 | afficherReçu(facture, prix); 55 | System.out.println(); 56 | System.out.println("Merci pour votre visite!"); 57 | break; 58 | } 59 | else{ 60 | System.out.println("\nVous avez entrée un choix invalide\n"); 61 | } 62 | scanner.nextLine(); 63 | 64 | 65 | } 66 | } 67 | public static void afficherReçu(ArrayList facture, float[] prix){ 68 | double total = 0; 69 | for(int i = 0 ; i < facture.size() ; i++){ 70 | total += prix[i]; 71 | String prixFormatter = String.format("%.02f$", prix[i]); 72 | System.out.printf("%d. %-24s %s\n", (i+1), facture.get(i), prixFormatter); 73 | 74 | } 75 | System.out.println("---------------------------------"); 76 | String totalFormatter = String.format("%.02f$",total); 77 | System.out.printf("%-27s %s\n","Total",totalFormatter); 78 | // System.out.println("Total" + " ".repeat(22 - totalFormatter.length()) + totalFormatter); 79 | } 80 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen2/question2/Menu.java: -------------------------------------------------------------------------------- 1 | package question2; 2 | 3 | 4 | import java.util.Scanner; 5 | import java.util.ArrayList; 6 | public class Menu{ 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | ArrayList facture = new ArrayList<>(); 10 | 11 | 12 | String[] plats = {"Crevette", "Salade", "Frite", "Hamburger", "Gâteau"}; 13 | float[] prix = {8.99f, 5.60f, 6.40f, 10.99f, 7.99f}; 14 | while(true){ 15 | System.out.println(""); 16 | 17 | System.out.println("1. Ajouter un item"); 18 | System.out.println("2. Retirer un item"); 19 | System.out.println("3. Afficher le reçu"); 20 | System.out.println("4. Terminer la transaction"); 21 | String choix = scanner.nextLine(); 22 | System.out.println("Vous avez choisi : " + choix); 23 | System.out.println("Appuyer sur enter pour continuer"); 24 | System.out.println(""); 25 | if(choix.equals("1")){ 26 | for(int i = 0 ; i < plats.length ; i++){ 27 | System.out.printf("%d. %-14s%10.02f$\n",(i+1) , plats[i], prix[i]); 28 | } 29 | 30 | System.out.print("Entrez le numéro de l'item : "); 31 | choix = scanner.nextLine(); 32 | try{ 33 | facture.add(plats[Integer.parseInt(choix) - 1]); 34 | } 35 | catch(NumberFormatException e){ 36 | System.out.println("Mauvaise entrée, vous devez choisir un chiffre parmi les numéros d'item"); 37 | } 38 | //-1, manque 1 exception 39 | } 40 | else if(choix.equals("2")){ 41 | 42 | afficherReçu(facture, prix); 43 | 44 | System.out.print("Quel item voulez-vous retirer : "); 45 | choix = scanner.nextLine(); 46 | try{ 47 | facture.remove(Integer.parseInt(choix)); 48 | } 49 | catch(NumberFormatException e){ 50 | System.out.println("Mauvaise entrée, vous devez choisir un chiffre parmi les numéros d'item"); 51 | } 52 | catch(IndexOutOfBoundsException e){ 53 | System.out.println("Mauvaise entrée, vous devez choisir un chiffre parmi les numéros d'item"); 54 | } 55 | } 56 | else if(choix.equals("3")){ 57 | afficherReçu(facture, prix); 58 | } 59 | else if(choix.equals("4")){ 60 | afficherReçu(facture, prix); 61 | System.out.println(); 62 | System.out.println("Merci pour votre visite!"); 63 | break; 64 | } 65 | else{ 66 | System.out.println("Mauvaise entrée, vous devez choisir un chiffre entre 1 et 4"); 67 | } 68 | scanner.nextLine(); 69 | 70 | 71 | } 72 | } 73 | public static void afficherReçu(ArrayList facture, float[] prix){ 74 | double total = 0; 75 | for(int i = 0 ; i < facture.size() ; i++){ 76 | total += prix[i]; 77 | String prixFormatter = String.format("%.02f$", prix[i]); 78 | System.out.printf("%d. %-13s%10.02f$\n",(i+1) , facture.get(i), prix[i]); 79 | 80 | 81 | } 82 | System.out.println("-".repeat(27)); 83 | System.out.printf("%-16s%10.2f$\n","Total", total); 84 | 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Exo016V2.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie2; 2 | import java.util.Scanner; 3 | import java.util.ArrayList; 4 | public class Exo016V2{ 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | ArrayList facture = new ArrayList<>(); 8 | 9 | 10 | String[] plats = {"Crevette", "Salade", "Frite", "Hamburger", "Gâteau"}; 11 | float[] prix = {8.99f, 5.60f, 6.40f, 10.99f, 7.99f}; 12 | while(true){ 13 | System.out.println(""); 14 | 15 | System.out.println("1. Ajouter un item"); 16 | System.out.println("2. Retirer un item"); 17 | System.out.println("3. Afficher le reçu"); 18 | System.out.println("4. Terminer la transaction"); 19 | String choix = scanner.nextLine(); 20 | System.out.println("Vous avez choisi : " + choix); 21 | System.out.println("Appuyer sur enter pour continuer"); 22 | System.out.println(""); 23 | if(choix.equals("1")){ 24 | for(int i = 0 ; i < plats.length ; i++){ 25 | String prixFormatter = String.format("%.02f$", prix[i]); 26 | 27 | System.out.printf("%-20s%7s\n",(i+1) + ". " + plats[i], prixFormatter); 28 | } 29 | for(int k = 0 ; k < 3 ; k++){ 30 | System.out.print("Entrez le numéro de l'item : "); 31 | 32 | choix = scanner.nextLine(); 33 | try{ 34 | facture.add(plats[Integer.parseInt(choix) - 1]); 35 | break; 36 | }catch(NumberFormatException e){ 37 | System.out.println("Votre choix est invalide"); 38 | } 39 | } 40 | } 41 | else if(choix.equals("2")){ 42 | 43 | afficherReçu(facture, prix); 44 | for(int k = 0 ; k < 3 ; k++){ 45 | System.out.print("Quel item voulez-vous retirer : "); 46 | choix = scanner.nextLine(); 47 | try{ 48 | facture.remove(Integer.parseInt(choix)-1); 49 | break; 50 | }catch(NumberFormatException e){ 51 | System.out.println("Votre choix est invalide"); 52 | } 53 | } 54 | } 55 | else if(choix.equals("3")){ 56 | afficherReçu(facture, prix); 57 | } 58 | else if(choix.equals("4")){ 59 | afficherReçu(facture, prix); 60 | System.out.println(); 61 | System.out.println("Merci pour votre visite!"); 62 | break; 63 | } 64 | else{ 65 | System.out.println("Votre choix est invalide"); 66 | } 67 | scanner.nextLine(); 68 | 69 | 70 | } 71 | } 72 | public static void afficherReçu(ArrayList facture, float[] prix){ 73 | double total = 0; 74 | for(int i = 0 ; i < facture.size() ; i++){ 75 | total += prix[i]; 76 | String prixFormatter = String.format("%.02f$", prix[i]); 77 | System.out.printf("%-20s%7s\n",(i+1) + ". " + facture.get(i), prixFormatter); 78 | 79 | 80 | } 81 | System.out.println("----------------------------"); 82 | String totalFormatter = String.format("%.02f$",total); 83 | 84 | System.out.printf("%-20s%7s\n","Total", totalFormatter); 85 | 86 | } 87 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/final/src/main/java/question2/otherVersions/Main.java: -------------------------------------------------------------------------------- 1 | package question2; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | // Création de l’arborescence 8 | Repertoire root = new Repertoire("Documents"); 9 | 10 | Repertoire projets = new Repertoire("Projets"); 11 | Repertoire perso = new Repertoire("Personnel"); 12 | 13 | Repertoire projetJava = new Repertoire("ProjetJava"); 14 | projetJava.ajouterFichier(new Document("README.md", 300)); 15 | projetJava.ajouterFichier(new Document("rapport.docs", 1200)); 16 | 17 | Repertoire photos = new Repertoire("PhotosVacances"); 18 | photos.ajouterFichier(new Document("plage.png", 500000)); 19 | photos.ajouterFichier(new Document("montagne.pdf", 450000)); 20 | 21 | perso.ajouterFichier(photos); 22 | perso.ajouterFichier(new Document("budget.xlsx", 150)); 23 | 24 | projets.ajouterFichier(projetJava); 25 | projets.ajouterFichier(new Document("presentation.pptx", 850)); 26 | 27 | root.ajouterFichier(projets); 28 | root.ajouterFichier(perso); 29 | root.ajouterFichier(new Document("CV.pdf", 300)); 30 | 31 | // Affichage complet 32 | System.out.println("Arborescence complète :"); 33 | root.afficheAvecProfondeur(0); 34 | 35 | } 36 | } 37 | 38 | abstract class Fichier{ 39 | public static final int INDENT = 10; 40 | private String nom; 41 | 42 | public Fichier(String nom) { 43 | this.nom = nom; 44 | } 45 | public String getNom() { 46 | return nom; 47 | } 48 | public void setNom(String nom) { 49 | this.nom = nom; 50 | } 51 | 52 | 53 | abstract long getTaille(); 54 | 55 | abstract void afficheAvecProfondeur(int depth); 56 | } 57 | 58 | 59 | class Document extends Fichier{ 60 | private long taille; 61 | public Document(String nom, long taille) { 62 | super(nom); 63 | this.taille = taille; 64 | } 65 | 66 | @Override 67 | public long getTaille() { 68 | return taille; 69 | } 70 | public void setTaille(long taille) { 71 | this.taille = taille; 72 | } 73 | 74 | @Override 75 | public void afficheAvecProfondeur(int depth){ 76 | System.out.printf("%" + INDENT * depth + "s%-" + (80 - INDENT * depth) + "s%16d octets\n","" ,this.getNom(), this.getTaille()); 77 | } 78 | 79 | } 80 | 81 | class Repertoire extends Fichier{ 82 | private ArrayList listeFichier = new ArrayList<>(); 83 | 84 | public Repertoire(String nom) { 85 | super(nom); 86 | } 87 | 88 | public void ajouterFichier(Fichier fichier){ 89 | this.listeFichier.add(fichier); 90 | } 91 | 92 | public void listerFichier(){ 93 | for (Fichier fichier : listeFichier) { 94 | System.out.println(fichier); 95 | } 96 | } 97 | 98 | @Override 99 | public long getTaille(){ 100 | long somme = 0; 101 | for (Fichier fichier : listeFichier) { 102 | somme += fichier.getTaille(); 103 | } 104 | return somme; 105 | } 106 | @Override 107 | public void afficheAvecProfondeur(int depth){ 108 | System.out.printf("%" + ((depth > 0) ? INDENT * depth : "") + "s%-" + (80 - depth*INDENT) + "s%16d octets\n","", this.getNom(), this.getTaille()); 109 | for (Fichier fichier : listeFichier) { 110 | fichier.afficheAvecProfondeur(depth + 1); 111 | } 112 | 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Exo021.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie2; 2 | import java.util.ArrayList; 3 | 4 | public class Exo021 { 5 | public static void main(String[] args) { 6 | Depense test1 = new Depense("Bouf", 123.54, Categorie.nourriture); 7 | Depense test2 = new Depense("Salaire", -123.54, Categorie.diver); 8 | Depense test3 = new Depense("voiture", 10000, Categorie.diver); 9 | System.out.println(test1); 10 | 11 | Budget budget = new Budget(1000); 12 | budget.ajouterDepense(test1); 13 | budget.ajouterDepense(test2); 14 | budget.ajouterDepense(test3); 15 | 16 | 17 | } 18 | 19 | } 20 | enum Categorie{ 21 | voyage, 22 | santé, 23 | habitation, 24 | nourriture, 25 | éducation, 26 | loisir, 27 | diver 28 | } 29 | class Depense{ 30 | private String nom = ""; 31 | private double cout = 0; 32 | private Categorie categorie = Categorie.diver; 33 | 34 | 35 | public Depense(String nom, double cout, Categorie categorie){ 36 | this.setNom(nom); 37 | this.setCout(cout); 38 | this.setCategorie(categorie); 39 | } 40 | 41 | public void setNom(String nom){ 42 | this.nom = nom; 43 | } 44 | 45 | public String getNom(){ 46 | return this.nom; 47 | } 48 | 49 | public void setCout(double cout){ 50 | this.cout = cout; 51 | } 52 | 53 | public double getCout(){ 54 | return this.cout; 55 | } 56 | 57 | public void setCategorie(Categorie categorie){ 58 | this.categorie = categorie; 59 | } 60 | 61 | public Categorie getCategorie(){ 62 | return this.categorie; 63 | } 64 | 65 | 66 | @Override 67 | public String toString(){ 68 | return String.format("%-30s%10s%9.2f$", this.nom, this.categorie, this.cout); 69 | 70 | } 71 | } 72 | 73 | class Budget{ 74 | private double montantTotal = 0; 75 | private double montantUtilise = 0; 76 | private ArrayList depenses = new ArrayList<>(); 77 | 78 | public Budget(double montantTotal){ 79 | this.setMontantTotal(montantTotal); 80 | } 81 | 82 | public void setMontantTotal(double montantTotal){ 83 | if(montantTotal < 0){ 84 | System.out.println("Nous ne pouvons pas avoir un montant total négatif"); 85 | return; 86 | } 87 | this.montantTotal = montantTotal; 88 | } 89 | 90 | public double getMontantTotal(){ 91 | return this.montantTotal; 92 | } 93 | 94 | public void setMontantUtilise(double montantUtilise){ 95 | this.montantUtilise = montantUtilise; 96 | } 97 | 98 | public double getMontantUtilise(){ 99 | return this.montantUtilise; 100 | } 101 | 102 | public void ajouterDepense(Depense depense){ 103 | if(this.montantUtilise + depense.getCout() > this.montantTotal){ 104 | System.out.println("Échec de l'ajout de : " + depense); 105 | System.out.println("Montant total excédé"); 106 | return; 107 | } 108 | else if(depense.getCout() >= 0){ 109 | this.depenses.add(depense); 110 | } 111 | else{ 112 | System.out.println("Échec de l'ajout de : " + depense); 113 | System.out.println("Le coût est négatif"); 114 | return; 115 | } 116 | } 117 | 118 | public void modifierDepense(int indice, Depense depense){ 119 | this.depenses.set(indice, depense); 120 | } 121 | 122 | public void retirerDepense(int indice){ 123 | this.depenses.remove(indice); 124 | } 125 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie2/Exo028.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie2; 2 | 3 | public class Exo028 { 4 | public static void main(String[] args) { 5 | Personne personne = new Personne("Jean", 40, "10 rue des Lilas"); 6 | Etudiant etudiant = new Etudiant("Marie", 22, "15 rue de la Paix", "Informatique", "E123"); 7 | Professeur professeur = new Professeur("Mr. Dupont", 45, "12 avenue des Champs", "Mathématiques", 2500.00); 8 | 9 | personne.sePresenter(); 10 | etudiant.seDecrire(); 11 | etudiant.etudier(); 12 | professeur.seDecrire(); 13 | professeur.enseigner(); 14 | } 15 | } 16 | class Personne{ 17 | protected String nom; 18 | protected int age; 19 | protected String adresse; 20 | 21 | public void setNom(String nom){ 22 | this.nom = nom; 23 | } 24 | public String getNom(){ 25 | return this.nom; 26 | } 27 | public void setAge(int age){ 28 | this.age = age; 29 | } 30 | public int getAge(){ 31 | return this.age; 32 | } 33 | public void setAdresse(String adresse){ 34 | this.adresse = adresse; 35 | } 36 | public String getAdresse(){ 37 | return this.adresse; 38 | } 39 | public Personne(String nom, int age, String adresse){ 40 | this.setNom(nom); 41 | this.setAge(age); 42 | this.setAdresse(adresse); 43 | } 44 | 45 | public void sePresenter(){ 46 | System.out.println("Je suis " + this.nom + ", j'ai " + this.age + " ans et mon adresse est " + this.adresse); 47 | } 48 | } 49 | class Etudiant extends Personne{ 50 | protected String filiere; 51 | protected String numEtudiant; 52 | 53 | public void setFiliere(String filiere){ 54 | this.filiere = filiere; 55 | } 56 | public String getFiliere(){ 57 | return this.filiere; 58 | } 59 | 60 | public void setNumEtudiant(String numEtudiant){ 61 | this.numEtudiant = numEtudiant; 62 | } 63 | public String getNumEtudiant(){ 64 | return this.numEtudiant; 65 | } 66 | public Etudiant(String nom, int age, String adresse, String filiere, String numEtudiant){ 67 | super(nom, age, adresse); 68 | this.setFiliere(filiere); 69 | this.setNumEtudiant(numEtudiant); 70 | 71 | } 72 | 73 | public void etudier(){ 74 | System.out.printf("L'étudiant %s étudie %s\n",this.nom, this.filiere); 75 | } 76 | public void seDecrire(){ 77 | super.sePresenter(); 78 | System.out.printf("Je suis en filière %s, Numéro étudiant: %s\n", this.filiere, this.numEtudiant); 79 | } 80 | } 81 | class Professeur extends Personne{ 82 | protected String matiere; 83 | protected double salaire; 84 | 85 | public void setMatiere(String matiere){ 86 | this.matiere = matiere; 87 | } 88 | public String getMatiere(){ 89 | return this.matiere; 90 | } 91 | public void setSalaire(double salaire){ 92 | this.salaire = salaire; 93 | } 94 | public double getSalaire(){ 95 | return this.salaire; 96 | } 97 | public Professeur(String nom, int age, String adresse, String matiere, double salaire){ 98 | super(nom, age, adresse); 99 | this.setMatiere(matiere); 100 | this.setSalaire(salaire); 101 | } 102 | public void enseigner(){ 103 | System.out.printf("L'enseignant %s enseigne %s\n",this.nom, this.matiere); 104 | } 105 | public void seDecrire(){ 106 | super.sePresenter(); 107 | System.out.printf("J'enseigne la matière %s, salaire: %.02f€\n", this.matiere, this.salaire); 108 | } 109 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/formatif2/question2/rgv1.drawio: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examen3/question2/Main2.java: -------------------------------------------------------------------------------- 1 | package question2; 2 | 3 | public class Main2 { 4 | public static void main(String[] args) { 5 | DoublyLinkedList list = new DoublyLinkedList(); 6 | 7 | list.addLast(10); 8 | list.addLast(20); 9 | list.addFirst(5); 10 | list.printForward(); // Liste → 5 10 20 11 | list.printBackward(); // Liste (revers) ← 20 10 5 12 | 13 | list.addBefore(new Node(88),list.getElementFromStart(1)); 14 | list.printForward(); // Liste → 5 88 10 20 15 | list.printBackward(); // Liste (revers) ← 20 10 88 5 16 | 17 | 18 | list.addBefore(new Node(8),list.getElementFromStart(0)); 19 | list.printForward(); // Liste → 8 5 88 10 20 20 | list.printBackward(); // Liste (revers) ← 20 10 88 5 8 21 | 22 | 23 | 24 | System.out.println("Taille: " + list.size()); // Taille: 5 25 | } 26 | } 27 | class Node { 28 | int data; 29 | Node prev; 30 | Node next; 31 | 32 | Node(int data) { 33 | this.data = data; 34 | } 35 | } 36 | // Classe de la liste doublement chaînée 37 | class DoublyLinkedList { 38 | private Node head; 39 | private Node tail; 40 | private int size = 0; 41 | 42 | // Ajouter à la fin 43 | public void addLast(int value) { 44 | Node newNode = new Node(value); 45 | if (tail == null) { 46 | head = tail = newNode; 47 | } else { 48 | tail.next = newNode; 49 | newNode.prev = tail; 50 | tail = newNode; 51 | } 52 | size++; 53 | } 54 | 55 | // Ajouter au début 56 | public void addFirst(int value) { 57 | Node newNode = new Node(value); 58 | if (head == null) { 59 | head = tail = newNode; 60 | } else { 61 | head.prev = newNode; 62 | newNode.next = head; 63 | head = newNode; 64 | } 65 | size++; 66 | } 67 | 68 | 69 | 70 | // Affichage de la liste (vers l'avant) 71 | public void printForward() { 72 | Node current = head; 73 | System.out.print("Liste → "); 74 | while (current != null) { 75 | System.out.print(current.data + " "); 76 | current = current.next; 77 | } 78 | System.out.println(); 79 | } 80 | 81 | // Affichage de la liste (vers l'arrière) 82 | public void printBackward() { 83 | Node current = tail; 84 | System.out.print("Liste (revers) ← "); 85 | while (current != null) { 86 | System.out.print(current.data + " "); 87 | current = current.prev; 88 | } 89 | System.out.println(); 90 | } 91 | 92 | // Obtenir la taille 93 | public int size() { 94 | return size; 95 | } 96 | 97 | public Node getElementFromStart(int index){ 98 | if(index < 0 || index > this.size){ 99 | System.out.println("Erreur"); 100 | return null; 101 | } 102 | Node cur = this.head; 103 | for(int i = 0 ; i < index ; i++){ 104 | cur = cur.next; 105 | } 106 | return cur; 107 | } 108 | 109 | //Remplisser cette méthode 110 | public void addBefore(Node nouveau, Node vieux){ 111 | //4 112 | if(vieux == head){ 113 | addFirst(nouveau.data); 114 | } 115 | else{ 116 | //4 117 | nouveau.prev = vieux.prev; 118 | nouveau.next = vieux; 119 | nouveau.next.prev = nouveau; 120 | nouveau.prev.next = nouveau; 121 | } 122 | //2 123 | size++; 124 | } 125 | 126 | 127 | 128 | } 129 | -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/serie3/Exo9.java: -------------------------------------------------------------------------------- 1 | package solution_exo.serie3; 2 | 3 | public class Exo9 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Etudiant etudiant = new Etudiant("Marie", 22, "15 rue de la Paix", "Informatique", "E123"); 8 | Professeur professeur = new Professeur("Mr. Dupont", 45, "12 avenue des Champs", "Mathématiques", 2500.00); 9 | 10 | Personne[] personnes = { 11 | etudiant, 12 | professeur 13 | }; 14 | etudiant.etudier(); 15 | professeur.enseigner(); 16 | 17 | for(Personne personne : personnes){ 18 | personne.seDecrire(); 19 | } 20 | } 21 | } 22 | abstract class Personne{ 23 | protected String nom; 24 | protected int age; 25 | protected String adresse; 26 | 27 | public void setNom(String nom){ 28 | this.nom = nom; 29 | } 30 | public String getNom(){ 31 | return this.nom; 32 | } 33 | public void setAge(int age){ 34 | this.age = age; 35 | } 36 | public int getAge(){ 37 | return this.age; 38 | } 39 | public void setAdresse(String adresse){ 40 | this.adresse = adresse; 41 | } 42 | public String getAdresse(){ 43 | return this.adresse; 44 | } 45 | public Personne(String nom, int age, String adresse){ 46 | this.setNom(nom); 47 | this.setAge(age); 48 | this.setAdresse(adresse); 49 | } 50 | 51 | 52 | abstract void seDecrire(); 53 | 54 | public void sePresenter(){ 55 | System.out.println("Je suis " + this.nom + ", j'ai " + this.age + " ans et mon adresse est " + this.adresse); 56 | } 57 | } 58 | class Etudiant extends Personne{ 59 | protected String filiere; 60 | protected String numEtudiant; 61 | 62 | public void setFiliere(String filiere){ 63 | this.filiere = filiere; 64 | } 65 | public String getFiliere(){ 66 | return this.filiere; 67 | } 68 | 69 | public void setNumEtudiant(String numEtudiant){ 70 | this.numEtudiant = numEtudiant; 71 | } 72 | public String getNumEtudiant(){ 73 | return this.numEtudiant; 74 | } 75 | public Etudiant(String nom, int age, String adresse, String filiere, String numEtudiant){ 76 | super(nom, age, adresse); 77 | this.setFiliere(filiere); 78 | this.setNumEtudiant(numEtudiant); 79 | 80 | } 81 | 82 | public void etudier(){ 83 | System.out.printf("L'étudiant %s étudie %s\n",this.nom, this.filiere); 84 | } 85 | @Override 86 | public void seDecrire(){ 87 | super.sePresenter(); 88 | System.out.printf("Je suis en filière %s, Numéro étudiant: %s\n", this.filiere, this.numEtudiant); 89 | } 90 | } 91 | class Professeur extends Personne{ 92 | protected String matiere; 93 | protected double salaire; 94 | 95 | public void setMatiere(String matiere){ 96 | this.matiere = matiere; 97 | } 98 | public String getMatiere(){ 99 | return this.matiere; 100 | } 101 | public void setSalaire(double salaire){ 102 | this.salaire = salaire; 103 | } 104 | public double getSalaire(){ 105 | return this.salaire; 106 | } 107 | public Professeur(String nom, int age, String adresse, String matiere, double salaire){ 108 | super(nom, age, adresse); 109 | this.setMatiere(matiere); 110 | this.setSalaire(salaire); 111 | } 112 | public void enseigner(){ 113 | System.out.printf("L'enseignant %s enseigne %s\n",this.nom, this.matiere); 114 | } 115 | @Override 116 | public void seDecrire(){ 117 | super.sePresenter(); 118 | System.out.printf("J'enseigne la matière %s, salaire: %.02f€\n", this.matiere, this.salaire); 119 | } 120 | } -------------------------------------------------------------------------------- /cours/src/main/java/solution_exo/examenFinal/formatif2/question2/q2V2.java: -------------------------------------------------------------------------------- 1 | package solution_exo.examenFinal.formatif2.question2; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class q2V2 { 6 | public static void main(String[] args) { 7 | 8 | // Dernier niveau 9 | Employe hugo = new Employe("Stagiaire", "Hugo Chartrand", new ArrayList<>(), 3); 10 | 11 | // Niveau 2 12 | ArrayList alexSubordonnes = new ArrayList<>(); 13 | alexSubordonnes.add(hugo); 14 | Employe alex = new Employe("Développeur frontend", "Alex Gagnon", alexSubordonnes, 2); 15 | 16 | Employe nadia = new Employe("Développeuse backend", "Nadia Belhumeur", new ArrayList<>(), 2); 17 | 18 | // Niveau 1 - Directeur TI 19 | ArrayList marcSubordonnes = new ArrayList<>(); 20 | marcSubordonnes.add(nadia); 21 | marcSubordonnes.add(alex); 22 | Employe marc = new Employe("Directeur TI", "Marc Boivin", marcSubordonnes, 1); 23 | 24 | // Niveau 2 Marketing 25 | Employe sarah = new Employe("Analyste marketing", "Sarah Lefebvre", new ArrayList<>(), 2); 26 | Employe kevin = new Employe("Designer graphique", "Kevin Lemoine", new ArrayList<>(), 2); 27 | 28 | // Niveau 1 - Directrice Marketing 29 | ArrayList aliceSubordonnes = new ArrayList<>(); 30 | aliceSubordonnes.add(sarah); 31 | aliceSubordonnes.add(kevin); 32 | Employe alice = new Employe("Directrice Marketing", "Alice Tremblay", aliceSubordonnes, 1); 33 | 34 | // PDG - Niveau 0 35 | ArrayList jeanSubordonnes = new ArrayList<>(); 36 | jeanSubordonnes.add(alice); 37 | jeanSubordonnes.add(marc); 38 | Employe jean = new Employe("PDG", "Jean Dupuis", jeanSubordonnes, 0); 39 | 40 | // Affichage récursif 41 | // afficherEmployes(jean); 42 | 43 | //Affichage Non-récursif 44 | 45 | System.out.print(jean); 46 | System.out.print(alice); 47 | System.out.print(sarah); 48 | System.out.print(kevin); 49 | System.out.print(marc); 50 | System.out.print(nadia); 51 | System.out.print(alex); 52 | System.out.print(hugo); 53 | 54 | } 55 | 56 | public static void afficherEmployes(Employe e) { 57 | System.out.print(e.toString()); 58 | for (Employe sub : e.getEmployes()) { 59 | afficherEmployes(sub); 60 | } 61 | } 62 | 63 | } 64 | 65 | 66 | class Employe{ 67 | private String titre; 68 | private String nom; 69 | private ArrayList employes; 70 | private int nivIndent = 0; 71 | 72 | 73 | public Employe(String titre, String nom, ArrayList employes, int nivIndent) { 74 | this.titre = titre; 75 | this.nom = nom; 76 | this.employes = employes; 77 | this.nivIndent = nivIndent; 78 | } 79 | public String getTitre() { 80 | return titre; 81 | } 82 | public void setTitre(String titre) { 83 | this.titre = titre; 84 | } 85 | public String getNom() { 86 | return nom; 87 | } 88 | public void setNom(String nom) { 89 | this.nom = nom; 90 | } 91 | public ArrayList getEmployes() { 92 | return employes; 93 | } 94 | public void setEmployes(ArrayList employes) { 95 | this.employes = employes; 96 | } 97 | public int getNivIndent() { 98 | return nivIndent; 99 | } 100 | public void setNivIndent(int nivIndent) { 101 | this.nivIndent = nivIndent; 102 | } 103 | @Override 104 | public String toString() { 105 | String msg = ""; 106 | msg += "\t".repeat(nivIndent); 107 | msg += String.format("%s - %s\n",this.nom, this.titre); 108 | return msg; 109 | } 110 | 111 | 112 | 113 | 114 | } 115 | 116 | 117 | --------------------------------------------------------------------------------