Skip to content
Open
25 changes: 25 additions & 0 deletions src/main/java/org/fundacionjala/coding/cynthia/Video/Children.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.fundacionjala.coding.cynthia.Video;

/**
* movie class.
*/
public class Children extends Movie {

/**
* movie constructor.
*
* @param title movie.
* @param priceCode movie.
*/
public Children(String title, int priceCode) {
super(title, priceCode);
}

/**
* @return Cost of the days rented by all movie.
*/
@Override
public double costDaysRented(Rental rental) {
return rental.getDaysRented() > 2 ? ((rental.getDaysRented() - 3) * 1.5) + 1.5 : 1.5;
}
}
83 changes: 83 additions & 0 deletions src/main/java/org/fundacionjala/coding/cynthia/Video/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.fundacionjala.coding.cynthia.Video;

import java.util.ArrayList;
import java.util.List;

/**
* costumer class.
*/
public class Customer {
private String customerName;
private List<Rental> movieRentals;
private double totalAmount = 0;
private int frequentRenterPoints;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these attributes are no longer necessary because you have methods that are returned the totalAmount and totalFrequentRenterPoints.


/**
* constumer constructor.
*
* @param name of the client.
*/
public Customer(String name) {
customerName = name;
movieRentals = new ArrayList<>();
}

/**
* add a new rental fr the customer.
*
* @param arg rental that will added for the customer.
*/
public void addRental(Rental arg) {
movieRentals.add(arg);
}

/**
* @return name of the customer.
*/
public String getName() {
return customerName;
}

/**
* @return all movies rented.
*/
public String moviesRented() {
StringBuffer result = new StringBuffer();
movieRentals.forEach(rental -> {
result.append("\t" + rental.getMovie().getTitle() + "\t" + String.valueOf(rental.costDaysRented()) + "\n");
});
return result.toString();
}

/**
* @return total cost for all movies rented.
*/
public double totalCostRented() {
movieRentals.forEach(rental -> {
totalAmount += rental.costDaysRented();
});
return totalAmount;
}

/**
* @return return the bonus for all movies rented.
*/
public int totalBonusFrequencyRented() {
movieRentals.forEach(rental -> {
frequentRenterPoints += 1 + rental.bonusTwoDaysNewReleaseRental();
});
return frequentRenterPoints;
}

/**
* @return all information about movies rented for the customer.
*/
public String statement() {
StringBuffer result = new StringBuffer();
result.append("Rental Record for " + getName() + "\n");
result.append(this.moviesRented());
result.append("Amount owed is " + String.valueOf(this.totalCostRented()) + "\n");
result.append("You earned " + String.valueOf(this.totalBonusFrequencyRented()) + " frequent renter points");
return result.toString();
}
}
57 changes: 57 additions & 0 deletions src/main/java/org/fundacionjala/coding/cynthia/Video/Movie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.fundacionjala.coding.cynthia.Video;

/**
* movie class.
*/
abstract class Movie {
private static final int DEFAULT_BONUS_DAY_RENTED = 0;
private String titleMovie;
private int priceCodeMovie;

/**
* movie constructor.
* @param title movie.
* @param priceCode movie.
*/
Movie(String title, int priceCode) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need the priceCode?

titleMovie = title;
priceCodeMovie = priceCode;
}

/**
* @return price code of the movie.
*/
public int getPriceCode() {
return priceCodeMovie;
}

/**
* @param arg set the price code for the movie.
*/
public void setPriceCode(int arg) {
priceCodeMovie = arg;
}

/**
* @return the title for the movie.
*/
public String getTitle() {
return titleMovie;
}

/**
*
* @param rental to get the cost of days rented by movie.
* @return cost days by movies rented.
*/
public abstract double costDaysRented(Rental rental);

/**
*
* @param rental movie.
* @return bonus by movie rented.
*/
public int bonusTwoDaysNewReleaseRental(Rental rental) {
return DEFAULT_BONUS_DAY_RENTED;
}
}
27 changes: 27 additions & 0 deletions src/main/java/org/fundacionjala/coding/cynthia/Video/Regular.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.fundacionjala.coding.cynthia.Video;

/**
* movie class.
*/
public class Regular extends Movie {
public static final int REGULAR = 0;

/**
* movie constructor.
*
* @param title movie.
* @param priceCode movie.
*/
public Regular(String title, int priceCode) {
super(title, priceCode);
}

/**
* @return Cost of the days rented by all movie.
*/
@Override
public double costDaysRented(Rental rental) {
return rental.getDaysRented() > 2 ? ((rental.getDaysRented() - 2) * 1.5) + 2 : 2;
}

}
38 changes: 38 additions & 0 deletions src/main/java/org/fundacionjala/coding/cynthia/Video/Release.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.fundacionjala.coding.cynthia.Video;

/**
* movie class.
*/
public class Release extends Movie {

/**
* movie constructor.
*
* @param title movie.
* @param priceCode movie.
*/
public Release(String title, int priceCode) {
super(title, priceCode);
}

/**
* @return Cost of the days rented by all movie.
*/
@Override
public double costDaysRented(Rental rental) {
return rental.getDaysRented() * 3;
}

/**
*
* @param rental movie.
* @return bonus by movie rented.
*/
@Override
public int bonusTwoDaysNewReleaseRental(Rental rental) {
if (rental.getDaysRented() > 1) {
return 1;
}
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refactor this method in a single line.

}
}
50 changes: 50 additions & 0 deletions src/main/java/org/fundacionjala/coding/cynthia/Video/Rental.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.fundacionjala.coding.cynthia.Video;

/**
* Rental Class.
*/
public class Rental {
private Movie movie;
private int daysRented;

/**
* Rental constructor.
*
* @param movie rental.
* @param daysRented rental.
*/
public Rental(Movie movie, int daysRented) {
this.movie = movie;
this.daysRented = daysRented;
}

/**
* get days rented.
*
* @return number of days by movie rented.
*/
public int getDaysRented() {
return daysRented;
}

/**
* @return movie rented.
*/
public Movie getMovie() {
return movie;
}

/**
* @return Cost of the days rented by all movie.
*/
public double costDaysRented() {
return movie.costDaysRented(this);
}

/**
* @return bonus for frequency.
*/
public int bonusTwoDaysNewReleaseRental() {
return movie.bonusTwoDaysNewReleaseRental(this);
}
}
103 changes: 103 additions & 0 deletions src/test/java/org/fundacionjala/coding/cynthia/VideoTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package org.fundacionjala.coding.cynthia;

import org.fundacionjala.coding.cynthia.Video.Customer;
import org.fundacionjala.coding.cynthia.Video.Regular;
import org.fundacionjala.coding.cynthia.Video.Release;
import org.fundacionjala.coding.cynthia.Video.Children;
import org.fundacionjala.coding.cynthia.Video.Rental;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
* Created by USUARIO on 07/06/2017.
*/
public class VideoTest {

/**
* verify the rental for one customer (RELESEA, CHILDREN).
*/
@Test
public void testVideoOnCustomer() {
Customer customer = new Customer("Test");
customer.addRental(new Rental(new Release("The Revenant", 1), 2));
customer.addRental(new Rental(new Regular("Terminator", 0), 2));
assertEquals("Rental Record for Test\n"
+ "\tThe Revenant\t6.0\n"
+ "\tTerminator\t2.0\n"
+ "Amount owed is 8.0\n"
+ "You earned 3 frequent renter points", customer.statement());
}

/**
* verify just to one rented movie (RELEASE movie).
*/
@Test
public void testVideoOneVideoRented() {
Customer customer = new Customer("Juan");
customer.addRental(new Rental(new Release("The Revenant", 1), 4));
assertEquals("Rental Record for Juan\n"
+ "\tThe Revenant\t12.0\n"
+ "Amount owed is 12.0\n"
+ "You earned 2 frequent renter points", customer.statement());
}

/**
* verify the rental whithout bonus.
*/
@Test
public void testVideoWithoutBonus() {
Customer customer = new Customer("Pedro");
customer.addRental(new Rental(new Release("The Revenant", 1), 1));
assertEquals("Rental Record for Pedro\n"
+ "\tThe Revenant\t3.0\n"
+ "Amount owed is 3.0\n"
+ "You earned 1 frequent renter points", customer.statement());
}

/**
* verify the rental for several movies.
*/
@Test
public void testVideoSeveralMovies() {
Customer customer = new Customer("Oscar");
customer.addRental(new Rental(new Regular("The Revenant", 0), 1));
customer.addRental(new Rental(new Release("Cars", 1), 2));
customer.addRental(new Rental(new Children("king kong", 2), 5));
customer.addRental(new Rental(new Regular("Titanic", 0), 3));
customer.addRental(new Rental(new Children("Galaxy", 2), 4));
assertEquals("Rental Record for Oscar\n"
+ "\tThe Revenant\t2.0\n"
+ "\tCars\t6.0\n"
+ "\tking kong\t4.5\n"
+ "\tTitanic\t3.5\n"
+ "\tGalaxy\t3.0\n"
+ "Amount owed is 19.0\n"
+ "You earned 6 frequent renter points", customer.statement());
}

/**
* verify rental for two customers.
*/
@Test
public void testVideoTwoCustomers() {
Customer marcan = new Customer("marcan");
Customer agustin = new Customer("Agustin");
marcan.addRental(new Rental(new Regular("The Revenant", 0), 1));
marcan.addRental(new Rental(new Release("Cars", 1), 2));
marcan.addRental(new Rental(new Children("king kong", 2), 5));
agustin.addRental(new Rental(new Regular("Titanic", 0), 3));
agustin.addRental(new Rental(new Children("Galaxy", 2), 4));
assertEquals("Rental Record for marcan\n"
+ "\tThe Revenant\t2.0\n"
+ "\tCars\t6.0\n"
+ "\tking kong\t4.5\n"
+ "Amount owed is 12.5\n"
+ "You earned 4 frequent renter points", marcan.statement());
assertEquals("Rental Record for Agustin\n"
+ "\tTitanic\t3.5\n"
+ "\tGalaxy\t3.0\n"
+ "Amount owed is 6.5\n"
+ "You earned 2 frequent renter points", agustin.statement());
}
}