diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 00000000..13566b81
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/AulaPraticaRefactoring.iml b/.idea/AulaPraticaRefactoring.iml
new file mode 100644
index 00000000..75c06680
--- /dev/null
+++ b/.idea/AulaPraticaRefactoring.iml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml
new file mode 100644
index 00000000..f593bb3c
--- /dev/null
+++ b/.idea/material_theme_project_new.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 00000000..4444b225
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 00000000..e07d8d49
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 00000000..35eb1ddf
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ChildrensPrice.java b/ChildrensPrice.java
new file mode 100644
index 00000000..c1cf552e
--- /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 result = 1.5;
+ if (daysRented > 3) {
+ result += (daysRented - 3) * 1.5;
+ }
+ return result;
+ }
+}
diff --git a/Customer.java b/Customer.java
new file mode 100644
index 00000000..b9933a80
--- /dev/null
+++ b/Customer.java
@@ -0,0 +1,51 @@
+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 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 statement() {
+ return new TextStatement().value(this); // Delegação para TextStatement
+ }
+
+ public String htmlStatement() {
+ return new HtmlStatement().value(this); // Delegação para HtmlStatement
+ }
+}
diff --git a/HtmlStatement.java b/HtmlStatement.java
new file mode 100644
index 00000000..c7f121b6
--- /dev/null
+++ b/HtmlStatement.java
@@ -0,0 +1,21 @@
+public class HtmlStatement extends Statement {
+
+ @Override
+ protected String headerString(Customer aCustomer) {
+ return "
Rentals for " + aCustomer.getName() + "
\n";
+ }
+
+ @Override
+ protected String rentalString(Rental aRental) {
+ return aRental.getMovie().getTitle() + ": " +
+ String.valueOf(aRental.getCharge()) + "
\n";
+ }
+
+ @Override
+ protected String footerString(Customer aCustomer) {
+ return "
You owe " + String.valueOf(aCustomer.getTotalCharge()) + "
\n" +
+ "On this rental you earned " +
+ String.valueOf(aCustomer.getTotalFrequentRenterPoints()) +
+ " frequent renter points
";
+ }
+}
diff --git a/Movie.java b/Movie.java
new file mode 100644
index 00000000..90ced6c0
--- /dev/null
+++ b/Movie.java
@@ -0,0 +1,45 @@
+public class Movie {
+ public static final int REGULAR = 0;
+ public static final int CHILDRENS = 1;
+ public static final int NEW_RELEASE = 2;
+
+ private String _title;
+ private Price _price;
+
+ public Movie(String title, int priceCode) {
+ _title = title;
+ setPriceCode(priceCode);
+ }
+
+ public int getPriceCode() {
+ return _price.getPriceCode();
+ }
+
+ public void setPriceCode(int arg) {
+ switch (arg) {
+ case REGULAR:
+ _price = new RegularPrice();
+ break;
+ case CHILDRENS:
+ _price = new ChildrensPrice();
+ break;
+ case NEW_RELEASE:
+ _price = new NewReleasePrice();
+ break;
+ default:
+ throw new IllegalArgumentException("Incorrect Price Code");
+ }
+ }
+
+ public String getTitle() {
+ return _title;
+ }
+
+ public double getCharge(int daysRented) {
+ return _price.getCharge(daysRented);
+ }
+
+ public int getFrequentRenterPoints(int daysRented) {
+ return _price.getFrequentRenterPoints(daysRented);
+ }
+}
diff --git a/NewReleasePrice.java b/NewReleasePrice.java
new file mode 100644
index 00000000..240e4eb9
--- /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) {
+ // Sobrescrevendo para tratar o caso especial
+ return (daysRented > 1) ? 2 : 1;
+ }
+}
diff --git a/POM.xml b/POM.xml
new file mode 100644
index 00000000..a23a97f7
--- /dev/null
+++ b/POM.xml
@@ -0,0 +1,54 @@
+
+ 4.0.0
+ com.example
+ rental-system
+ 1.0-SNAPSHOT
+
+
+ 17
+ 17
+ 5.9.3
+
+
+
+
+ org.junit.jupiter
+ junit-jupiter
+ ${junit.jupiter.version}
+ test
+
+
+
+ org.slf4j
+ slf4j-api
+ 2.0.9
+
+
+ org.slf4j
+ slf4j-simple
+ 2.0.9
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.10.1
+
+ ${maven.compiler.source}
+ ${maven.compiler.target}
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 3.1.2
+
+
+
+
diff --git a/Price.java b/Price.java
new file mode 100644
index 00000000..231eaa0a
--- /dev/null
+++ b/Price.java
@@ -0,0 +1,9 @@
+public abstract class Price {
+ public abstract int getPriceCode();
+ public abstract double getCharge(int daysRented);
+
+ public int getFrequentRenterPoints(int daysRented) {
+ // Regra padrão para pontos de aluguel
+ return 1;
+ }
+}
diff --git a/RegularPrice.java b/RegularPrice.java
new file mode 100644
index 00000000..96612bd3
--- /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 result = 2;
+ if (daysRented > 2) {
+ result += (daysRented - 2) * 1.5;
+ }
+ return result;
+ }
+}
diff --git a/Rental.java b/Rental.java
new file mode 100644
index 00000000..e51a4e70
--- /dev/null
+++ b/Rental.java
@@ -0,0 +1,26 @@
+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() {
+ // Delegar cálculo para a classe Movie
+ return _movie.getFrequentRenterPoints(_daysRented);
+ }
+}
diff --git a/Statement.java b/Statement.java
new file mode 100644
index 00000000..519fbd90
--- /dev/null
+++ b/Statement.java
@@ -0,0 +1,23 @@
+import java.util.Enumeration;
+
+public abstract class Statement {
+
+ // Método Template
+ public String value(Customer aCustomer) {
+ String result = headerString(aCustomer);
+
+ Enumeration rentals = aCustomer.getRentals();
+ while (rentals.hasMoreElements()) {
+ Rental each = (Rental) rentals.nextElement();
+ result += rentalString(each);
+ }
+
+ result += footerString(aCustomer);
+ return result;
+ }
+
+ // Métodos abstratos a serem implementados pelas subclasses
+ protected abstract String headerString(Customer aCustomer);
+ protected abstract String rentalString(Rental aRental);
+ protected abstract String footerString(Customer aCustomer);
+}
diff --git a/TextStatement.java b/TextStatement.java
new file mode 100644
index 00000000..25c87dd2
--- /dev/null
+++ b/TextStatement.java
@@ -0,0 +1,21 @@
+public class TextStatement extends Statement {
+
+ @Override
+ protected String headerString(Customer aCustomer) {
+ return "Rental Record for " + aCustomer.getName() + "\n";
+ }
+
+ @Override
+ protected String rentalString(Rental aRental) {
+ return "\t" + aRental.getMovie().getTitle() + "\t" +
+ String.valueOf(aRental.getCharge()) + "\n";
+ }
+
+ @Override
+ protected String footerString(Customer aCustomer) {
+ return "Amount owed is " + String.valueOf(aCustomer.getTotalCharge()) + "\n" +
+ "You earned " + String.valueOf(aCustomer.getTotalFrequentRenterPoints()) +
+ " frequent renter points";
+ }
+}
+