Skip to content

Commit

Permalink
Project File
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanmai committed Nov 18, 2011
1 parent 1c30860 commit f7e327b
Show file tree
Hide file tree
Showing 7 changed files with 300 additions and 288 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ bin
.classpath
.project
.settings
.idea
out
22 changes: 22 additions & 0 deletions The_rental_example.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library>
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.8.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

108 changes: 54 additions & 54 deletions src/com/aquiles/alexandre/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,61 @@
import java.util.Collection;

public class Customer {

private String name;
private Collection<Rental> rentals;

public Customer(String name) {
super();
rentals = new ArrayList<Rental>();
this.name = name;
}

public String getName() {
return name;
}

public void addRental(Rental rental) {
rentals.add(rental);
}
private String name;
private Collection<Rental> rentals;

public String statement() {
double totalAmount = 0;
int frequentRenterPoints = 0;
String result = "Rental record for " + getName() + "\n";
for(Rental rental : rentals) {
double thisAmount = 0;
switch(rental.getMovie().getPriceCode()) {
case Movie.REGULAR:
thisAmount += 2;
if(rental.getDaysRented() > 2)
thisAmount += (rental.getDaysRented() - 2) * 1.5;
break;
case Movie.NEW_RELEASE:
thisAmount += rental.getDaysRented() * 3;
break;
case Movie.CHILDRENS:
thisAmount += 1.5;
if(rental.getDaysRented() > 3)
thisAmount += (rental.getDaysRented() - 3) * 1.5;
break;
}

//add frequent renter points
frequentRenterPoints++;
public Customer(String name) {
super();
rentals = new ArrayList<Rental>();
this.name = name;
}

//add bonus for a two day new release rental
if(rental.getMovie().getPriceCode() == Movie.NEW_RELEASE && rental.getDaysRented() > 1)
frequentRenterPoints++;

//show figures for this rental
result += "\t" + rental.getMovie().getTitle() + "\t" + String.valueOf(thisAmount) + "\n";
totalAmount += thisAmount;
}

//add footer lines
result += "Amount owed is " + String.valueOf(totalAmount) + "\n";
result += "You earned " + String.valueOf(frequentRenterPoints) + " frequent renter points";
return result;
}
public String getName() {
return name;
}

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

public String statement() {
double totalAmount = 0;
int frequentRenterPoints = 0;
String result = "Rental record for " + getName() + "\n";
for (Rental rental : rentals) {
double thisAmount = 0;
switch (rental.getMovie().getPriceCode()) {
case REGULAR:
thisAmount += 2;
if (rental.getDaysRented() > 2)
thisAmount += (rental.getDaysRented() - 2) * 1.5;
break;
case NEW_RELEASE:
thisAmount += rental.getDaysRented() * 3;
break;
case CHILDRENS:
thisAmount += 1.5;
if (rental.getDaysRented() > 3)
thisAmount += (rental.getDaysRented() - 3) * 1.5;
break;
}

//add frequent renter points
frequentRenterPoints++;

//add bonus for a two day new release rental
if (rental.getMovie().getPriceCode() == Movie.PriceCode.NEW_RELEASE && rental.getDaysRented() > 1)
frequentRenterPoints++;

//show figures for this rental
result += "\t" + rental.getMovie().getTitle() + "\t" + String.valueOf(thisAmount) + "\n";
totalAmount += thisAmount;
}

//add footer lines
result += "Amount owed is " + String.valueOf(totalAmount) + "\n";
result += "You earned " + String.valueOf(frequentRenterPoints) + " frequent renter points";
return result;
}
}
36 changes: 13 additions & 23 deletions src/com/aquiles/alexandre/Movie.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
package com.aquiles.alexandre;

public class Movie {
public enum PriceCode {REGULAR, NEW_RELEASE, CHILDRENS}

public static final int REGULAR = 0;
public static final int NEW_RELEASE = 1;
public static final int CHILDRENS = 2;
private final String title;
private final PriceCode priceCode;

private String title;
private Integer priceCode;

public Movie(String title, Integer priceCode) {
super();
this.title = title;
this.priceCode = priceCode;
}
public Movie(String title, PriceCode priceCode) {
this.title = title;
this.priceCode = priceCode;
}

public Integer getPriceCode() {
return priceCode;
}
public PriceCode getPriceCode() {
return priceCode;
}

public void setPriceCode(Integer priceCode) {
this.priceCode = priceCode;
}
public String getTitle() {
return title;
}

public String getTitle() {
return title;
}



}
32 changes: 15 additions & 17 deletions src/com/aquiles/alexandre/Rental.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package com.aquiles.alexandre;


public class Rental {

private Movie movie;
private Integer daysRented;

public Rental(Movie movie, Integer daysRented) {
super();
this.movie = movie;
this.daysRented = daysRented;
}
private Movie movie;
private Integer daysRented;

public Rental(Movie movie, Integer daysRented) {
super();
this.movie = movie;
this.daysRented = daysRented;
}

public Movie getMovie() {
return movie;
}

public Movie getMovie() {
return movie;
}
public Integer getDaysRented() {
return daysRented;
}

public Integer getDaysRented() {
return daysRented;
}


}
Loading

0 comments on commit f7e327b

Please sign in to comment.