From 6cdb4d3da7de23d2f8a959c1ccc87df260fd5eff Mon Sep 17 00:00:00 2001 From: Niklas Raab Date: Thu, 12 Nov 2020 10:16:43 +0100 Subject: [PATCH] cr --- refactoring-movie/movie.java | 73 ++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 11 deletions(-) diff --git a/refactoring-movie/movie.java b/refactoring-movie/movie.java index df08c60..4bdf238 100644 --- a/refactoring-movie/movie.java +++ b/refactoring-movie/movie.java @@ -6,24 +6,66 @@ class Customer { private final String name; private final List rentals = new ArrayList(); - public Customer(final String name) { + public Customer(final String name, List rentals) { this.name = name; + this.rentals = rentals; } public String getName() { return name; } - public void addRental(final Rental rental) { - rentals.add(rental); + public List getRentals() + { + + } + + //public void addRental(final Rental rental) { + // rentals.add(rental); + //} +} + +class CustomerStatementDomainService() +{ + Protected Customer customer; + //private final List rentals = new ArrayList(); + + public CustomerStatementDomainService(Customer customer) { + this.customer = customer; + } +} + +interface calculateService +{ + public calculate(); +} + +class CustomerStatementCalculations implements calculateService +{ + private double totalAmount = 0; + private int frequentRenterPoints = 0; + private String result; + Protected Customer customer; + + public CustomerStatementCalculations(Customer customer) + { + this.customer = customer; + } + + Protected execute() + { + this.initResult(); + this.calculate(); + } + + Protected initResult() + { + this.result = "Rental record for " + this.customer.getName() + "\n"; } - public String statement() { - double totalAmount = 0; - int frequentRenterPoints = 0; - String result = "Rental record for " + getName() + "\n"; - for (final Rental rental : rentals) { + public calculate() { + for (final Rental rental : this.customer.getRentals()) { double amount = 0; switch (rental.getMovie().getPriceCode()) { case Movie.REGULAR: @@ -42,13 +84,13 @@ public String statement() { } // add frequent renter points - frequentRenterPoints++; + this.frequentRenterPoints++; // add bonus for a two day new release rental if (rental.getMovie().getPriceCode() == Movie.NEW_RELEASE && rental.getDaysRented() > 1) - frequentRenterPoints++; + this.frequentRenterPoints++; // show figures for this rental - result += "\t" + rental.getMovie().getTitle() + "\t" + String.valueOf(amount) + "\n"; + totalAmount += amount; } @@ -59,6 +101,15 @@ public String statement() { return result; } + private addResultString() + { + this.result += "\t" + rental.getMovie().getTitle() + "\t" + String.valueOf(amount) + "\n"; + } + + public getResults() + { + return result; + } } class Movie {