diff --git a/VideoStore/Test/CustomerTest.java b/VideoStore/Test/CustomerTest.java
index 203b8c5..be0a911 100644
--- a/VideoStore/Test/CustomerTest.java
+++ b/VideoStore/Test/CustomerTest.java
@@ -140,4 +140,56 @@ public class CustomerTest {
System.out.println(invoice_text);
}
+
+ /*
+ @Test
+ public void test_htmlStatement() {
+ String expected_text =
+ "Rentals for Customer_A\n" +
+ "\n" +
+ "Regular_Movie_1 : 2.0\n" +
+ "Regular_Movie_2 : 3.5\n" +
+ "Children_Movie_1 : 1.5\n" +
+ "Children_Movie_2 : 3.0\n" +
+ "NewRelease_Movie_1 : 9.0\n" +
+ "NewRelease_Movie_2 : 12.0\n" +
+ "\n" +
+ "Amount owed is 31.0\n" +
+ "\n" +
+ "On this rental you earned 8 frequent renter points";
+
+ Movie regular_movie_1 = new Movie ("regular_movie_1", Movie.REGULAR );
+ Rental rental_1 = new Rental(regular_movie_1, 1);
+ customer.addRental(rental_1);
+
+ Movie regular_movie_2 = new Movie ("regular_movie_2", Movie.REGULAR );
+ Rental rental_2 = new Rental(regular_movie_2, 3);
+ customer.addRental(rental_2);
+
+ Movie childrens_movie_1 = new Movie ("childrens_movie_1", Movie.CHILDRENS );
+ Rental rental_3 = new Rental(childrens_movie_1, 1);
+ customer.addRental(rental_3);
+
+ Movie childrens_movie_2 = new Movie ("childrens_movie_2", Movie.CHILDRENS );
+ Rental rental_4 = new Rental(childrens_movie_2, 4);
+ customer.addRental(rental_4);
+
+ Movie new_release_movie_1 = new Movie ("new_release_movie_1", Movie.NEW_RELEASE );
+ Rental rental_5 = new Rental(new_release_movie_1, 3);
+ customer.addRental(rental_5);
+
+ Movie new_release_movie_2 = new Movie ("new_release_movie_2", Movie.NEW_RELEASE );
+ Rental rental_6 = new Rental(new_release_movie_2, 4);
+ customer.addRental(rental_6);
+
+ String invoice_text = customer.statement();
+ assertEquals(expected_text, invoice_text);
+
+ System.out.println("test_statement_no_rentals");
+ System.out.println(invoice_text);
+
+ }
+
+ */
+
}
\ No newline at end of file
diff --git a/VideoStore/src/Application.java b/VideoStore/src/Application.java
index e9564cd..ea7f004 100644
--- a/VideoStore/src/Application.java
+++ b/VideoStore/src/Application.java
@@ -38,6 +38,7 @@ public class Application {
customer_1.addRental( new Rental( movies.get( 5 ), 4 ) );
String statement = customer_1.statement();
System.out.println( statement );
+ System.out.println( customer_1.htmlStatement() );
}
public void done() {
diff --git a/VideoStore/src/ChildrensPrice.java b/VideoStore/src/ChildrensPrice.java
new file mode 100644
index 0000000..d138c7d
--- /dev/null
+++ b/VideoStore/src/ChildrensPrice.java
@@ -0,0 +1,18 @@
+public class ChildrensPrice implements Price {
+ @Override
+ public int getPriceCode() {
+ return Movie.CHILDRENS;
+ }
+ @Override
+ public double getFee(int daysRented) {
+ double thisAmount = 1.5;
+ if(daysRented > 3) {
+ thisAmount += ( daysRented -3 ) * 1.5;
+ }
+ return thisAmount;
+ }
+ @Override
+ public int getBonus( int daysRented ) {
+ return 1;
+ }
+}
\ No newline at end of file
diff --git a/VideoStore/src/Customer.java b/VideoStore/src/Customer.java
index d783cdb..1f5aba2 100644
--- a/VideoStore/src/Customer.java
+++ b/VideoStore/src/Customer.java
@@ -25,47 +25,36 @@ public class Customer {
// add line for each rental
for( Rental curRental : rentals ) {
// show figures for this rental
- result.append("\t").append(curRental.getMovie().getTitle()).append("\t days rented: ").append(curRental.getDaysRented()).append(" = ").append(String.valueOf( calculateAmountFor(curRental) )).append("\n");
+ result.append("\t").append(curRental.getMovie().getTitle()).append("\t days rented: ").append(curRental.getDaysRented()).append(" = ").append(String.valueOf( curRental.calculateFee() )).append("\n");
}
// add footer lines
result.append("Amount owed is ").append(String.valueOf( getTotalAmount() )).append("\n");
result.append("You earned ").append(String.valueOf( getFrequentRenterPoints() )).append(" frequent renter points");
return result.toString();
}
- public double calculateAmountFor (Rental curRental) {
- double thisAmount = 0;
- // determine amounts for each line
- switch( curRental.getMovie().getPriceCode() ) {
- case Movie.REGULAR:
- thisAmount += 2;
- if( curRental.getDaysRented() > 2 )
- thisAmount += ( curRental.getDaysRented() - 2 ) * 1.5;
- break;
- case Movie.NEW_RELEASE:
- thisAmount += curRental.getDaysRented() * 3;
- break;
- case Movie.CHILDRENS:
- thisAmount += 1.5;
- if( curRental.getDaysRented() > 3 )
- thisAmount += ( curRental.getDaysRented() - 3 ) * 1.5;
- break;
+ public String htmlStatement() {
+ StringBuilder result = new StringBuilder();
+ result.append("").append("\n");
+ result.append("
").append("Rental Record for ").append(getName()).append("
").append("\n");
+
+ for(Rental curRental : rentals) {
+ result.append("");
+ result.append("\t").append(curRental.getMovie().getTitle());
+ result.append("\t days rented: ").append(curRental.getDaysRented());
+ result.append(" = ").append(String.valueOf(curRental.calculateFee())).append("\n");
+ result.append("
\n");
}
- return thisAmount;
- }
- public int calculateFrequentRenterPointsFor (Rental curRental){
- int frequentRenterPoints = 1;
- // add bonus for a two day new release rental
- if( ( curRental.getMovie().getPriceCode() == Movie.NEW_RELEASE ) && curRental.getDaysRented() > 1 )
- frequentRenterPoints++;
- return frequentRenterPoints;
+ result.append("Amount owed is ").append(String.valueOf(getTotalAmount())).append("
\n");
+ result.append("You earned ").append(String.valueOf(getFrequentRenterPoints())).append(" frequent renter points
");
+ return(result.toString());
}
private int getFrequentRenterPoints() {
int frequentRenterPoints = 0;
for( Rental curRental : rentals ) {
// add frequent renter points
- frequentRenterPoints += calculateFrequentRenterPointsFor(curRental);
+ frequentRenterPoints += curRental.calculateBonus();
}
return frequentRenterPoints;
}
@@ -73,7 +62,7 @@ public class Customer {
private double getTotalAmount() {
double totalAmount = 0;
for( Rental curRental : rentals ) {
- double thisAmount = calculateAmountFor(curRental);
+ double thisAmount = curRental.calculateFee();
totalAmount += thisAmount;
}
return totalAmount;
diff --git a/VideoStore/src/Movie.java b/VideoStore/src/Movie.java
index 93dc367..85e28a5 100644
--- a/VideoStore/src/Movie.java
+++ b/VideoStore/src/Movie.java
@@ -3,13 +3,14 @@ public class Movie {
public static final int CHILDRENS = 2;
public static final int REGULAR = 0;
public static final int NEW_RELEASE = 1;
+ public static final int STUDENTS = 3;
private final String title;
- private int priceCode;
+ private Price price;
public Movie( String title, int priceCode ) {
this.title = title;
- this.priceCode = priceCode;
+ setPriceCode( priceCode );
}
public String getTitle() {
@@ -17,10 +18,64 @@ public class Movie {
}
public int getPriceCode() {
- return priceCode;
+ return price.getPriceCode();
}
public void setPriceCode( int priceCode ) {
- this.priceCode = priceCode;
+ switch( priceCode ) {
+ case Movie.REGULAR:
+ this.price = new RegularPrice();
+ break;
+ case Movie.CHILDRENS:
+ this.price = new ChildrensPrice();
+ break;
+ case Movie.NEW_RELEASE:
+ this.price = new NewReleasePrice();
+ break;
+ case Movie.STUDENTS:
+ this.price = new StudentsPrice();
+ break;
+ default:
+ throw new IllegalArgumentException("Incorrect Price Code");
+ }
}
+
+ public double calculateFee ( int daysRented) {
+ return price.getFee( daysRented);
+ }
+
+ public int calculateBonus( int daysRented) {
+ return price.getBonus( daysRented );
+ }
+
+ /* public double calculateFee (int daysRented) {
+ double thisAmount = 0;
+ // determine amounts for each line
+ switch( getPriceCode() ) {
+ case Movie.REGULAR:
+ thisAmount += 2;
+ if( daysRented > 2 )
+ thisAmount += ( daysRented - 2 ) * 1.5;
+ break;
+ case Movie.NEW_RELEASE:
+ thisAmount += daysRented * 3;
+ break;
+ case Movie.CHILDRENS:
+ thisAmount += 1.5;
+ if( daysRented > 3 )
+ thisAmount += ( daysRented - 3 ) * 1.5;
+ break;
+
+ }
+ return thisAmount;
+ }
+ */
+ /* public int calculateBonus (int daysRented){
+ int frequentRenterPoints = 1;
+ // add bonus for a two day new release rental
+ if( ( getPriceCode() == Movie.NEW_RELEASE ) && daysRented > 1 )
+ frequentRenterPoints++;
+ return frequentRenterPoints;
+ }
+ */
}
\ No newline at end of file
diff --git a/VideoStore/src/NewReleasePrice.java b/VideoStore/src/NewReleasePrice.java
new file mode 100644
index 0000000..02c382d
--- /dev/null
+++ b/VideoStore/src/NewReleasePrice.java
@@ -0,0 +1,18 @@
+public class NewReleasePrice implements Price {
+ @Override
+ public int getPriceCode() {
+ return Movie.NEW_RELEASE;
+ }
+ @Override
+ public double getFee(int daysRented) {
+ double thisAmount = daysRented * 3;
+ return thisAmount;
+ }
+ @Override
+ public int getBonus( int daysRented ) {
+ int frequentRenterPoints = 1;
+ if( daysRented > 1 )
+ frequentRenterPoints++;
+ return frequentRenterPoints;
+ }
+}
\ No newline at end of file
diff --git a/VideoStore/src/Price.java b/VideoStore/src/Price.java
new file mode 100644
index 0000000..abfbc87
--- /dev/null
+++ b/VideoStore/src/Price.java
@@ -0,0 +1,5 @@
+public interface Price {
+ int getPriceCode();
+ double getFee( int daysRented );
+ int getBonus( int daysRented );
+}
\ No newline at end of file
diff --git a/VideoStore/src/RegularPrice.java b/VideoStore/src/RegularPrice.java
new file mode 100644
index 0000000..52f9a68
--- /dev/null
+++ b/VideoStore/src/RegularPrice.java
@@ -0,0 +1,18 @@
+public class RegularPrice implements Price {
+ @Override
+ public int getPriceCode() {
+ return Movie.REGULAR;
+ }
+ @Override
+ public double getFee(int daysRented) {
+ double thisAmount = 2;
+ if(daysRented > 2) {
+ thisAmount += (daysRented -2) * 1.5;
+ }
+ return thisAmount;
+ }
+ @Override
+ public int getBonus( int daysRented ) {
+ return 1;
+ }
+}
\ No newline at end of file
diff --git a/VideoStore/src/Rental.java b/VideoStore/src/Rental.java
index 088c4c5..ed1a824 100644
--- a/VideoStore/src/Rental.java
+++ b/VideoStore/src/Rental.java
@@ -15,4 +15,12 @@ public class Rental {
public int getDaysRented() {
return daysRented;
}
+
+ public double calculateFee () {
+ return getMovie().calculateFee(getDaysRented());
+ }
+
+ public int calculateBonus (){
+ return getMovie().calculateBonus(getDaysRented());
+ }
}
\ No newline at end of file
diff --git a/VideoStore/src/StudentsPrice.java b/VideoStore/src/StudentsPrice.java
new file mode 100644
index 0000000..4e0b2c1
--- /dev/null
+++ b/VideoStore/src/StudentsPrice.java
@@ -0,0 +1,18 @@
+public class StudentsPrice implements Price {
+ @Override
+ public int getPriceCode() {
+ return Movie.CHILDRENS;
+ }
+ @Override
+ public double getFee(int daysRented) {
+ double thisAmount = 1;
+ if(daysRented > 2) {
+ thisAmount += ( daysRented -2 );
+ }
+ return thisAmount;
+ }
+ @Override
+ public int getBonus( int daysRented ) {
+ return 1;
+ }
+}
\ No newline at end of file