Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 62 additions & 11 deletions refactoring-movie/movie.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,66 @@ class Customer {
private final String name;
private final List<Rental> rentals = new ArrayList<Rental>();

public Customer(final String name) {
public Customer(final String name, List<Rental> rentals) {
this.name = name;
this.rentals = rentals;
}

public String getName() {
return name;
}

public void addRental(final Rental rental) {
rentals.add(rental);
public List<Rental> getRentals()
{

}

//public void addRental(final Rental rental) {
// rentals.add(rental);
//}
}

class CustomerStatementDomainService()
{
Protected Customer customer;
//private final List<Rental> rentals = new ArrayList<Rental>();

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:
Expand All @@ -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;
}
Expand All @@ -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 {
Expand Down