From b794b35db8d7b825aa4e6974ddc2f1d61c2ff62a Mon Sep 17 00:00:00 2001 From: Kevin Santiago Rey Date: Thu, 11 Jan 2024 00:11:36 +0100 Subject: [PATCH 1/5] feat(first): first problem --- .idea/.gitignore | 8 ++ level1/pom.xml | 17 +++ .../main/java/org/com/level/Manchester.java | 133 ++++++++++++++++++ .../src/main/java/org/com/level/Player.java | 11 ++ 4 files changed, 169 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 level1/pom.xml create mode 100644 level1/src/main/java/org/com/level/Manchester.java create mode 100644 level1/src/main/java/org/com/level/Player.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/level1/pom.xml b/level1/pom.xml new file mode 100644 index 0000000..6904600 --- /dev/null +++ b/level1/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.example + level1 + 1.0-SNAPSHOT + + + 21 + 21 + UTF-8 + + + \ No newline at end of file diff --git a/level1/src/main/java/org/com/level/Manchester.java b/level1/src/main/java/org/com/level/Manchester.java new file mode 100644 index 0000000..080b618 --- /dev/null +++ b/level1/src/main/java/org/com/level/Manchester.java @@ -0,0 +1,133 @@ +package org.com.level; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Locale; +import java.util.Map; +import java.util.Scanner; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collector; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class Manchester { + public static final Map> COMPARATOR = Map.of( + "goals", Comparator.comparingInt(Player :: goals), + "speed", Comparator.comparingInt(Player :: speed), + "assists", Comparator.comparingInt(Player :: assists), + "passing", Comparator.comparingInt(Player :: passingAccuracy), + "defensivePlayer", + Comparator.comparingInt(Player :: passingAccuracy) + ); + private static Scanner scanner = new Scanner(System.in); + private static Map manchester = Map.of( + 8, new Player("Bruno Fernandes", 5, 6, 9, 10, 3, 8), + 11, new Player("Rasmus Hojlund", 12, 8, 2, 6, 2, 11), + 5, new Player("Harry Maguire", 1, 5, 1, 7, 9, 5), + 1, new Player("Alejandro Garnacho", 8, 7, 8, 6, 0, 17), + 7, new Player("Mason Mount", 2, 6, 14, 8, 1, 7) + ); + + public static void main(String[] args) { + var shouldContinue = true; + while (shouldContinue) { + printMenu(); + switch (scanner.nextInt()) { + case 1 -> { + System.out.println("give the jersey number"); + System.out.println(manchester.get(scanner.nextInt())); + } + case 2 -> { + requireData result = getRequireData(); + var playerMap = getComparationMap( + result.statistics(), + result.player1(), + result.player2(), + COMPARATOR); + printComparation(playerMap); + } + case 3 -> printTopPlayerByStatistic("speed"); + case 4 -> printTopPlayerByStatistic("goals"); + case 5 -> printTopPlayerByStatistic("assists"); + case 6 -> printTopPlayerByStatistic("passing"); + case 7 -> printTopPlayerByStatistic("defensivePlayer"); + case 9 -> shouldContinue = false; + } + } + } + + private static void printTopPlayerByStatistic(String st) { + System.out.println(manchester.values().stream().max(COMPARATOR.get(st)).get()); + } + + private static requireData getRequireData() { + var statistics = new ArrayList(); + System.out.println("give the jersey number of player one"); + var player1 = manchester.get(scanner.nextInt()); + System.out.println("give the jersey number of player two"); + var player2 = manchester.get(scanner.nextInt()); + + var shouldAksStatistic = true; + while (shouldAksStatistic) { + System.out.println("Select player's statistic to compare. 'Q' to stop"); + String next = scanner.next().toLowerCase(Locale.ROOT); + shouldAksStatistic = (! next.equals("q")) && statistics.add(next); + } + return new requireData(statistics, player1, player2); + } + + private record requireData( + ArrayList statistics, Player player1, Player player2 + ) {} + + private static Map getComparationMap(ArrayList statistics, + Player player1, Player player2 + , Map> comparator) { + return statistics + .stream() + .map(comparatorFromStatisticToStaAndPlayer(player1, player2, comparator)) + .collect(makeAMap()); + } + + private static void printComparation(Map list) { + list.forEach((key, player) -> System.out.println("Statistic: " + key + " Player" + + ":" + player.name())); + } + + private static Collector, ?, Map> makeAMap() { + return Collectors.toMap(Map.Entry :: getKey, Map.Entry :: getValue); + } + + private static Function> comparatorFromStatisticToStaAndPlayer(Player player1, Player player2, Map> comparator) { + return st -> Map.entry(st, + Stream.of(player1, player2).max(comparator.get(st)).get()); + } + + private static void printMenu() { + System.out.println("1) Show player characteristics by Jersey Number"); + System.out.println("2) Compare two players"); + System.out.println("3) Show the fastest player"); + System.out.println("4) Show the top goal scorer"); + System.out.println("5) Show the player with most assist"); + System.out.println("6) Show the highest passing accuracy"); + System.out.println("7) Show the better defense player"); + System.out.println("8) to exit...!"); + } + + public static Player searchBy(String characteristic, int comparator) { + Map> playerMap = Map.of( + "goals", player -> player.goals().equals(comparator), + "speed", player -> player.speed().equals(comparator), + "assists", player -> player.assists().equals(comparator), + "accurate", player -> player.passingAccuracy().equals(comparator), + "defensivePlayer", player -> player.defensive().equals(comparator) + ); + return manchester + .values() + .stream() + .filter(playerMap.get(characteristic)) + .findFirst() + .orElseGet(() -> new Player("", 0, 0, 0, 0, 0, 0)); + } +} diff --git a/level1/src/main/java/org/com/level/Player.java b/level1/src/main/java/org/com/level/Player.java new file mode 100644 index 0000000..7f24f08 --- /dev/null +++ b/level1/src/main/java/org/com/level/Player.java @@ -0,0 +1,11 @@ +package org.com.level; + +public record Player (String name, + Integer goals, + Integer speed, + Integer assists, + Integer passingAccuracy, + Integer defensive, + Integer jerseyNumber) +{ +} From eff56f5d5adbee9e7efa64a4d608727a62ccbd95 Mon Sep 17 00:00:00 2001 From: Kevin Santiago Rey Date: Thu, 11 Jan 2024 17:04:55 +0100 Subject: [PATCH 2/5] feat(first): refactor classes --- .../main/java/org/com/level/Manchester.java | 133 ------------------ .../src/main/java/org/com/level/Player.java | 11 -- .../org/com/level/manchester/Manchester.java | 87 ++++++++++++ .../java/org/com/level/manchester/Player.java | 36 +++++ .../org/com/level/manchester/Printer.java | 31 ++++ 5 files changed, 154 insertions(+), 144 deletions(-) delete mode 100644 level1/src/main/java/org/com/level/Manchester.java delete mode 100644 level1/src/main/java/org/com/level/Player.java create mode 100644 level1/src/main/java/org/com/level/manchester/Manchester.java create mode 100644 level1/src/main/java/org/com/level/manchester/Player.java create mode 100644 level1/src/main/java/org/com/level/manchester/Printer.java diff --git a/level1/src/main/java/org/com/level/Manchester.java b/level1/src/main/java/org/com/level/Manchester.java deleted file mode 100644 index 080b618..0000000 --- a/level1/src/main/java/org/com/level/Manchester.java +++ /dev/null @@ -1,133 +0,0 @@ -package org.com.level; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.Locale; -import java.util.Map; -import java.util.Scanner; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.stream.Collector; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class Manchester { - public static final Map> COMPARATOR = Map.of( - "goals", Comparator.comparingInt(Player :: goals), - "speed", Comparator.comparingInt(Player :: speed), - "assists", Comparator.comparingInt(Player :: assists), - "passing", Comparator.comparingInt(Player :: passingAccuracy), - "defensivePlayer", - Comparator.comparingInt(Player :: passingAccuracy) - ); - private static Scanner scanner = new Scanner(System.in); - private static Map manchester = Map.of( - 8, new Player("Bruno Fernandes", 5, 6, 9, 10, 3, 8), - 11, new Player("Rasmus Hojlund", 12, 8, 2, 6, 2, 11), - 5, new Player("Harry Maguire", 1, 5, 1, 7, 9, 5), - 1, new Player("Alejandro Garnacho", 8, 7, 8, 6, 0, 17), - 7, new Player("Mason Mount", 2, 6, 14, 8, 1, 7) - ); - - public static void main(String[] args) { - var shouldContinue = true; - while (shouldContinue) { - printMenu(); - switch (scanner.nextInt()) { - case 1 -> { - System.out.println("give the jersey number"); - System.out.println(manchester.get(scanner.nextInt())); - } - case 2 -> { - requireData result = getRequireData(); - var playerMap = getComparationMap( - result.statistics(), - result.player1(), - result.player2(), - COMPARATOR); - printComparation(playerMap); - } - case 3 -> printTopPlayerByStatistic("speed"); - case 4 -> printTopPlayerByStatistic("goals"); - case 5 -> printTopPlayerByStatistic("assists"); - case 6 -> printTopPlayerByStatistic("passing"); - case 7 -> printTopPlayerByStatistic("defensivePlayer"); - case 9 -> shouldContinue = false; - } - } - } - - private static void printTopPlayerByStatistic(String st) { - System.out.println(manchester.values().stream().max(COMPARATOR.get(st)).get()); - } - - private static requireData getRequireData() { - var statistics = new ArrayList(); - System.out.println("give the jersey number of player one"); - var player1 = manchester.get(scanner.nextInt()); - System.out.println("give the jersey number of player two"); - var player2 = manchester.get(scanner.nextInt()); - - var shouldAksStatistic = true; - while (shouldAksStatistic) { - System.out.println("Select player's statistic to compare. 'Q' to stop"); - String next = scanner.next().toLowerCase(Locale.ROOT); - shouldAksStatistic = (! next.equals("q")) && statistics.add(next); - } - return new requireData(statistics, player1, player2); - } - - private record requireData( - ArrayList statistics, Player player1, Player player2 - ) {} - - private static Map getComparationMap(ArrayList statistics, - Player player1, Player player2 - , Map> comparator) { - return statistics - .stream() - .map(comparatorFromStatisticToStaAndPlayer(player1, player2, comparator)) - .collect(makeAMap()); - } - - private static void printComparation(Map list) { - list.forEach((key, player) -> System.out.println("Statistic: " + key + " Player" + - ":" + player.name())); - } - - private static Collector, ?, Map> makeAMap() { - return Collectors.toMap(Map.Entry :: getKey, Map.Entry :: getValue); - } - - private static Function> comparatorFromStatisticToStaAndPlayer(Player player1, Player player2, Map> comparator) { - return st -> Map.entry(st, - Stream.of(player1, player2).max(comparator.get(st)).get()); - } - - private static void printMenu() { - System.out.println("1) Show player characteristics by Jersey Number"); - System.out.println("2) Compare two players"); - System.out.println("3) Show the fastest player"); - System.out.println("4) Show the top goal scorer"); - System.out.println("5) Show the player with most assist"); - System.out.println("6) Show the highest passing accuracy"); - System.out.println("7) Show the better defense player"); - System.out.println("8) to exit...!"); - } - - public static Player searchBy(String characteristic, int comparator) { - Map> playerMap = Map.of( - "goals", player -> player.goals().equals(comparator), - "speed", player -> player.speed().equals(comparator), - "assists", player -> player.assists().equals(comparator), - "accurate", player -> player.passingAccuracy().equals(comparator), - "defensivePlayer", player -> player.defensive().equals(comparator) - ); - return manchester - .values() - .stream() - .filter(playerMap.get(characteristic)) - .findFirst() - .orElseGet(() -> new Player("", 0, 0, 0, 0, 0, 0)); - } -} diff --git a/level1/src/main/java/org/com/level/Player.java b/level1/src/main/java/org/com/level/Player.java deleted file mode 100644 index 7f24f08..0000000 --- a/level1/src/main/java/org/com/level/Player.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.com.level; - -public record Player (String name, - Integer goals, - Integer speed, - Integer assists, - Integer passingAccuracy, - Integer defensive, - Integer jerseyNumber) -{ -} diff --git a/level1/src/main/java/org/com/level/manchester/Manchester.java b/level1/src/main/java/org/com/level/manchester/Manchester.java new file mode 100644 index 0000000..850d980 --- /dev/null +++ b/level1/src/main/java/org/com/level/manchester/Manchester.java @@ -0,0 +1,87 @@ +package org.com.level.manchester; + +import java.util.ArrayList; +import java.util.Locale; +import java.util.Map; +import java.util.Scanner; +import java.util.function.Supplier; + +import static org.com.level.manchester.Printer.printComparative; +import static org.com.level.manchester.Printer.printMenu; +import static org.com.level.manchester.Printer.print; +import static org.com.level.manchester.Printer.printTopPlayerByStatistic; + +public class Manchester { + private static final Scanner scanner = new Scanner(System.in); + static final Map manchester = Map.of( + 8, new Player("Bruno Fernandes", 5, 6, 9, 10, 3, 8), + 11, new Player("Rasmus Hojlund", 12, 8, 2, 6, 2, 11), + 5, new Player("Harry Maguire", 1, 5, 1, 7, 9, 5), + 1, new Player("Alejandro Garnacho", 8, 7, 8, 6, 0, 17), + 7, new Player("Mason Mount", 2, 6, 14, 8, 1, 7) + ); + + public static void main(String[] args) { + repeat(Manchester::statisticsProcess); + } + + private static boolean statisticsProcess() { + printMenu(); + switch (scanner.nextInt()) { + case 1 -> { + print("give the jersey number"); + print(getPlayer()); + } + case 2 -> { + var results = compareTwoPlayers(); + printComparative(results); + } + case 3 -> printTopPlayerByStatistic("speed"); + case 4 -> printTopPlayerByStatistic("goals"); + case 5 -> printTopPlayerByStatistic("assists"); + case 6 -> printTopPlayerByStatistic("passing"); + case 7 -> printTopPlayerByStatistic("defensivePlayer"); + case 9 -> {return false;} + } + return true; + } + + private static Map compareTwoPlayers() { + var selected = getRequireData(); + return Player + .getComparativeFor(selected.statistics(), + selected.player1(), + selected.player2()); + } + + private static Player getPlayer() { + return manchester.get(scanner.nextInt()); + } + + private static SubmitedData getRequireData() { + var statistics = new ArrayList(); + print("give the jersey number of player one"); + var player1 = getPlayer(); + print("give the jersey number of player two"); + var player2 = getPlayer(); + repeat( + () -> { + print("Select player's statistic to compare. 'Q' to stop"); + String next = scanner.next().toLowerCase(Locale.ROOT); + return (! next.equals("q")) && statistics.add(next); + } + ); + return new SubmitedData(statistics, player1, player2); + } + + private static void repeat(Supplier fun) { + var shouldContinue = true; + while (shouldContinue) { + shouldContinue = fun.get(); + } + } + + private record SubmitedData( + ArrayList statistics, Player player1, Player player2 + ) {} +} diff --git a/level1/src/main/java/org/com/level/manchester/Player.java b/level1/src/main/java/org/com/level/manchester/Player.java new file mode 100644 index 0000000..fdcda1d --- /dev/null +++ b/level1/src/main/java/org/com/level/manchester/Player.java @@ -0,0 +1,36 @@ +package org.com.level.manchester; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public record Player (String name, + Integer goals, + Integer speed, + Integer assists, + Integer passingAccuracy, + Integer defensive, + Integer jerseyNumber) +{ + public static final Map> COMPARATORS = Map.of( + "goals", Comparator.comparingInt(Player :: speed), + "speed", Comparator.comparingInt(Player :: speed), + "assists", Comparator.comparingInt(Player :: assists), + "passing", Comparator.comparingInt(Player :: passingAccuracy), + "defensivePlayer", Comparator.comparingInt(Player :: passingAccuracy)); + + static Map getComparativeFor(ArrayList statistics, + Player player1, Player player2) { + return statistics + .stream() + .map(comparePlayers(player1, player2)) + .collect(Collectors.toMap(Map.Entry :: getKey, Map.Entry :: getValue)); + } + + private static Function> comparePlayers(Player player1, Player player2) { + return st -> Map.entry(st, Stream.of(player1, player2).max(COMPARATORS.get(st)).get()); + } +} diff --git a/level1/src/main/java/org/com/level/manchester/Printer.java b/level1/src/main/java/org/com/level/manchester/Printer.java new file mode 100644 index 0000000..fc3c8ef --- /dev/null +++ b/level1/src/main/java/org/com/level/manchester/Printer.java @@ -0,0 +1,31 @@ +package org.com.level.manchester; + +import java.util.Map; + +public class Printer { + + static void printMenu() { + System.out.println("1) Show player characteristics by Jersey Number"); + System.out.println("2) Compare two players"); + System.out.println("3) Show the fastest player"); + System.out.println("4) Show the top goal scorer"); + System.out.println("5) Show the player with most assist"); + System.out.println("6) Show the highest passing accuracy"); + System.out.println("7) Show the better defense player"); + System.out.println("8) to exit...!"); + } + + static void printComparative(Map list) { + list.forEach((key, player) -> System.out.println("Statistic: " + key + " Player" + + ":" + player.name())); + } + + static void printTopPlayerByStatistic(String st) { + Player player = Manchester.manchester.values().stream().max(Player.COMPARATORS.get(st)).get(); + System.out.println(player); + } + + static void print(T x) { + System.out.println(x); + } +} From f60fb35954e3796c2a793ac7c4c253b93978bf97 Mon Sep 17 00:00:00 2001 From: Kevin Santiago Rey Date: Sat, 13 Jan 2024 12:53:32 +0100 Subject: [PATCH 3/5] feat(hospoital): add possible solution for hospital --- .../org/com/level/hospital/Authenticator.java | 56 ++++++++ .../java/org/com/level/hospital/Doctor.java | 6 + .../java/org/com/level/hospital/Main.java | 94 +++++++++++++ .../java/org/com/level/hospital/Printer.java | 21 +++ .../java/org/com/level/hospital/Slot.java | 9 ++ .../java/org/com/level/hospital/User.java | 33 +++++ .../java/org/com/level/hospital/Utils.java | 125 ++++++++++++++++++ level_1.txt | 2 +- 8 files changed, 345 insertions(+), 1 deletion(-) create mode 100644 level1/src/main/java/org/com/level/hospital/Authenticator.java create mode 100644 level1/src/main/java/org/com/level/hospital/Doctor.java create mode 100644 level1/src/main/java/org/com/level/hospital/Main.java create mode 100644 level1/src/main/java/org/com/level/hospital/Printer.java create mode 100644 level1/src/main/java/org/com/level/hospital/Slot.java create mode 100644 level1/src/main/java/org/com/level/hospital/User.java create mode 100644 level1/src/main/java/org/com/level/hospital/Utils.java diff --git a/level1/src/main/java/org/com/level/hospital/Authenticator.java b/level1/src/main/java/org/com/level/hospital/Authenticator.java new file mode 100644 index 0000000..dbe27c8 --- /dev/null +++ b/level1/src/main/java/org/com/level/hospital/Authenticator.java @@ -0,0 +1,56 @@ + +package org.com.level.hospital; + +import java.util.Scanner; +import java.util.function.BiPredicate; + + +public class Authenticator { + private Scanner scanner = new Scanner(System.in); + public Boolean isLogged = false; + + void shouldLogOut() { + System.out.println("Do you want to continue? "); + String next = scanner.next(); + if (next.equalsIgnoreCase("no")) { + Main.authenticator.isLogged = false; + } + } + + private void printMessage(String x) { + System.out.println(x); + } + + public void authProcessFor(int tries, + User user) { + var isLoged = false; + while (! isLoged && tries > 0) { + isLoged = authLogic().test(user.password(), user.name()); + if(!isLoged){ + printMessage("you still have " + (tries - 1) + " tries left"); + tries--; + } + } + isLogged = isLoged; + authMessage(); + } + + + private BiPredicate authLogic() { + return (passwordP, userNameP) -> { + printMessage("Enter User Name"); + var userName = scanner.next(); + printMessage("Enter Password"); + var password = scanner.next(); + return userName.equals(userNameP) && password.equals(passwordP); + }; + } + + private void authMessage() { + if (! isLogged) { + printMessage("Sorry, max try possible"); + } else { + printMessage("Welcome "); + } + } +} diff --git a/level1/src/main/java/org/com/level/hospital/Doctor.java b/level1/src/main/java/org/com/level/hospital/Doctor.java new file mode 100644 index 0000000..f8a009b --- /dev/null +++ b/level1/src/main/java/org/com/level/hospital/Doctor.java @@ -0,0 +1,6 @@ +package org.com.level.hospital; + +import java.util.List; + +public record Doctor(String speciality, String name, List slotList) { +} diff --git a/level1/src/main/java/org/com/level/hospital/Main.java b/level1/src/main/java/org/com/level/hospital/Main.java new file mode 100644 index 0000000..fc118d0 --- /dev/null +++ b/level1/src/main/java/org/com/level/hospital/Main.java @@ -0,0 +1,94 @@ +package org.com.level.hospital; + + +import java.util.List; +import java.util.Map; +import java.util.Scanner; + +import static org.com.level.hospital.Printer.printOptions; + +public class Main { + static Authenticator authenticator = new Authenticator(); + static Scanner scanner = new Scanner(System.in); + static User user; + + public static void main(String[] args) { + user = new User("lol", "pass", Map.of()); + authenticator.authProcessFor(3, user); + while (authenticator.isLogged && ! user.userHave3Appointments()) { + searchAppointment(); + authenticator.shouldLogOut(); + } + } + + + private static void searchAppointment() { + + System.out.println("Select the speciality"); + var selectedSpeciality = printOptions(Utils.specialities); + var possibleDoctors = filterDoctorsBySpeciality(selectedSpeciality); + + System.out.println("Possible Doctors for this Speciality"); + var numberSelectedDoctor = printOptions(possibleDoctors.stream() + .map(Doctor :: name) + .toList()); + var selectedDoctorByUser = possibleDoctors.get(numberSelectedDoctor); + var possibleSlots = filterSlotsByDoctorAndUser(selectedDoctorByUser); + + System.out.println("Select a free slot"); + var numberOfSelectedSlot = printOptions(possibleSlots); + + var appointment = possibleSlots.get(numberOfSelectedSlot) + .registerAppointment(); + + user = user.registerAppointment(selectedDoctorByUser, + appointment); + + Utils.doctors = updateDoctor(possibleSlots, + appointment, + selectedDoctorByUser); + + } + + private static List filterSlotsByDoctorAndUser(Doctor selectedDoctorByUser) { + return selectedDoctorByUser.slotList() + .stream() + .filter(Slot :: free) + .filter(Main :: isFreeForUser) + .toList(); + } + + private static List updateDoctor(List possibleSlots, + Slot newSlot, + Doctor selectedDoctor) + { + var updatedSlotList = possibleSlots.stream() + .map(slot -> slot.id() + .equals(newSlot.id()) ? newSlot : slot) + .toList(); + + return Utils.doctors.stream().map(doctor -> { + if (doctor.name().equals(selectedDoctor.name())) { + return new Doctor(selectedDoctor.speciality(), + selectedDoctor.name(), + updatedSlotList); + } + return doctor; + }).toList(); + } + + private static boolean isFreeForUser(Slot slot) { + return user.getUserSlotsStream() + .noneMatch(slotFromUser -> slotFromUser.timeStamp().equals(slot.timeStamp())); + } + + private static List filterDoctorsBySpeciality(int selectedSpeciality) { + return Utils.doctors.stream() + .filter(doctor -> (doctor.speciality() + .equals(Utils.specialities.get(selectedSpeciality)) && + (! user.doctorAndAppointment() + .containsKey(doctor.name())) + )).toList(); + } + +} diff --git a/level1/src/main/java/org/com/level/hospital/Printer.java b/level1/src/main/java/org/com/level/hospital/Printer.java new file mode 100644 index 0000000..eec1def --- /dev/null +++ b/level1/src/main/java/org/com/level/hospital/Printer.java @@ -0,0 +1,21 @@ +package org.com.level.hospital; + +import java.util.List; + +public class Printer { + static int printOptions(List options) { + var repeat = true; + var optionNumber = - 1; + while (repeat) { + for (int i = 0; i < options.size(); i++) { + System.out.println(i + ") para " + options.get(i)); + } + optionNumber = Main.scanner.nextInt(); + repeat = ! (optionNumber >= 0 && optionNumber <= options.size()); + if (repeat) { + System.out.println("Elegiste una option invalida intentalo de nuevo"); + } + } + return optionNumber; + } +} diff --git a/level1/src/main/java/org/com/level/hospital/Slot.java b/level1/src/main/java/org/com/level/hospital/Slot.java new file mode 100644 index 0000000..33771bb --- /dev/null +++ b/level1/src/main/java/org/com/level/hospital/Slot.java @@ -0,0 +1,9 @@ +package org.com.level.hospital; + +public record Slot(Integer id, String timeStamp, boolean free) { + Slot registerAppointment() { + return new Slot(this.id(), + this.timeStamp(), + false); + } +} diff --git a/level1/src/main/java/org/com/level/hospital/User.java b/level1/src/main/java/org/com/level/hospital/User.java new file mode 100644 index 0000000..bee4e21 --- /dev/null +++ b/level1/src/main/java/org/com/level/hospital/User.java @@ -0,0 +1,33 @@ +package org.com.level.hospital; + +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public record User(String name, + String password, + Map doctorAndAppointment) { + Stream getUserSlotsStream() { + return this.doctorAndAppointment() + .values() + .stream(); + } + + User registerAppointment(Doctor selectedDoctor, + Slot newSlot) { + var newMapSlot = + Stream.concat(this.doctorAndAppointment().entrySet().stream(), + Stream.of(Map.entry(selectedDoctor.name(), newSlot))) + .collect(Collectors.toMap(Map.Entry :: getKey, + Map.Entry :: getValue)); + return new User(this.name(), this.password(), newMapSlot); + } + + boolean userHave3Appointments() { + if (this.doctorAndAppointment().size() >= 3) { + System.out.println("Maximal Number Appointments gotten"); + return true; + } + return false; + } +} diff --git a/level1/src/main/java/org/com/level/hospital/Utils.java b/level1/src/main/java/org/com/level/hospital/Utils.java new file mode 100644 index 0000000..0c0aee4 --- /dev/null +++ b/level1/src/main/java/org/com/level/hospital/Utils.java @@ -0,0 +1,125 @@ +package org.com.level.hospital; + +import java.util.List; + +public class Utils { + static List specialities = List.of("General Medicine", + "Emergency Care", + "Clinical Analysis", + "Cardiology", + "Neurology", + "Nutrition", + "Physiotherapy", + "Traumatology", + "Internal Medicine"); + static List doctors = List.of( + new Doctor("General Medicine", "Dr. Ana Torres", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("General Medicine", "Dr. Carlos Ruiz", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("General Medicine", "Dr. Laura García", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Emergency Care", "Dr. Roberto Fernández", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Emergency Care", "Dr. Sofia Martínez", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Emergency Care", "Dr. Juan Pérez", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Clinical Analysis", "Dr. María López", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Clinical Analysis", "Dr. Jorge Gómez", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Clinical Analysis", "Dr. Patricia Díaz", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Cardiology", "Dr. Fernando Sánchez", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Cardiology", "Dr. Isabel Rodríguez", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Cardiology", "Dr. Luis Jiménez", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Neurology", "Dr. Carmen Ortiz", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Neurology", "Dr. Diego Vázquez", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Neurology", "Dr. Elena Moreno", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Nutrition", "Dr. Sara Navarro", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Nutrition", "Dr. Rafael Morales", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Nutrition", "Dr. Clara Fernández", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Physiotherapy", "Dr. José González", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Physiotherapy", "Dr. Teresa Romero", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Physiotherapy", "Dr. Daniel Castillo", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Traumatology", "Dr. Laura Martín", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Traumatology", "Dr. Miguel Ángel Soto", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Traumatology", "Dr. Beatriz Rivas", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Internal Medicine", "Dr. Óscar Domínguez", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Internal Medicine", "Dr. Alicia Vega", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))), + new Doctor("Internal Medicine", "Dr. Guillermo Alonso", List.of( + new Slot(1, "8-9", true), + new Slot(2, "9-10", true), + new Slot(3, "10-11", true))) + ); +} diff --git a/level_1.txt b/level_1.txt index 68b3ef8..996f3a7 100644 --- a/level_1.txt +++ b/level_1.txt @@ -43,7 +43,7 @@ The user can schedule an appointment for: General Medicine, Emergency Care, Clin There are 3 doctors for each specialty. The user can only book one appointment per specialist. An error message should be displayed if the user tries to choose two appointments with the same doctor or the same specialty. As a developer, you can choose the doctors' names. The maximum limit for appointments, in general, is 3. -Upon selecting a specialty, it will display if the user prefers a morning or afternoon appointment and show available hours. As a developer, you can choose the hours. +Upon selecting a specialists, it will display if the user prefers a morning or afternoon appointment and show available hours. As a developer, you can choose the hours. Display available specialists. The user can choose their preferred specialist. The basic process is: Login -> Choose specialty -> Choose doctor -> Choose time slot. From 318e13780837df12a800a8ced307911d4b466fdd Mon Sep 17 00:00:00 2001 From: Kevin Santiago Rey Date: Sat, 13 Jan 2024 19:17:08 +0100 Subject: [PATCH 4/5] feat(hospoital): add possible solution for hospital --- .../java/org/com/level/hospital/Doctor.java | 11 ++++ .../java/org/com/level/hospital/Main.java | 52 +++++++----------- .../java/org/com/level/hospital/User.java | 5 ++ .../java/org/com/level/hospital/Utils.java | 28 +++++++--- .../com/level/hospital/Authenticator.class | Bin 0 -> 3351 bytes .../org/com/level/hospital/Doctor.class | Bin 0 -> 3513 bytes .../classes/org/com/level/hospital/Main.class | Bin 0 -> 6099 bytes .../org/com/level/hospital/Printer.class | Bin 0 -> 1713 bytes .../classes/org/com/level/hospital/Slot.class | Bin 0 -> 1867 bytes .../classes/org/com/level/hospital/User.class | Bin 0 -> 4958 bytes .../org/com/level/hospital/Utils.class | Bin 0 -> 4476 bytes 11 files changed, 57 insertions(+), 39 deletions(-) create mode 100644 level1/target/classes/org/com/level/hospital/Authenticator.class create mode 100644 level1/target/classes/org/com/level/hospital/Doctor.class create mode 100644 level1/target/classes/org/com/level/hospital/Main.class create mode 100644 level1/target/classes/org/com/level/hospital/Printer.class create mode 100644 level1/target/classes/org/com/level/hospital/Slot.class create mode 100644 level1/target/classes/org/com/level/hospital/User.class create mode 100644 level1/target/classes/org/com/level/hospital/Utils.class diff --git a/level1/src/main/java/org/com/level/hospital/Doctor.java b/level1/src/main/java/org/com/level/hospital/Doctor.java index f8a009b..c534b9d 100644 --- a/level1/src/main/java/org/com/level/hospital/Doctor.java +++ b/level1/src/main/java/org/com/level/hospital/Doctor.java @@ -1,6 +1,17 @@ package org.com.level.hospital; import java.util.List; +import java.util.stream.Stream; public record Doctor(String speciality, String name, List slotList) { + Stream getFreeSlotStream(User user) { + return this.slotList().stream().filter(user :: isFreeForUser) + .filter(Slot :: free); + } + + Doctor registerAppointment(List updatedSlotList) { + return new Doctor(this.speciality(), + this.name(), + updatedSlotList); + } } diff --git a/level1/src/main/java/org/com/level/hospital/Main.java b/level1/src/main/java/org/com/level/hospital/Main.java index fc118d0..511100b 100644 --- a/level1/src/main/java/org/com/level/hospital/Main.java +++ b/level1/src/main/java/org/com/level/hospital/Main.java @@ -32,55 +32,43 @@ private static void searchAppointment() { var numberSelectedDoctor = printOptions(possibleDoctors.stream() .map(Doctor :: name) .toList()); + var selectedDoctorByUser = possibleDoctors.get(numberSelectedDoctor); var possibleSlots = filterSlotsByDoctorAndUser(selectedDoctorByUser); System.out.println("Select a free slot"); var numberOfSelectedSlot = printOptions(possibleSlots); - var appointment = possibleSlots.get(numberOfSelectedSlot) - .registerAppointment(); + var appointment = possibleSlots.get(numberOfSelectedSlot).registerAppointment(); + + user = user.registerAppointment(selectedDoctorByUser, appointment); - user = user.registerAppointment(selectedDoctorByUser, - appointment); + Doctor updatedDoctor = updateDoctorWithNewAppointment(appointment, selectedDoctorByUser); - Utils.doctors = updateDoctor(possibleSlots, - appointment, - selectedDoctorByUser); + updateDoctorsList(updatedDoctor); } + private static Doctor updateDoctorWithNewAppointment(Slot appointment, + Doctor selectedDoctorByUser) { + var updatedSlotList = selectedDoctorByUser.getFreeSlotStream(user) + .map(slot -> slot.id().equals(appointment.id()) ? appointment : slot) + .toList(); + return selectedDoctorByUser.registerAppointment(updatedSlotList); + } + private static List filterSlotsByDoctorAndUser(Doctor selectedDoctorByUser) { - return selectedDoctorByUser.slotList() - .stream() - .filter(Slot :: free) - .filter(Main :: isFreeForUser) - .toList(); + return selectedDoctorByUser.getFreeSlotStream(user).toList(); } - private static List updateDoctor(List possibleSlots, - Slot newSlot, - Doctor selectedDoctor) + private static void updateDoctorsList(Doctor selectedDoctor) { - var updatedSlotList = possibleSlots.stream() - .map(slot -> slot.id() - .equals(newSlot.id()) ? newSlot : slot) - .toList(); - - return Utils.doctors.stream().map(doctor -> { - if (doctor.name().equals(selectedDoctor.name())) { - return new Doctor(selectedDoctor.speciality(), - selectedDoctor.name(), - updatedSlotList); - } - return doctor; - }).toList(); + Utils.doctors = Utils.doctors.stream().map(doctor -> + doctor.name() + .equals(selectedDoctor.name())? + selectedDoctor: doctor).toList(); } - private static boolean isFreeForUser(Slot slot) { - return user.getUserSlotsStream() - .noneMatch(slotFromUser -> slotFromUser.timeStamp().equals(slot.timeStamp())); - } private static List filterDoctorsBySpeciality(int selectedSpeciality) { return Utils.doctors.stream() diff --git a/level1/src/main/java/org/com/level/hospital/User.java b/level1/src/main/java/org/com/level/hospital/User.java index bee4e21..17b2f7b 100644 --- a/level1/src/main/java/org/com/level/hospital/User.java +++ b/level1/src/main/java/org/com/level/hospital/User.java @@ -30,4 +30,9 @@ boolean userHave3Appointments() { } return false; } + + boolean isFreeForUser(Slot slot) { + return getUserSlotsStream() + .noneMatch(slotFromUser -> slotFromUser.timeStamp().equals(slot.timeStamp())); + } } diff --git a/level1/src/main/java/org/com/level/hospital/Utils.java b/level1/src/main/java/org/com/level/hospital/Utils.java index 0c0aee4..73213c7 100644 --- a/level1/src/main/java/org/com/level/hospital/Utils.java +++ b/level1/src/main/java/org/com/level/hospital/Utils.java @@ -16,31 +16,45 @@ public class Utils { new Doctor("General Medicine", "Dr. Ana Torres", List.of( new Slot(1, "8-9", true), new Slot(2, "9-10", true), - new Slot(3, "10-11", true))), + new Slot(3, "10-11", true), + new Slot(3, "14-15", true), + new Slot(3, "16-17", true))), new Doctor("General Medicine", "Dr. Carlos Ruiz", List.of( new Slot(1, "8-9", true), new Slot(2, "9-10", true), - new Slot(3, "10-11", true))), + new Slot(3, "10-11", true), + new Slot(3, "14-15", true), + new Slot(3, "16-17", true))), new Doctor("General Medicine", "Dr. Laura García", List.of( new Slot(1, "8-9", true), new Slot(2, "9-10", true), - new Slot(3, "10-11", true))), + new Slot(3, "10-11", true), + new Slot(3, "14-15", true), + new Slot(3, "16-17", true))), new Doctor("Emergency Care", "Dr. Roberto Fernández", List.of( new Slot(1, "8-9", true), new Slot(2, "9-10", true), - new Slot(3, "10-11", true))), + new Slot(3, "10-11", true), + new Slot(3, "14-15", true), + new Slot(3, "16-17", true))), new Doctor("Emergency Care", "Dr. Sofia Martínez", List.of( new Slot(1, "8-9", true), new Slot(2, "9-10", true), - new Slot(3, "10-11", true))), + new Slot(3, "10-11", true), + new Slot(3, "14-15", true), + new Slot(3, "16-17", true))), new Doctor("Emergency Care", "Dr. Juan Pérez", List.of( new Slot(1, "8-9", true), new Slot(2, "9-10", true), - new Slot(3, "10-11", true))), + new Slot(3, "10-11", true), + new Slot(3, "14-15", true), + new Slot(3, "16-17", true))), new Doctor("Clinical Analysis", "Dr. María López", List.of( new Slot(1, "8-9", true), new Slot(2, "9-10", true), - new Slot(3, "10-11", true))), + new Slot(3, "10-11", true), + new Slot(3, "14-15", true), + new Slot(3, "16-17", true))), new Doctor("Clinical Analysis", "Dr. Jorge Gómez", List.of( new Slot(1, "8-9", true), new Slot(2, "9-10", true), diff --git a/level1/target/classes/org/com/level/hospital/Authenticator.class b/level1/target/classes/org/com/level/hospital/Authenticator.class new file mode 100644 index 0000000000000000000000000000000000000000..fcef3278e8e58c8edeb6a21c68bcf79a8fb8c0e3 GIT binary patch literal 3351 zcmcImYj+dZ72Q`7%vcOq5ny5*hyaJ!GDHc1rp3etoKW1#;6%hUPG8s3MIJnwQD#O4 z_mwtH+obPz18vjS2Uge0hlG_lEnTZWpsU~d8~QKO(tT$}_88l=U%G6M@7%{ZXYYN^ znfteY-}x(mGx$Ru8DtIQENsD6fx=a}C@YS1o0W@mS5-X}*m}x#?Ql#WJ2X6Fz!Z2O z+SCbcr&6m+*HwNG^4Mm;valUH)>x@61)*vQWNcSpcQra`dzDGI-3e=CAm^&<3})9* z8eg*0#FNy{_3}7@j~IB$!bkD3wE{;bIi+6iNGF(Vx}L8lWS};2J==p(oHFpVg)xi^ z3~Zw0l++osU9J`MaCMXIYlNq=J8{OsSxgA@XcN@Mt_vLOVvO?OO2@5-w&zyP+S9&j z=%i6R`Yg^F__&4hnw-tTdm&KFFS9L!;F{+*^r=r+_+-qdY^iOS!UY2tEllG%f&Hr` zvyoSd5UPM8JepQ3uE5b$)+IB;vqe^K&B7(TAh4$;7u1C3GW^SSIL}cKGHU`Yz~ly+ zYH}`H_>|5bE6S586$G-W^unx#mvkf8rddnoixBvX2J%^f^F#le0*T-I@!XHkTacJz z6mxOC&FEr_8qKT;R?(iC=le@XN-cT46#7f0wig8UoTE&zAkE9lVFyqp6Y~PS&$^-V zOInuF1@dp=s=$tTa(YFi6L2iFz{J`br|UgQy2397neZBnrMGIk>O!YAr~FHjt_6x! zuP&V#>D&4}naqXrHVLBe{ccSs69E>B_L<6V>_uS{bL- zgIPZ_HcHfvY|S;~;7Z*MK7LPPCtR#QKCGka*3>k|8kUxmW3xLJ$k)7%UsvbsNRKn= z7V(%aGf4;Riv=ws4HOs&-HG>_jC<> z-@@1MY5}kIZpDxC_%VKB;HSFSe#Q?^RLD^?wcSN;K~-Wfas8c>b$)l21l~;7ak4Rv z#Dbex*a_C`p*$m31iFmTht zFYzlj#dVOXk${X>Ug-kb)=Izq{r?Z|zS!3+#*C(^S+gARmTrUhQo^#G)R&kEhkZf? z27V*($U06oQqREex~)B(5o@-x)x=Wc08=Z&zMbI@FEJbmeQ)4@gCkzQ`1JTTg&aq~ zK=}iR@?T)QcpE(*p!a37`%;x#ly=OD!+%~G9Igr6ptZ3*4OMDfui+75U{yUsCAwI+*gI9-){@Nt)PA4&#jA4W!tYXo3QD8Ue=u6o)S8$kE zjBE>B!}Y}4d&HmPsqyUCzMH5FyoHhSGEN^^#xwkz{4=UqaOLhl%LBQ_9Xt;#W9Bt+ z_txEil=sDCa{r4uh#2f)5((^OCKZO8a@)dKkxW5GM(JjDR)xa_o8~z;P_$ z3laI__#(a(0eu=@##d-t6Jj9qAu^)E1zt_~)N((;16ppQd+{cLTN#^7U3i?#a z%ihF`jyQ+R&Mk$E?uUt=Khlp*hvVg9lSY#Sx==3Kt8XWBM@jy|4HWuwl$Zk}cMG}f z+dP*}sbNN6W>SqXZH|!Vqfr#cWBV(t9>>=s+36Fnag^bS!}tbAS)SR$ds@gib+p@& x`4^5c;rM%+_XvEGlNo#quk(MAqaPB)8~8a_zJu@L2lzGT^PGDNzs2v-{~v^-QOp1U literal 0 HcmV?d00001 diff --git a/level1/target/classes/org/com/level/hospital/Doctor.class b/level1/target/classes/org/com/level/hospital/Doctor.class new file mode 100644 index 0000000000000000000000000000000000000000..7d6b077717271ab8f967da956fae9ed8083b3786 GIT binary patch literal 3513 zcmb_fYjYD-7=BJ~o2HvKE#)Rxpr^Ip!$U;nKB3E(V#N}>au8oG3Jqemcp z*H|%fmSLB3S7gy~O9DL;rfvFX1Ug4E^Swx*S3^=qA9R6Tj$6(Zol4GJ6_fF z4J&uvDf*5p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skCKdv}c}t8m<$^uXo&6QsdQo&oYJ|E$t|6RyK4Jcm zpyvv~xaIWo2#2k3i-r7t0M`fjknf#Lao9Tb#)-GhZE}o|qsHeB3@k@0ldI2IHwjeX T!h?@*$eCnZ-{O1xi0%IZE1`8L literal 0 HcmV?d00001 diff --git a/level1/target/classes/org/com/level/hospital/Main.class b/level1/target/classes/org/com/level/hospital/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..03705aef5481a564323207d79fe667c52c6fb109 GIT binary patch literal 6099 zcmb7I30xf28UMd!VPKgAvH=W842h^5>KbDb4T;T3gCRi0U=wTYWOsl`hMmpMY%J-a zJ?wqg9!Tkr!v?oxt(aKuhsW%Mz#=80;8}KRw~-Tw zIimtgIy(Ey)_W4r&>&GY3asn!Hx;g7FK=bXdZJc}jC(pqYH$XYX=v8bf-|FG?>4L~ zp%#c||8!M4yH$bnHUEKx>2p_b|X+saR3EW%6ge4_O6izvX%~{Qw3v4C#0h zt`s;cf}2uM#;2~(4dy({$&%mF0Ah(@XP>nCRXX-yM4)-pvOP1u-AOY>-K~?uMKqI= zwlAD?3Qjei%$OW<$qmY(x;6mVFe#rNE>?RfN?zrQ7$k;yHvx+5z2{ewMWwF1XJT_71`h0!*eH<=jZ zt>H*?Wt74bn8Y)6JPXfe#N^E}I@ipHvek1AT2I5G5%}(5!hQ6b|+!lo#rF5njx~7lz{c zVYDhzdQreg0*CNY9WTSn$%0|kOOHute&(pSj=vX(c)=(|u*QX?hkvB?cM+GjAgjO_BNW;0{ zlBmF&bi5gFVQcqHS&`T>!)Y-~Gn6+ovWc52<=>{`?RW=M-p@aQ%T8NBN(@7M7G+*aQ8)Wkzb=AnWin@U+@^5?XkPSuY; zsN+L&$ZGH{%7PJ!dWq*w9d}7Q@vJdn%E|1Qj=QD2+O(7PI0?DCO!mo1OzSv~8IETb zhla*7z+@%!3dKesw1+xxb26qtUB8tz z2MQDW&HPmcyBzCczmqoX5hHKO-@#&BHoSQTLOC`{rW0y>Z0fkiml<|xCp&Q5$dAcJ zeVT2~ki(vlKFBe+2*g!mi-(jR^Z}tZwOpcUW4Z4;(M@10$*ht z6Zmm6dSluS-f|PeP9dK*do5WQYGjgMC_5VqGT((f7I-7K z+w{hrj9ZVt@U1T>OyNl{=m_DZx=P$pkG~77iBzWOqq$|It_uH@6UD!D{06_R$A2D2 ze@u(j2&P3YR6HFpVu!c;XCp_q5DlxL>Ya z&9&|m*ef{bTnC&$I>rx6fTuQfx1PX64EN*Ezy&jKH^e2y^`vNyb9-H7bG)%KI59bm zXKauE51m#YK3-r0jLjB+>6%bO##!wtNVk*>IsTeBmDmX&uRD}IW>{e=k_CV^C=%9WkSAr z`IaRGZxwm=tZwDTmvo)PE5i2M-F^NvUVSG|_})yC9$1G(SWjPGieConLQ8;*j zQ7Z9r93-NLi8rPY$)NLB9^y(uzCZI@2Hkpo%b;7-<>OG!lVZb>yD1bfia z$c*oBfl>njv(_oxtb&4Cy&@>9tGtx0dMEV9VajqqiijHE8-Qm^SJM#CWZtkvYKXZ!fpn~00VEA5-mf5Yy;8q z>6gk)GVLl6>)b4egRLgOVe+^nXprK%_^%*nT@=_|iV0ufcG7GklkL=Z2ld?+64($J zQbu=4poUm-vxY+y$!-~l+!GRc4@KTHjT1-lzasrgw!Tb+Oab}VfZy>+s8SM$n4~d& zU#up$L^&K-b_y%^9><4|q4gB*-8+Sk9LL9x;Zrg+gsNTg&Ry2l1j}Uw{=nxL{)j*E ry9;qq&9y({ulQT=^bhk>y literal 0 HcmV?d00001 diff --git a/level1/target/classes/org/com/level/hospital/Printer.class b/level1/target/classes/org/com/level/hospital/Printer.class new file mode 100644 index 0000000000000000000000000000000000000000..5f0dc93b61bb148fba88371360aebedf485a5a99 GIT binary patch literal 1713 zcmaJ>%W@k<6g@4CJ(4oE9Lq@vwi5+xM-t!(Z-`{&Az~tsqkt4A7&dLGkvksEsAgI& z%$koN#g3xN8(5GSXNDjX5vishx6eKI+5O93kADVm1zQ;;kThXf zn7|~%%w4|6ZHK!(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msl8|e?82{Ih>~_LI!o@`%+LzRxinOhVl)%A4yRH=oKg^e;24p78GBgMkKKC z9qKFnD-O_gIQ0$VpD7qt9win~T84Va(<(dALQvE}fliU55uqfOgo?h6Nnn>IE+B*} zefTsk4S=5nKJ~juf|qeQg3nRUQoX9rZsYXd@CU=3{`^#2!PTH|I))=ABX}m=`WGlk zD)vP*OrFpKz$5<$9>cW(;6l;>b}FZFJs8ss+@w`*dT6`QbfM*L(VILKxJMhPqKezN RgS&V{(JV!m@ECO*`3+}wentQQ literal 0 HcmV?d00001 diff --git a/level1/target/classes/org/com/level/hospital/User.class b/level1/target/classes/org/com/level/hospital/User.class new file mode 100644 index 0000000000000000000000000000000000000000..d0c200b542de0797f14b800c14bf0ebcf1a1c73f GIT binary patch literal 4958 zcmb_g`Fj)B6+O?}$nqEqVHO7nPH?Ctzygw{ZRAkE;6h^)5`jyg+gKXxfzgaIGcs|y zZ|T18O}BJ!Ll@FujMJw3mZtmm-}LKw^G4Q8Y&rSz^#{%J=G}YGJ$HHU>6!m7Jq_S6 z{*y)<+BJ0O=tP%5=AtoY6l}wpDcoxXmC`Pzdm7|?K& zj;+`x&>O;N$kMSn!>*gYz?OvMm}}c+Ij~%(*n^v~L&KnsTW~8uH5D``QI8*Zrcosu z2|a4GK#%#6s^GXx<}9FB$O-sy{Uy|{AZIn)jvlO7Q39eAmRJ9WGaFBjO{ zyoDw%)SWOB3ggj3F$;l%X^i2hhGRO$@hZlBh2K$nxE`~sGjN%z0%zmc zS1OL-U-@wrAC^soOr6m2YTP5Bl~wi%?2DU=7-`Bx3d7`xf-Y-mkG!0eg*hUhPRXut zpTM2*$dyzH$8sbw(x|UuZc3(GNyllNVK4BlhuI6*Lr!$#H8`u`0UhUXKGAYY^L}8m zklNikgS}Ciu-w8aHjRK*WFe*SI)Pg!jfbqNVGo|HSEo&HFxDje!5KFQOec*u;Efs# z9n&ZaYzSkN)J3{#QnT&Q*eWjOrX&fbjtjE-vomHO`&!9%17Cs3vU$$xu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!tUb^)nRJKO$8BhLZX(1X?{_*0$n;mc*R4AG6vBE^4Rnigpf{v=H;!4P4f~ zgV(h0 Date: Wed, 17 Jan 2024 22:45:17 +0100 Subject: [PATCH 5/5] feat(hospoital): add possible solution for Agency --- .../java/org/com/level/agency/Agency.java | 67 ++++++++++++++++++ .../main/java/org/com/level/agency/Print.java | 15 ++++ .../java/org/com/level/hospital/Main.java | 1 - .../java/org/com/level/manchester/Player.java | 2 +- .../classes/org/com/level/hospital/Main.class | Bin 6099 -> 6099 bytes 5 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 level1/src/main/java/org/com/level/agency/Agency.java create mode 100644 level1/src/main/java/org/com/level/agency/Print.java diff --git a/level1/src/main/java/org/com/level/agency/Agency.java b/level1/src/main/java/org/com/level/agency/Agency.java new file mode 100644 index 0000000..6c2faa9 --- /dev/null +++ b/level1/src/main/java/org/com/level/agency/Agency.java @@ -0,0 +1,67 @@ +package org.com.level.agency; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Scanner; +import java.util.stream.Collectors; + +public class Agency { + static Scanner scanner = new Scanner(System.in); + static Map options = Map.of(100, "Winter", 200, "Summer", 500, + "Spring", 1000, "Autumn"); + static List priceTravels = options.keySet().stream().sorted().toList(); + + public static void main(String[] args) { + System.out.println("write your budget.."); + var budget = scanner.nextInt(); + System.out.println("Possible Travel for budget: "); + findPossiblesCombinations(new HashSet<>(), priceTravels, budget) + .stream() + .map(Agency :: getMapPriceAndRepetitions) + .forEach(Print :: printMapTravelRepetition); + } + + private static Map getMapPriceAndRepetitions(List integers) { + return integers.stream() + .distinct() + .collect(Collectors.toMap( + integer -> integer, + integer -> integers.stream() + .filter(integer1 -> integer1.equals(integer)) + .count() + )); + } + + public static HashSet> findPossiblesCombinations(HashSet> results, + List optionsCopy, + Integer budget) { + if (optionsCopy.isEmpty()) {return results;} + results.add(getOptionsFor(budget, optionsCopy, new ArrayList<>())); + return findPossiblesCombinations(results, + optionsCopy.subList(0, optionsCopy.size() - 1), + budget); + + } + + public static List getOptionsFor(Integer budget, + List optionsPrices, + List possibleTravels) { + Integer lastTravelPrice = optionsPrices.getLast(); + if (budget >= 0 && budget < optionsPrices.getFirst()) { + return possibleTravels; + } else if (budget - lastTravelPrice >= 0) { + possibleTravels.add(lastTravelPrice); + return getOptionsFor(budget - lastTravelPrice, + optionsPrices, + possibleTravels); + } else { + return getOptionsFor(budget, + optionsPrices.stream() + .filter(integer -> ! integer.equals(lastTravelPrice)) + .toList(), + possibleTravels); + } + } +} diff --git a/level1/src/main/java/org/com/level/agency/Print.java b/level1/src/main/java/org/com/level/agency/Print.java new file mode 100644 index 0000000..1500c5b --- /dev/null +++ b/level1/src/main/java/org/com/level/agency/Print.java @@ -0,0 +1,15 @@ +package org.com.level.agency; + +import java.util.Map; + +public class Print { + static void printMapTravelRepetition(Map integerLongMap) { + System.out.println( + "::::Option::::"); + integerLongMap.forEach( + (integer, aLong) -> + System.out.println( + "You would got tickets: " + aLong + " for: " + Agency.options.get(integer)) + ); + } +} diff --git a/level1/src/main/java/org/com/level/hospital/Main.java b/level1/src/main/java/org/com/level/hospital/Main.java index 511100b..750df91 100644 --- a/level1/src/main/java/org/com/level/hospital/Main.java +++ b/level1/src/main/java/org/com/level/hospital/Main.java @@ -1,6 +1,5 @@ package org.com.level.hospital; - import java.util.List; import java.util.Map; import java.util.Scanner; diff --git a/level1/src/main/java/org/com/level/manchester/Player.java b/level1/src/main/java/org/com/level/manchester/Player.java index fdcda1d..893fe5a 100644 --- a/level1/src/main/java/org/com/level/manchester/Player.java +++ b/level1/src/main/java/org/com/level/manchester/Player.java @@ -16,7 +16,7 @@ public record Player (String name, Integer jerseyNumber) { public static final Map> COMPARATORS = Map.of( - "goals", Comparator.comparingInt(Player :: speed), + "goals", Comparator.comparingInt(Player :: goals), "speed", Comparator.comparingInt(Player :: speed), "assists", Comparator.comparingInt(Player :: assists), "passing", Comparator.comparingInt(Player :: passingAccuracy), diff --git a/level1/target/classes/org/com/level/hospital/Main.class b/level1/target/classes/org/com/level/hospital/Main.class index 03705aef5481a564323207d79fe667c52c6fb109..3bc14503cd95715fdfe744a735587f7c0e2167dc 100644 GIT binary patch delta 225 zcmWNKy-osQ6hzM!BraxIcHvtH7{EX@{$(Wuq}aj*G~rVSiCEbf3kphNWn*o9AHf%( zv#{a`D5#0A;%z3AnUk4ayo=XQq2tOtd^bJ;d8(?{gmfs7U}PU|(h3Kf`y5fErdsEe z2A3SuR^O$`EiLXjVXDnDXDqm2#T6gKeA1S`!jIR*qo>O^l-vYnFl4_Xi>#sW9OjD>ix!hByq!FjRh|{6K!AH>W4H(jt>3%b|Rg F>_4%{BxC>p delta 225 zcmWNKyG{ZD5Jk@xBnmFF3%d|eUXehE0g)(>K!UuAT?G=Pq9GI%l!VHL+Il{LAF!jK z@(V1eiNE4xnwv8x_ns=J%J