Skip to content
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
72 changes: 72 additions & 0 deletions src/Customer.java
Original file line number Diff line number Diff line change
@@ -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 = "<H1>Rentals for <EM>" + getName() + "</EM></H1><P>\n";
Enumeration rentals = _rentals.elements();
while (rentals.hasMoreElements()) {
Rental each = (Rental) rentals.nextElement();
result += each.getMovie().getTitle() + ": " +
String.valueOf(each.getCharge()) + "<BR>\n";
}
result += "<P>You owe <EM>" + String.valueOf(getTotalCharge()) + "</EM><P>\n";
result += "On this rental you earned <EM>" +
String.valueOf(getTotalFrequentRenterPoints()) +
"</EM> frequent renter points<P>";
return result;
}
}
53 changes: 53 additions & 0 deletions src/Movie.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
25 changes: 25 additions & 0 deletions src/Rental.java
Original file line number Diff line number Diff line change
@@ -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);
}
}