diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..b83d22266ac8aa2f8df2edef68082c789727841d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/src/main/java/com/mycompany/miamle/MainClass.java b/src/main/java/com/mycompany/miamle/MainClass.java index 37691cc5eda7589d612ec1ce5d1df95cb7302411..5a080656bfeacc6681342cf516b4f2b194c43db8 100644 --- a/src/main/java/com/mycompany/miamle/MainClass.java +++ b/src/main/java/com/mycompany/miamle/MainClass.java @@ -5,10 +5,40 @@ */ package com.mycompany.miamle; +import enums.Meal; +import java.time.LocalDate; +import java.time.Month; +import models.DTO.Attendance; +import models.Inn; + /** * - * @author ramzi + * @author Herbert Caffarel */ public class MainClass { - -} + + public static void main(String[] args) { + Inn inn = new Inn(LocalDate.of(2023, Month.APRIL, 12)); + // Créer des participations + Attendance alf = new Attendance("Danlta", "Alphonse", "0123456789", ""); + Attendance sophie = new Attendance("Stule", "Sophie", "9876543210", "Avec la famille"); + Attendance guy = new Attendance("Tare", "Guy", "@guitounet", ""); + // Configurer le premier participant et l'ajouter à l'événement + alf.addMeal(Meal.STARTERS, 5); + alf.addMeal(Meal.MAIN_COURSES, 3); + alf.addMeal(Meal.DRINKS, 5); + alf.addMeal(Meal.DESSERTS, 2); + inn.add(alf); + // Configurer le second participant et l'ajouter à l'événement + sophie.addMeal(Meal.DRINKS, 2); + sophie.addMeal(Meal.DESSERTS, 6); + sophie.addMeal(Meal.MAIN_COURSES, 6); + sophie.addMeal(Meal.STARTERS, 3); + inn.add(sophie); + // Configurer le troisième participant et l'ajouter à l'événement + guy.addMeal(Meal.DRINKS, 6); + inn.add(guy); + + System.out.println(inn); + } +} \ No newline at end of file diff --git a/src/main/java/enums/Meal.java b/src/main/java/enums/Meal.java index 5ccc1c0e645b95f6edb7ca4911cea23bca034620..80c06522aa196c21acc0eb58c88970ca1f1b8afa 100644 --- a/src/main/java/enums/Meal.java +++ b/src/main/java/enums/Meal.java @@ -1,14 +1,25 @@ /* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Enum.java to edit this template */ package enums; /** * - * @author ramzi + * @author stag */ -public class Meal { +public enum Meal { + STARTERS("Entrees"), + MAIN_COURSES("Plats de resistance"), + DESSERTS("Desserts"),DRINKS("Boissons"); + private final String frenchName; + + private Meal(String frenchName) { + this.frenchName = frenchName; + } + + public String getFrenchName() { + return frenchName; + } } diff --git a/src/main/java/model/DTO/Attendance.java b/src/main/java/model/DTO/Attendance.java deleted file mode 100644 index 0b23052d60428b345ebdbd34a0461d56844b01f4..0000000000000000000000000000000000000000 --- a/src/main/java/model/DTO/Attendance.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package model.DTO; - -/** - * - * @author ramzi - */ -public class Attendance { - -} diff --git a/src/main/java/model/DTO/Person.java b/src/main/java/model/DTO/Person.java deleted file mode 100644 index e0328f53a5486cbf570e9c9fcf4d52c95fad93d7..0000000000000000000000000000000000000000 --- a/src/main/java/model/DTO/Person.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package model.DTO; - -/** - * - * @author ramzi - */ -public class Person { - -} diff --git a/src/main/java/models/DTO/Attendance.java b/src/main/java/models/DTO/Attendance.java new file mode 100644 index 0000000000000000000000000000000000000000..04cb49d5bb3cf1c507b1b74d2f73a1c8055539a3 --- /dev/null +++ b/src/main/java/models/DTO/Attendance.java @@ -0,0 +1,87 @@ +package models.DTO; + +import java.util.HashMap; +import enums.Meal; + + + public class Attendance extends Person implements Comparable{ + + + + private String contact; //contacter le participant + private String comment;// les commentaires potentiels + private int guests; // le nombre de convives y compris le nombre de participants + private HashMap meals; // les plats amenes le type et la quantite + + public Attendance() { + this.guests = guests; + + } + + public Attendance(String name, + String forname, + String contact, + String comment) { + super(name, forname); + this.contact = contact; + this.comment = comment; + this.guests = guests; + + } + public Attendance(Person person, + String name, + String forname, + String contact, + String comment, + int guests) { + super(name, forname); + this.contact = contact; + this.comment = comment; + this.guests = guests; + + } + + + + + + public void setContact(String contact) { + this.contact = contact; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public void setGuests(int guests) { + this.guests = guests; + } + + public void addMeal(Meal meal,int qty){ + this.meals.put(meal,qty); + if (qty>0) { + this.meals.put(meal, qty); + }else if (qty==0) { + clearMeal(meal); + this.meals.remove(meal); + }else{ + throw new IllegalArgumentException("la quantite doit etre >=0"); + } + } + + public void clearMeal(Meal meal){ + this.meals.remove(meal); + + } + + @Override + public int compareTo(Attendance o){ + if (this==o) { + return 0; + } + if (!this.name.equals(o.name)) { + return this.name.compareTo(o.name); + } + return this.forname.compareTo(o.forname); + } +} diff --git a/src/main/java/models/DTO/Person.java b/src/main/java/models/DTO/Person.java new file mode 100644 index 0000000000000000000000000000000000000000..32b4de7906a02d3f7273bedd48fb7e59feb084c0 --- /dev/null +++ b/src/main/java/models/DTO/Person.java @@ -0,0 +1,75 @@ + +package models.DTO; + +import java.util.Objects; +import java.util.Scanner; + + +public class Person { + protected String name; + protected String forname; + Scanner scanner = new Scanner(System.in); + + @Override + public int hashCode() { + int hash = 3; + hash = 79 * hash + Objects.hashCode(this.name); + hash = 79 * hash + Objects.hashCode(this.forname); + return hash; + } + + + + public Person(){ + + } + + public Person(String name, String forname) { + this.name = name; + this.forname = forname; + } + + public String getName() { + return name; + } + + public String getForname() { + return forname; + } + + public void setName(String name) { + this.name = name; + } + + public void setForname(String forname) { + this.forname = forname; + } + + @Override + public String toString() { + StringBuilder sb =new StringBuilder(); + sb.append("Person{"); + sb.append("name=").append(name); + sb.append(", forname=").append(forname); + sb.append('}'); + return sb.toString(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Person other = (Person) obj; + if (!Objects.equals(this.name, other.name)) { + return false; + } + return Objects.equals(this.forname, other.forname); + } +} diff --git a/src/main/java/models/Inn.java b/src/main/java/models/Inn.java index 3ccf493faec233118b0b3916d4f97052b2281075..4eea54433ceb0e1269a1381e28d19ff0e4038340 100644 --- a/src/main/java/models/Inn.java +++ b/src/main/java/models/Inn.java @@ -1,14 +1,40 @@ /* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */ package models; +import models.DTO.Attendance; +import java.time.LocalDate; +import java.util.Date; +import java.util.HashSet; +import java.util.TreeSet; + /** * - * @author ramzi + * @author stag + * */ -public class Inn { +public class Inn extends TreeSet { + LocalDate date; // la date de l'evenement + TreeSet attendances;// la "liste" des particiations + + public Inn() { + super(); + } + public Inn(LocalDate date) { + this(); + this.date = date; + } + + + public LocalDate getDate() { + return date; + } + + public void setDate(LocalDate date) { + this.date = date; + } + }