diff --git a/specifications.md b/specifications.md index 2341c15901160ab223923688385360c320cfad0a..6e4b92a46268dbbf0bf70e2e4032487ca883828b 100644 --- a/specifications.md +++ b/specifications.md @@ -2,18 +2,18 @@ Projet: Meet us Ateur: Marc Vachon Date: 19 octobre 2018 -Description: +### Description: Application facilitant le rendez-vous de personne (minimum 2). Avec les paramètres entré par les utilisateurs le serveur retourne le rendez-vous le plus optimal pour le groupe de personne. Les trajets sont calculés par rapport aux transport publique de la suisse. -Technologies: - scala, +###Technologies: + Java, transport api, google map -Paramètres utilisateurs: +###Paramètres utilisateurs: durée rencontre, jour possible, plage horaires, @@ -21,7 +21,7 @@ Paramètres utilisateurs: emplacement personne, (prix maximum) -Recherche serveur: +###Recherche serveur: moyenne jour possible, moyenne heures possible, calcul centre géographique, @@ -31,12 +31,12 @@ Recherche serveur: calcul des trajets de chacun, Trouver la bonne heure -Resultat: +###Resultat: heure et jour du rdv, un trajet por chacun, (prix du trajet) -Algorithmes: +###Algorithmes: Trouver le centre de plusieurs points: - barycentre - calcul de n points: x: ∑x/n y: ∑y/n diff --git a/src/Appointment.java b/src/Appointment.java new file mode 100644 index 0000000000000000000000000000000000000000..339e5a92b2febde047f8aa65531219b178b69926 --- /dev/null +++ b/src/Appointment.java @@ -0,0 +1,74 @@ +import java.util.*; + +public class Appointment { + + MyDate f_date; + ArrayList<MyDate> t_date; + + public Appointment(ArrayList<MyDate> table_date) { + this.t_date = table_date; + + Scanner sc = new Scanner(System.in); + + System.out.println("--------------------------------------------------"); + System.out.println("Durée"); + System.out.println("Fini"); + + System.out.println("--------------------------------------------------"); + System.out.println("Calcul de la date et heure idéal..."); + this.most_popular_date(); + System.out.println("Rendez-vous fixé le: " + + this.f_date.get_day() + "/" + + this.f_date.get_month() + "/" + + this.f_date.get_year()); + + System.out.println("Fini"); + } + + /** + * [most_popular_date description] + */ + private void most_popular_date(){ + //-1 cause after dates compares hiself once + int c = 0; + int tmp = 0; + + // Compare each date with each other in the table + for(MyDate date1: this.t_date){ + + for(MyDate date2: this.t_date){ + if(compare_date(date1, date2)) + c++; + } + // if date's most popular + if(c > tmp){ + tmp = c; + this.f_date = date1; + } + // reset + c = -1; + } + } + + private void right_period(){ + for(MyDate d: this.t_date){ + } + } + + /** + * Compare 2 dates + * @param d1 Date format, first date + * @param d2 Date format, second date + * @return true if dates are the same + */ + private Boolean compare_date(MyDate d1, MyDate d2){ + if(d1.get_day() == d2.get_day()){ + if(d1.get_month() == d2.get_month()){ + if(d1.get_year() == d2.get_year()){ + return true; + } + } + } + return false; + } +} diff --git a/src/City.java b/src/City.java index 673f95fbd753e99e3bfec92945b74692c58a6fef..555412acc34a092e32d1ced8d8df0a101021c18b 100644 --- a/src/City.java +++ b/src/City.java @@ -1,4 +1,4 @@ -import java.util.ArrayList; +import java.util.*; public class City { @@ -6,10 +6,21 @@ public class City { private String city; private ArrayList<Location> t_loc; + private Boolean library = false; + private Boolean university = false; public City(ArrayList<Location> table_loc) { this.t_loc = table_loc; + Scanner sc = new Scanner(System.in); + + System.out.println("--------------------------------------------------"); + System.out.println("Paramètres pour le choix de la ville:"); + System.out.println("Besoin d'une bibliothèque ? (y/n)"); + if(sc.nextLine().equals("y")) + this.library = true; + System.out.println("Fini"); + System.out.println("--------------------------------------------------"); System.out.println("Calcul du centre géogrpahique..."); this.calcul_geo_center(); @@ -17,11 +28,11 @@ public class City { System.out.println("Fini"); System.out.println("--------------------------------------------------"); - System.out.println("Correction centre par rapport aux poids"); + System.out.println("Correction centre par rapport aux poids..."); System.out.println("Fini"); System.out.println("--------------------------------------------------"); - System.out.println("Choix de la ville"); + System.out.println("Choix de la ville..."); System.out.println("Fini"); } @@ -48,8 +59,15 @@ public class City { this.t_loc.forEach((l) -> System.out.println("x: " + l.get_x() + ", y: " + l.get_y())); } - private void set_city_params(){ - + /** + * Print all city parameters state + */ + public void show_params(){ + System.out.println("--------------------------------------------------"); + System.out.println("Paramètres de la ville:"); + System.out.println("Bibliothèque: " + this.library); + System.out.println("Université: " + this.university); + System.out.println("Fini"); } /** diff --git a/src/Date.java b/src/Date.java deleted file mode 100644 index bbcb915ed5caae4e05e9033b04f4384995c8d903..0000000000000000000000000000000000000000 --- a/src/Date.java +++ /dev/null @@ -1,25 +0,0 @@ -public class Date{ - - private int day; - private int month; - private int year; - - public Date(int d, int m, int y){ - this.day = d; - this.month = m; - this.year = y; - } - - public int get_day(){ - return this.day; - } - - public int get_month(){ - return this.month; - } - - public int get_year(){ - return this.year; - } - -} diff --git a/src/Ideal_date.java b/src/Ideal_date.java deleted file mode 100644 index 32f252bc2c1f2894021a602a6d33182fbfb94988..0000000000000000000000000000000000000000 --- a/src/Ideal_date.java +++ /dev/null @@ -1,27 +0,0 @@ -import java.util.ArrayList; - -public class Ideal_date { - - Date day_final; - ArrayList<Date> t_date; - - public Ideal_date(ArrayList<Date> table_date) { - this.t_date = table_date; - } - /* - public void calcul_day(){ - int d, m, y; - int[] t_d, t_m, t_y; - - - - } - - - private int most_popular(int[] table){ - - - - - }*/ -} diff --git a/src/LibUtil.inc.java b/src/LibUtil.inc.java index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..8f78d2a06d25bea058aded78a154335b41238671 100644 --- a/src/LibUtil.inc.java +++ b/src/LibUtil.inc.java @@ -0,0 +1,11 @@ +/* + public final String ANSI_RESET = "\u001B[0m"; + public final String ANSI_BLACK = "\u001B[30m"; + public final String ANSI_RED = "\u001B[31m"; + public final String ANSI_GREEN = "\u001B[32m"; + public final String ANSI_YELLOW = "\u001B[33m"; + public final String ANSI_BLUE = "\u001B[34m"; + public final String ANSI_PURPLE = "\u001B[35m"; + public final String ANSI_CYAN = "\u001B[36m"; + public final String ANSI_WHITE = "\u001B[37m"; +*/ diff --git a/src/Meeting.java b/src/Meeting.java index 144d45636bd3df7f1686e56b4510b487e5250f06..ac9c80a58e68c3f4eb8c63ff484b5adb75ffb731 100644 --- a/src/Meeting.java +++ b/src/Meeting.java @@ -1,29 +1,26 @@ import java.util.*; import java.net.*; import java.io.*; - +import java.util.Date; +import java.text.SimpleDateFormat; public class Meeting{ - public final String ANSI_RESET = "\u001B[0m"; - public final String ANSI_BLACK = "\u001B[30m"; - public final String ANSI_RED = "\u001B[31m"; - public final String ANSI_GREEN = "\u001B[32m"; - public final String ANSI_YELLOW = "\u001B[33m"; - public final String ANSI_BLUE = "\u001B[34m"; - public final String ANSI_PURPLE = "\u001B[35m"; - public final String ANSI_CYAN = "\u001B[36m"; - public final String ANSI_WHITE = "\u001B[37m"; - private static ArrayList<User> table_User; - - public static void main(String[] args) { table_User = new ArrayList<User>(); + String date = "14/03/2019"; + System.out.println(date_validity(date)); + + set_t_user(); + ArrayList<MyDate> calendar = get_calendar(); + + print_calendar(calendar); + System.out.println("--------------------------------------------------"); System.out.println("Voici les utilisateurs entrer :"); table_User.forEach((u) -> print_user(u)); @@ -34,20 +31,9 @@ public class Meeting{ table_User.forEach((u) -> t_loc.add(u.get_location())); System.out.println("Fini"); - /* - System.out.println("Table locations:"); - t_loc.show_locs(); - System.out.println(); - */ - - City city = new City(t_loc); - - - System.out.println("--------------------------------------------------"); - System.out.println("Calcul de la date et heure idéal..."); - System.out.println("Fini"); + Appointment appointment = new Appointment(calendar); System.out.println("--------------------------------------------------"); System.out.println("Validation des données..."); @@ -60,18 +46,36 @@ public class Meeting{ System.out.println("--------------------------------------------------"); System.out.println("Rendus des résultats..."); System.out.println("Fini"); - - } - private static void init_gen_param(){ + /** + * Print all user data + * @param user [description] + */ + private static void print_user(User user){ + System.out.println("Utilisateur :"); + System.out.println("Coordonées x, y: " + user.get_location().get_x() + ", " + user.get_location().get_y()); + System.out.println("Date possible :"); + user.get_calendar().forEach((d) -> System.out.println(d.get_day() + "/" + d.get_month() + "/" + d.get_year())); + System.out.println(); } /** - * Set all users with: - * their location - * their calendar + * Print all date from a dates table + * @param cal ArrayList<MyDate>, array of date */ + private static void print_calendar(ArrayList<MyDate> cal){ + System.out.println("--------------------------------------------------"); + System.out.println("General calendar"); + cal.forEach((d) -> System.out.println(d.get_day() + "/" + d.get_month() + "/" + d.get_year())); + System.out.println("Fini"); + } + + /** + * Set all users with: + * their location, + * their calendar + */ private static void set_t_user(){ System.out.println("Bonjour, veuillez entrer les informations utilisateur:"); @@ -85,63 +89,108 @@ public class Meeting{ float posy = Float.parseFloat(sc.nextLine()); System.out.println("Vous avez saisi : " + posx + ", " + posy); - ArrayList<Date> t_date = set_user_date(); + ArrayList<MyDate> t_date = set_date(); new_user(posx, posy, t_date); - System.out.println("Avez-vous fini d'entrer les utilisateurs ? (y/n)"); - if(sc.nextLine().equals("y")) - end = true; + if(table_User.size() >= 2){ + System.out.println("--------------------------------------------------"); + System.out.println("Avez-vous fini d'entrer les utilisateurs ? (y/n)"); + if(sc.nextLine().equals("y")) + end = true; + } } } /** - * Set table of date's user - * @return ArrayList of date - */ - private static ArrayList<Date> set_user_date(){ - ArrayList<Date> t_date = new ArrayList<Date>(); + * Set table of date's user + * @return ArrayList of date + */ + private static ArrayList<MyDate> set_date(){ + ArrayList<MyDate> t_date = new ArrayList<MyDate>(); boolean end = false; Scanner sc = new Scanner(System.in); while(!end){ - System.out.println("Date possible (jour/mois):"); - String[] date = sc.nextLine().split("/"); - System.out.println("Vous avez saisi : " + date[0] + "/" + date[1] + "/2019 de " + " à "); - - Date d = new Date(Integer.parseInt(date[0]), Integer.parseInt(date[1]), 2019); - t_date.add(d); - - System.out.println("Avez-vous entrer toutes les t_date ? (y/n)"); - if(sc.nextLine().equals("y")) + System.out.println("Date possible (jour/mois heure:min heure:min):"); + String[] line = sc.nextLine().split(" "); + + if(line.length == 3){ + String[] date = line[0].split("/"); + String[] from = line[1].split(":"); + String[] to = line[2].split(":"); + + System.out.println("Vous avez saisi : " + + date[0] + "/" + date[1] + "/2019 de " + + from[0] + ":" + from[1] + " à " + + to[0] + ":" + to[1]); + + MyDate d = new MyDate(new int[]{Integer.parseInt(date[0]), Integer.parseInt(date[1]), 2019}, + new int[]{Integer.parseInt(from[0]), Integer.parseInt(from[1])}, + new int[]{Integer.parseInt(to[0]), Integer.parseInt(to[1])}); + + t_date.add(d); + //calendar.add(d); + // + System.out.println("--------------------------------------------------"); + System.out.println("Avez-vous entrer toutes les t_date ? (y/n)"); + if(sc.nextLine().equals("y")) end = true; + }else{ + System.out.println("La date doit être entrée comme montré."); + } } return t_date; } /** - * Create and add a new user in the table - * @param posx [description] - * @param posy [description] - * @param d [description] - */ - private static void new_user(float posx, float posy, ArrayList<Date> d){ + * Create and add a new user in the table + * @param posx [description] + * @param posy [description] + * @param d [description] + */ + private static void new_user(float posx, float posy, ArrayList<MyDate> d){ User u = new User(posx, posy, d); table_User.add(u); } /** - * Print all user data - * @param user [description] + * Concat all user's calendar + * @return ArrayList<MyDate>, calendar of date */ - private static void print_user(User user){ - System.out.println("Utilisateur :"); - System.out.println("Coordonées x, y: " + user.get_location().get_x() + ", " + user.get_location().get_y()); - System.out.println("Date possible :"); - user.get_calendar().forEach((d) -> System.out.println(d.get_day() + "/" + d.get_month() + "/" + d.get_year())); - System.out.println(); + private static ArrayList<MyDate> get_calendar(){ + ArrayList<MyDate> calendar = new ArrayList<MyDate>(); + + for(User u: table_User) + calendar.addAll(u.get_calendar()); // concat ArrayList + + return calendar; + } + + private static Boolean date_validity(String d1){ + Boolean error = false; + + Date d2 = new Date(); // this object contains the current date value + SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); + + Date date = new SimpleDateFormat("dd/MM/yyyy").parse(d1); + return new Date().before(date); + } +/* + private static int[] get_current_date(){ + Date currentDate = new Date(); // this object contains the current date value + SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); + System.out.println(formatter.format(currentDate)); + + String[] tmp = formatter.format(currentDate).split("-"); + int[] date = {0,0,0}; + for(int i = 0; i < tmp.length(); i++){ + date[i] = tmp[i]; + } + return date; + }*/ } diff --git a/src/MyDate.java b/src/MyDate.java new file mode 100644 index 0000000000000000000000000000000000000000..ae7bed4b1f1c5a0454e35d612cdbad76fe9fe05c --- /dev/null +++ b/src/MyDate.java @@ -0,0 +1,51 @@ +public class MyDate{ + + private int day; + private int month; + private int year; + + private Time from; + private Time to; + + public MyDate(int[] date, int[] from, int[] to){ + this.day = date[0]; + this.month = date[1]; + this.year = date[2]; + + this.from = new Time(from[0], from[1]); + this.to = new Time(to[0], to[1]); + } + + public int get_day(){ + return this.day; + } + + public int get_month(){ + return this.month; + } + + public int get_year(){ + return this.year; + } + + public int[] get_t_from(){ + int[] table = {this.from.hour, this.from.minutes}; + return table; + } + + public int[] get_t_to(){ + int[] table = {this.to.hour, this.to.minutes}; + return table; + } + +} + +class Time{ + int hour; + int minutes; + + Time(int h, int m){ + this.hour = h; + this.minutes = m; + } +} diff --git a/src/User.java b/src/User.java index 7713962a8973d1ac6b19475972bac5326ddc834c..7ec997ebed51a86d557b9c141d2278a22b141dce 100644 --- a/src/User.java +++ b/src/User.java @@ -4,39 +4,60 @@ import java.io.*; public class User { - private Location location; // location x, y - private ArrayList<Date> calendar = new ArrayList<Date>(); + private ArrayList<MyDate> calendar = new ArrayList<MyDate>(); private Path path; - - public User(float x, float y, ArrayList<Date> dates) { + /** + * User constructor + * @param x float, coordinate x + * @param y float, coordinate y + * @param dates ArrayList<MyDate>, table of possible dates + */ + public User(float x, float y, ArrayList<MyDate> dates) { this.location = new Location(x, y); this.calendar = dates; } - + /** + * Get coordinate of the user + * @return Location + */ public Location get_location(){ return this.location; } + /** + * Get all possible dates from the user + * @return ArrayList<MyDate>, table of dates + */ + public ArrayList<MyDate> get_calendar(){ + return this.calendar; + } + + /** + * Set locaton coordinate x and y + * @param x Float, Coordinate x + * @param y Float, Coordinate y + */ public void set_location(float x, float y){ this.location.set_x(x); this.location.set_y(y); } - public ArrayList<Date> get_calendar(){ - return this.calendar; - } - - public void add_Date(int day, int month, int year){ - - Date d = new Date(day, month, year); + /** + * Add a Date in the calendar + * @param date int[] + * @param from int[] + * @param to int[] + */ + public void add_Date(int[] date, int[] from, int[] to){ + MyDate d = new MyDate(date, from, to); this.calendar.add(d); } public void calcul_path(){ - + } } diff --git a/src/makefile b/src/makefile new file mode 100644 index 0000000000000000000000000000000000000000..69ece4ef82e330ace8619c5396ef2f55002a161c --- /dev/null +++ b/src/makefile @@ -0,0 +1,30 @@ +JFLAGS = -g +JC = javac +JVM= java + +.SUFFIXES: .java .class + +.java.class: + $(JC) $(JFLAGS) $*.java + +CLASSES = \ + Foo.java \ + Blah.java \ + Library.java \ + Main.java + + +MAIN = Meeting + +default: classes + + +classes: $(CLASSES:.java=.class) + + +run: $(MAIN).class + $(JVM) $(MAIN) + + +clean: + $(RM) *.class