Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ChildrensPrice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class ChildrensPrice extends Price {

@Override
public int getPriceCode() {
return Movie.CHILDRENS;
}

@Override
public double getCharge(int daysRented) {
double valor = 1.5;
if (daysRented > 3)
valor += (daysRented - 3) * 1.5;
return valor;
}
}
69 changes: 69 additions & 0 deletions Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import java.util.Enumeration;
import java.util.Vector;

public class Customer {

private String nome;
private Vector alugueis = new Vector();

public Customer(String name) {
this.nome = name;
}

public void addRental(Rental arg) {
alugueis.addElement(arg);
}

public String getName() {
return nome;
}

public String statement() {
Enumeration rentals = alugueis.elements();
String result = "Registro de Aluguel para " + getName() + "\n";

while (rentals.hasMoreElements()) {
Rental each = (Rental) rentals.nextElement();
result += "\t" + each.getMovie().getTitle() + "\t" + each.getCharge() + "\n";
}

result += "Total devido é " + getTotalCharge() + "\n";
result += "Você ganhou " + getTotalFrequentRenterPoints() + " pontos de fidelidade";
return result;
}

public String htmlStatement() {
Enumeration rentals = alugueis.elements();
String result = "<H1>Aluguéis de <EM>" + getName() + "</EM></H1><P>\n";

while (rentals.hasMoreElements()) {
Rental each = (Rental) rentals.nextElement();
result += each.getMovie().getTitle() + ": " + each.getCharge() + "<BR>\n";
}

result += "<P>Você deve <EM>" + getTotalCharge() + "</EM><P>\n";
result += "Neste aluguel você ganhou <EM>" + getTotalFrequentRenterPoints() +
"</EM> pontos de fidelidade<P>";
return result;
}

private double getTotalCharge() {
double result = 0;
Enumeration rentals = alugueis.elements();
while (rentals.hasMoreElements()) {
Rental each = (Rental) rentals.nextElement();
result += each.getCharge();
}
return result;
}

private int getTotalFrequentRenterPoints() {
int result = 0;
Enumeration rentals = alugueis.elements();
while (rentals.hasMoreElements()) {
Rental each = (Rental) rentals.nextElement();
result += each.getFrequentRenterPoints();
}
return result;
}
}
46 changes: 46 additions & 0 deletions Movie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
public class Movie {

public static final int CHILDRENS = 2;
public static final int REGULAR = 0;
public static final int NEW_RELEASE = 1;

private String titulo;
private Price preco;

public Movie(String title, int priceCode) {
this.titulo = title;
setPriceCode(priceCode);
}

public String getTitle() {
return titulo;
}

public int getPriceCode() {
return preco.getPriceCode();
}

public void setPriceCode(int arg) {
switch (arg) {
case REGULAR:
preco = new RegularPrice();
break;
case CHILDRENS:
preco = new ChildrensPrice();
break;
case NEW_RELEASE:
preco = new NewReleasePrice();
break;
default:
throw new IllegalArgumentException("Código de preço incorreto");
}
}

public double getCharge(int daysRented) {
return preco.getCharge(daysRented);
}

public int getFrequentRenterPoints(int daysRented) {
return preco.getFrequentRenterPoints(daysRented);
}
}
17 changes: 17 additions & 0 deletions NewReleasePrice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class NewReleasePrice extends Price {

@Override
public int getPriceCode() {
return Movie.NEW_RELEASE;
}

@Override
public double getCharge(int daysRented) {
return daysRented * 3;
}

@Override
public int getFrequentRenterPoints(int daysRented) {
return daysRented > 1 ? 2 : 1;
}
}
8 changes: 8 additions & 0 deletions Price.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public abstract class Price {
public abstract int getPriceCode();
public abstract double getCharge(int daysRented);

public int getFrequentRenterPoints(int daysRented) {
return 1;
}
}
15 changes: 15 additions & 0 deletions RegularPrice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class RegularPrice extends Price {

@Override
public int getPriceCode() {
return Movie.REGULAR;
}

@Override
public double getCharge(int daysRented) {
double valor = 2;
if (daysRented > 2)
valor += (daysRented - 2) * 1.5;
return valor;
}
}
26 changes: 26 additions & 0 deletions Rental.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public class Rental {

private Movie filme;
private int diasAlugados;

public Rental(Movie movie, int daysRented) {
this.filme = movie;
this.diasAlugados = daysRented;
}

public int getDaysRented() {
return diasAlugados;
}

public Movie getMovie() {
return filme;
}

public double getCharge() {
return filme.getCharge(diasAlugados);
}

public int getFrequentRenterPoints() {
return filme.getFrequentRenterPoints(diasAlugados);
}
}