Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package christmasPastryShop.core;
- import christmasPastryShop.common.ExceptionMessages;
- import christmasPastryShop.common.OutputMessages;
- import christmasPastryShop.common.enums.DelicacyType;
- import christmasPastryShop.common.enums.CocktailType;
- import christmasPastryShop.common.enums.BoothType;
- import christmasPastryShop.core.interfaces.Controller;
- import christmasPastryShop.entities.delicacies.Gingerbread;
- import christmasPastryShop.entities.delicacies.Stolen;
- import christmasPastryShop.entities.delicacies.interfaces.Delicacy;
- import christmasPastryShop.entities.drinks.MulledWine;
- import christmasPastryShop.entities.drinks.Hibernation;
- import christmasPastryShop.entities.drinks.interfaces.Cocktail;
- import christmasPastryShop.entities.booths.OpenBooth;
- import christmasPastryShop.entities.booths.PrivateBooth;
- import christmasPastryShop.entities.booths.interfaces.Booth;
- import christmasPastryShop.repositories.interfaces.*;
- public class ControllerImpl implements Controller {
- private final DelicacyRepository<Delicacy> delicacyRepository;
- private final CocktailRepository<Cocktail> cocktailRepository;
- private final BoothRepository<Booth> boothRepository;
- private double totalIncome;
- public ControllerImpl(DelicacyRepository<Delicacy> delicacyRepository, CocktailRepository<Cocktail> cocktailRepository, BoothRepository<Booth> boothRepository) {
- this.delicacyRepository = delicacyRepository;
- this.cocktailRepository = cocktailRepository;
- this.boothRepository = boothRepository;
- this.totalIncome = 0;
- }
- @Override
- public String addDelicacy(String type, String name, double price) {
- Delicacy delicacy = delicacyRepository.getByName(name);
- if (delicacy != null) {
- throw new IllegalArgumentException(String.format(ExceptionMessages.FOOD_OR_DRINK_EXIST, delicacy.getClass().getSimpleName(), name));
- }
- DelicacyType foodType = DelicacyType.valueOf(type);
- delicacy = foodType == DelicacyType.Gingerbread ? new Gingerbread(name, price) : new Stolen(name, price);
- delicacyRepository.add(delicacy);
- return String.format(OutputMessages.DELICACY_ADDED, name, type);
- }
- @Override
- public String addCocktail(String type, String name, int size, String brand) {
- Cocktail cocktail = cocktailRepository.getByName(name);
- if (cocktail != null) {
- throw new IllegalArgumentException(String.format(ExceptionMessages.FOOD_OR_DRINK_EXIST, cocktail.getClass().getSimpleName(), cocktail.getName()));
- }
- cocktail = CocktailType.valueOf(type) == CocktailType.MulledWine ? new MulledWine(name, size, brand) : new Hibernation(name, size, brand);
- cocktailRepository.add(cocktail);
- return String.format(OutputMessages.COCKTAIL_ADDED, name, brand);
- }
- @Override
- public String addBooth(String type, int boothNumber, int capacity) {
- Booth booth = boothRepository.getByNumber(boothNumber);
- if (booth != null) {
- throw new IllegalArgumentException(String.format(ExceptionMessages.BOOTH_EXIST, boothNumber));
- }
- BoothType tableType = BoothType.valueOf(type);
- booth = tableType == BoothType.OpenBooth ? new OpenBooth(boothNumber, capacity) : new PrivateBooth(boothNumber, capacity);
- boothRepository.add(booth);
- return String.format(OutputMessages.BOOTH_ADDED, boothNumber);
- }
- @Override
- public String reserveBooth(int numberOfPeople) {
- for (Booth booth : boothRepository.getAll()) {
- if (!booth.isReserved() && booth.getCapacity() >= numberOfPeople) {
- booth.reserve(numberOfPeople);
- return String.format(OutputMessages.BOOTH_RESERVED, booth.getBoothNumber(), numberOfPeople);
- }
- }
- return String.format(OutputMessages.RESERVATION_NOT_POSSIBLE, numberOfPeople);
- }
- @Override
- public String leaveBooth(int boothNumber) {
- Booth booth = boothRepository.getByNumber(boothNumber);
- double bill = booth.getBill();
- booth.clear();
- this.totalIncome += bill;
- return String.format(OutputMessages.BILL, boothNumber, bill);
- }
- @Override
- public String getIncome() {
- return String.format(OutputMessages.TOTAL_INCOME, this.totalIncome);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement