-
Notifications
You must be signed in to change notification settings - Fork 2
Cynthia refactor video #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CynthiaTerrazas
wants to merge
12
commits into
develop
Choose a base branch
from
CynthiaVideo
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
faf8a84
initial solution for bank ocr
c91cd0a
Merge branch 'develop' of https://github.com/AT-04/coding into cynthi…
cynthiaT 57beff0
solution banck OCR
cynthiaT 507e56b
fix warning message using StringBuffer
cynthiaT 1593614
fix observations
cynthiaT 0f30342
Merge branch 'develop' of https://github.com/AT-04/coding into cynthi…
cynthiaT 2fc9f93
Merge branch 'develop' of https://github.com/AT-04/coding into cynthi…
cynthiaT 5a1d847
refactor movie code
cynthiaT bd507dc
fix observations
cynthiaT a7e1993
Merge branch 'develop' of https://github.com/AT-04/coding into Cynthi…
cynthiaT c484d50
Merge branch 'develop' of https://github.com/AT-04/coding into Cynthi…
cynthiaT bc441ea
fix observations
cynthiaT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/java/org/fundacionjala/coding/cynthia/Video/Children.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
83
src/main/java/org/fundacionjala/coding/cynthia/Video/Customer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
|
||
| /** | ||
| * 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
57
src/main/java/org/fundacionjala/coding/cynthia/Video/Movie.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
27
src/main/java/org/fundacionjala/coding/cynthia/Video/Regular.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
38
src/main/java/org/fundacionjala/coding/cynthia/Video/Release.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
50
src/main/java/org/fundacionjala/coding/cynthia/Video/Rental.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
103
src/test/java/org/fundacionjala/coding/cynthia/VideoTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.