From cff21d28f0bb42db0258a5e36971ec65b17b1071 Mon Sep 17 00:00:00 2001 From: Matheus Augusto <163954181+MatheusBorsa@users.noreply.github.com> Date: Thu, 27 Nov 2025 20:46:28 -0300 Subject: [PATCH 1/7] Add Movie class with pricing logic --- Movie.java | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Movie.java diff --git a/Movie.java b/Movie.java new file mode 100644 index 00000000..7ce1dbff --- /dev/null +++ b/Movie.java @@ -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); + } +} From df8111cb77092841b112c459e8004c9c6b5f0796 Mon Sep 17 00:00:00 2001 From: Matheus Augusto <163954181+MatheusBorsa@users.noreply.github.com> Date: Thu, 27 Nov 2025 20:46:54 -0300 Subject: [PATCH 2/7] Create Rental.java --- Rental.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Rental.java diff --git a/Rental.java b/Rental.java new file mode 100644 index 00000000..f000d47f --- /dev/null +++ b/Rental.java @@ -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); + } +} From 3ec3dc5ce9a2ce84a5c75369676243439ca2778d Mon Sep 17 00:00:00 2001 From: Matheus Augusto <163954181+MatheusBorsa@users.noreply.github.com> Date: Thu, 27 Nov 2025 20:47:15 -0300 Subject: [PATCH 3/7] Implement Customer class for rental management --- Customer.java | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Customer.java diff --git a/Customer.java b/Customer.java new file mode 100644 index 00000000..bf140920 --- /dev/null +++ b/Customer.java @@ -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 = "
\n";
+
+ while (rentals.hasMoreElements()) {
+ Rental each = (Rental) rentals.nextElement();
+ result += each.getMovie().getTitle() + ": " + each.getCharge() + "
\n";
+ }
+
+ result += "
Você deve " + getTotalCharge() + "
\n"; + result += "Neste aluguel você ganhou " + getTotalFrequentRenterPoints() + + " pontos de fidelidade
"; + 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; + } +} From 59b69527c4049b27d800d1bb2cd54462ff7e051f Mon Sep 17 00:00:00 2001 From: Matheus Augusto <163954181+MatheusBorsa@users.noreply.github.com> Date: Thu, 27 Nov 2025 20:47:36 -0300 Subject: [PATCH 4/7] Create abstract Price class with methods for pricing --- Price.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Price.java diff --git a/Price.java b/Price.java new file mode 100644 index 00000000..2b5525d6 --- /dev/null +++ b/Price.java @@ -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; + } +} From 225af606a81f9c89ec85597a771f2609b0afc253 Mon Sep 17 00:00:00 2001 From: Matheus Augusto <163954181+MatheusBorsa@users.noreply.github.com> Date: Thu, 27 Nov 2025 20:47:54 -0300 Subject: [PATCH 5/7] Implement ChildrensPrice class for rental pricing --- ChildrensPrice.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 ChildrensPrice.java diff --git a/ChildrensPrice.java b/ChildrensPrice.java new file mode 100644 index 00000000..da8dd100 --- /dev/null +++ b/ChildrensPrice.java @@ -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; + } +} From ff3654f3fb51782b79e5dec0539f377f1d31e262 Mon Sep 17 00:00:00 2001 From: Matheus Augusto <163954181+MatheusBorsa@users.noreply.github.com> Date: Thu, 27 Nov 2025 20:48:16 -0300 Subject: [PATCH 6/7] Implement NewReleasePrice class for pricing logic --- NewReleasePrice.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 NewReleasePrice.java diff --git a/NewReleasePrice.java b/NewReleasePrice.java new file mode 100644 index 00000000..d9129d5f --- /dev/null +++ b/NewReleasePrice.java @@ -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; + } +} From 104e012b1745abb32a6327afed92a2f507d529a8 Mon Sep 17 00:00:00 2001 From: Matheus Augusto <163954181+MatheusBorsa@users.noreply.github.com> Date: Thu, 27 Nov 2025 20:48:35 -0300 Subject: [PATCH 7/7] Create RegularPrice.java --- RegularPrice.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 RegularPrice.java diff --git a/RegularPrice.java b/RegularPrice.java new file mode 100644 index 00000000..92daeae8 --- /dev/null +++ b/RegularPrice.java @@ -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; + } +}