diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..9f11b755 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/src/Customer.java b/src/Customer.java new file mode 100644 index 00000000..2d938487 --- /dev/null +++ b/src/Customer.java @@ -0,0 +1,72 @@ +import java.util.Enumeration; +import java.util.Vector; + +public class Customer { + private String _name; + private Vector _rentals = new Vector(); + + public Customer(String name) { + _name = name; + } + + public void addRental(Rental arg) { + _rentals.addElement(arg); + } + + public String getName() { + return _name; + } + + public Enumeration getRentals() { + return _rentals.elements(); + } + + public String statement() { + String result = "Rental Record for " + getName() + "\n"; + Enumeration rentals = _rentals.elements(); + while (rentals.hasMoreElements()) { + Rental each = (Rental) rentals.nextElement(); + result += "\t" + each.getMovie().getTitle() + "\t" + + String.valueOf(each.getCharge()) + "\n"; + } + result += "Amount owed is " + String.valueOf(getTotalCharge()) + "\n"; + result += "You earned " + String.valueOf(getTotalFrequentRenterPoints()) + + " frequent renter points"; + return result; + } + + public double getTotalCharge() { + double result = 0; + Enumeration rentals = _rentals.elements(); + while (rentals.hasMoreElements()) { + Rental each = (Rental) rentals.nextElement(); + result += each.getCharge(); + } + return result; + } + + public int getTotalFrequentRenterPoints() { + int result = 0; + Enumeration rentals = _rentals.elements(); + while (rentals.hasMoreElements()) { + Rental each = (Rental) rentals.nextElement(); + result += each.getFrequentRenterPoints(); + } + return result; + } + + public String htmlStatement() { + String result = "

Rentals for " + getName() + "

\n"; + Enumeration rentals = _rentals.elements(); + while (rentals.hasMoreElements()) { + Rental each = (Rental) rentals.nextElement(); + result += each.getMovie().getTitle() + ": " + + String.valueOf(each.getCharge()) + "
\n"; + } + result += "

You owe " + String.valueOf(getTotalCharge()) + "

\n"; + result += "On this rental you earned " + + String.valueOf(getTotalFrequentRenterPoints()) + + " frequent renter points

"; + return result; + } +} diff --git a/src/Movie.java b/src/Movie.java new file mode 100644 index 00000000..0747048b --- /dev/null +++ b/src/Movie.java @@ -0,0 +1,53 @@ +public class Movie { + public static final int CHILDRENS = 2; + public static final int REGULAR = 0; + public static final int NEW_RELEASE = 1; + + private String _title; + private int _priceCode; + + public Movie(String title, int priceCode) { + _title = title; + _priceCode = priceCode; + } + + public String getTitle() { + return _title; + } + + public int getPriceCode() { + return _priceCode; + } + + public void setPriceCode(int arg) { + _priceCode = arg; + } + + public double getCharge(int daysRented) { + double result = 0; + switch (_priceCode) { + case REGULAR: + result += 2; + if (daysRented > 2) + result += (daysRented - 2) * 1.5; + break; + case NEW_RELEASE: + result += daysRented * 3; + break; + case CHILDRENS: + result += 1.5; + if (daysRented > 3) + result += (daysRented - 3) * 1.5; + break; + } + return result; + } + + public int getFrequentRenterPoints(int daysRented) { + if (_priceCode == NEW_RELEASE && daysRented > 1) { + return 2; + } else { + return 1; + } + } +} diff --git a/src/Rental.java b/src/Rental.java new file mode 100644 index 00000000..3f47c368 --- /dev/null +++ b/src/Rental.java @@ -0,0 +1,25 @@ +public class Rental { + private Movie _movie; + private int _daysRented; + + public Rental(Movie movie, int daysRented) { + _movie = movie; + _daysRented = daysRented; + } + + public int getDaysRented() { + return _daysRented; + } + + public Movie getMovie() { + return _movie; + } + + public double getCharge() { + return _movie.getCharge(_daysRented); + } + + public int getFrequentRenterPoints() { + return _movie.getFrequentRenterPoints(_daysRented); + } +}