OOP-01

Movie is just a simple data class. 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 int getPriceCode { return _priceCode; } public void setPriceCode(int arg) { _priceCode = arg; } <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 36pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">public String getTitle { <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">return _title; <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 36pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">}; } **Rental** The rental class represents a customer renting a movie. <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; text-indent: 36pt;">class Rental { <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 36pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">private Movie _movie; <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 36pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">private int _daysRented; <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 36pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">public Rental(Movie movie, int daysRented) { <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">_movie = movie; <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">_daysRented = daysRented; <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 36pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">} <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 36pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">public int getDaysRented { <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">return _daysRented; <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 36pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">} <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 36pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">public Movie getMovie { <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">return _movie; <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 36pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">} } **Customer** The customer class represents the customer of the store. Like the other classes it has data and accessors: <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; text-indent: 36pt;">class Customer { <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 36pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">private String _name; <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 36pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">private Vector _rentals = new Vector; ** public Customer (String name) ** { <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 36pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">_name = name; <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 36pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">}; ** public void addRental(Rental arg) ** { <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">_rentals.addElement(arg); <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 36pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">} ** public String getName ** { <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">return _name; <span style="font-family: 'Courier New'; font-size: 13px; line-height: 115%; margin-left: 36pt; text-indent: 36pt;">}; ** public String statement ** { <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">double totalAmount = 0; <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">int frequentRenterPoints = 0; <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">Enumeration rentals = _rentals.elements; <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">String result = "Rental Record for " + getName + "\n"; <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">while (rentals.hasMoreElements) { <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">double thisAmount = 0; <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">Rental each = (Rental) rentals.nextElement; <span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">//determine amounts for each line// //<span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">switch (each.getMovie.getPriceCode) { // //<span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">case Movie.REGULAR: // //<span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">thisAmount += 2; // //<span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">if (each.getDaysRented > 2) // //<span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">thisAmount += (each.getDaysRented - 2) * 1.5; // //<span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">break; // //<span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">case Movie.NEW_RELEASE: // //<span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">thisAmount += each.getDaysRented * 3; // //<span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">break; // //<span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">case Movie.CHILDRENS: // //<span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">thisAmount += 1.5; // //<span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">if (each.getDaysRented > 3) // //<span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">thisAmount += (each.getDaysRented - 3) * 1.5; // //<span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">break; // //<span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">} // add frequent renter points <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">frequentRenterPoints ++; <span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;"> //add bonus for a two day new release rental// //<span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">if ((each.getMovie.getPriceCode == Movie.NEW_RELEASE) // //<span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">&& // //<span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">each.getDaysRented > 1) frequentRenterPoints ++; // show figures for this rental <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">result += "\t" + each.getMovie.getTitle+ "\t" + <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">String.valueOf(thisAmount) + "\n"; <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">totalAmount += thisAmount; <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">} <span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">//add footer lines <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 108pt; margin-right: 0cm; margin-top: 0cm;">result += "Amount owed is " + String.valueOf(totalAmount) + "\n"; <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 108pt; margin-right: 0cm; margin-top: 0cm;">result += "You earned " + String.valueOf(frequentRenterPoints)+ " frequent renter points"; <span style="font-family: 'Courier New'; font-size: 13px; line-height: normal; margin-bottom: 0pt; margin-left: 72pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36pt;">return result; <span style="font-family: 'Courier New'; font-size: 13px; line-height: 115%; margin-left: 36pt; text-indent: 36pt;">}
 * Movie**