Skip to content
Snippets Groups Projects
Commit a86e4a9e authored by CORONA Nikola's avatar CORONA Nikola
Browse files

mise en place de tous le cours

parent f85b3c54
No related branches found
No related tags found
No related merge requests found
TD2 Qualité de développement @ e43d4816
Subproject commit e43d48160bf1d9aa01ecba7f77a7dd28db9c60a3
function creeInitiales(nom, prenom) {
return nom[0].toUpperCase() + prenom[0].toUpperCase();
}
console.log(creeInitiales('Corona', 'Nikola'));
function creeInitialesSecurise(nom, prenom) {
if (!nom || !prenom) {
throw new Error('Le nom et le prénom ne doivent pas être vides.');
}
return nom[0].toUpperCase() + prenom[0].toUpperCase();
}
class NomVideError extends Error {
constructor(message) {
super(message);
this.name = 'NomVideError';
}
}
class PrenomVideError extends Error {
constructor(message) {
super(message);
this.name = 'PrenomVideError';
}
}
class NomEtPrenomVideError extends Error {
constructor(message) {
super(message);
this.name = 'NomEtPrenomVideError';
}
}
function creeInitialesAvecExceptions(nom, prenom) {
if (!nom && !prenom) {
throw new NomEtPrenomVideError('Le nom et le prénom sont vides.');
}
if (!nom) {
throw new NomVideError('Le nom est vide.');
}
if (!prenom) {
throw new PrenomVideError('Le prénom est vide.');
}
return nom[0].toUpperCase() + prenom[0].toUpperCase();
}
try {
console.log(creeInitialesAvecExceptions('Corona', 'Nikola'));
} catch (error) {
if (error instanceof NomEtPrenomVideError || error instanceof NomVideError || error instanceof PrenomVideError) {
console.error(error.message);
} else {
throw error;
}
} finally {
console.log('Fin du programme');
}
class InitialesError extends Error {
constructor(message) {
super(message);
this.name = 'InitialesError';
}
}
function creeInitialesSimplifie(nom, prenom) {
if (!nom && !prenom) {
throw new InitialesError('Le nom et le prénom sont vides.');
}
if (!nom) {
throw new InitialesError('Le nom est vide.');
}
if (!prenom) {
throw new InitialesError('Le prénom est vide.');
}
return nom[0].toUpperCase() + prenom[0].toUpperCase();
}
class INEError extends Error {
constructor(message: string) {
super(message);
this.name = "INEError";
}
}
class Etudiant {
private INE: string;
private nom: string;
private prenom: string;
constructor(nom: string, prenom: string) {
this.nom = nom;
this.prenom = prenom;
this.INE = "";
}
isLetter(c: string): boolean {
return (c >= "a" && c <= "z") || (c >= "A" && c <= "Z");
}
setINE(ine: string): void {
const regex1 = /^\d{10}[A-Za-z]$/;
const regex2 = /^\d{9}[A-Za-z]{2}$/;
if (!regex1.test(ine) && !regex2.test(ine)) {
throw new INEError("Format incorrect");
}
this.INE = ine;
}
getINE(): string {
return this.INE;
}
}
function demanderINE(etudiant: Etudiant) {
let valide = false;
while (!valide) {
try {
const ine = prompt("Entrez le code INE :") || "";
etudiant.setINE(ine);
console.log("INE enregistré :", etudiant.getINE());
valide = true;
} catch (error) {
if (error instanceof INEError) {
console.log(error.message);
} else {
console.log("Une erreur inattendue s'est produite.");
break ;
}
}
}
}
class FormatDateError extends Error {
constructor(message: string) {
super(message);
this.name = "FormatDateError";
}
}
class ValeurDateError extends Error {
constructor(message: string) {
super(message);
this.name = "ValeurDateError";
}
}
function parseDate(dateStr: string): number[] {
const parts = dateStr.split("/");
if (parts.length !== 3) {
throw new FormatDateError("Format de date incorrect. Utilisez JJ/MM/AAAA.");
}
const jour = parseInt(parts[0], 10);
const mois = parseInt(parts[1], 10);
const annee = parseInt(parts[2], 10);
if (isNaN(jour) || isNaN(mois) || isNaN(annee)) {
throw new FormatDateError("La date contient des valeurs non numériques.");
}
if (jour < 1 || jour > 31) {
throw new ValeurDateError("Le jour doit être compris entre 1 et 31.");
}
if (mois < 1 || mois > 12) {
throw new ValeurDateError("Le mois doit être compris entre 1 et 12.");
}
return [jour, mois, annee];
}
class ErreurOperandeNull extends Error {
constructor(message: string) {
super(message);
this.name = "ErreurOperandeNull";
}
}
class ErreurOpeInva extends Error {
constructor(message : string){
super(message);
this.name = "ErreurOpeInva";
}
}
class ErreurHorsTab extends Error {
constructor(message : string){
super(message);
this.name = "ErreurHorsTab";
}
}
function calcule(
tableau: Array<number>,
indice: number,
operateur: string,
operande: number
): number {
if (indice < 0 || indice > tableau.length-1){
throw new ErreurHorsTab("Indice trop grand")
}
switch (operateur) {
case "+":
return tableau[indice] + operande;
case "-":
return tableau[indice] - operande;
case "*":
return tableau[indice] * operande;
case "/":
if (operande === 0){
throw new ErreurOperandeNull("Division Null")
}
else {
return tableau[indice] / operande;
}
}
return 0;
}
try {
console.log(calcule([10, 20, 30, 40], 2, "/", 0))
}
catch(error){
if (error instanceof ErreurOperandeNull){
console.log("Erreur de division denominateur null" + error.message) }
}
File added
File added
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"request": "launch",
"name": "Launch Program",
"type": "node",
"program": "${workspaceFolder}/test.ts",
"cwd": "${workspaceFolder}",
"env": {},
"runtimeExecutable": "/home/laroche5/.deno/bin/deno",
"runtimeArgs": [
"run",
"--unstable",
"--inspect-wait",
"--allow-all"
],
"attachSimplePort": 9229
}
]
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment