-
Notifications
You must be signed in to change notification settings - Fork 1
code-review-1 #1
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
HerrNiklasRaab
wants to merge
1
commit into
master
Choose a base branch
from
code-review-1
base: master
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
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
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 |
|---|---|---|
| @@ -1,95 +1,170 @@ | ||
| public class Customer { | ||
| public class Customer | ||
| { | ||
| private String name; | ||
| private List<Rental> rentals = new List<Rental> (); | ||
| public Customer (String name) { | ||
| private List<Rental> rentals; | ||
| public Customer(String name) | ||
| { | ||
| this.name = name; | ||
| this.rentals = new List<Rental>(); | ||
| } | ||
|
|
||
| public String getName () { | ||
| public String getName() | ||
| { | ||
| return name; | ||
| } | ||
|
|
||
| public void addRental (Rental rental) { | ||
| rentals.Add (rental); | ||
| } | ||
|
|
||
| public String statement () { | ||
| double totalAmount = 0; | ||
| int frequentRenterPoints = 0; | ||
|
|
||
| String result = "Rental record for " + getName () + "\n"; | ||
| foreach (var rental in rentals) { | ||
| double amount = 0; | ||
| switch (rental.getMovie ().getPriceCode ()) { | ||
| case Movie.REGULAR: | ||
| amount += 2; | ||
| if (rental.getDaysRented () > 2) | ||
| amount += (rental.getDaysRented () - 2) * 1.5; | ||
| break; | ||
| case Movie.NEW_RELEASE: | ||
| amount += rental.getDaysRented () * 3; | ||
| break; | ||
| case Movie.CHILDREN: | ||
| amount += 1.5; | ||
| if (rental.getDaysRented () > 3) | ||
| amount += (rental.getDaysRented () - 3) * 1.5; | ||
| break; | ||
| } | ||
| // add frequent renter points | ||
| frequentRenterPoints++; | ||
| // add bonus for a two day new release rental | ||
| if (rental.getMovie ().getPriceCode () == Movie.NEW_RELEASE && rental.getDaysRented () > 1) | ||
| frequentRenterPoints++; | ||
|
|
||
| // show figures for this rental | ||
| result += "\t" + rental.getMovie ().getTitle () + "\t" + amount + "\n"; | ||
|
|
||
| totalAmount += amount; | ||
| } | ||
| result += "Amount owed is " + totalAmount + "\n"; | ||
| result += "You earned " + frequentRenterPoints + " frequent renter points"; | ||
| return result; | ||
| public void addRental(Rental rental) | ||
| { | ||
| rentals.Add(rental); | ||
| } | ||
|
|
||
| public String statement() | ||
| { | ||
| StringBuilder statementBuilder = new StringBuilder($"Rental record for {getName()}\n"); | ||
|
|
||
| var statementElements = rentals.Select(rental => | ||
| { | ||
| return new | ||
| { | ||
| Amount = rental.GetAmount(), | ||
| FrequentRenterPoints = new FrequentRenterPoints(rental).GetEarnedPoints(), | ||
| Description = $"\t{rental.getMovie().getTitle()}\t{rental.GetAmount()}" | ||
| }; | ||
| }); | ||
|
|
||
| WriteOwedAmountTo(statementElements.Sum(statementElmenet => statementElmenet.Amount), statementBuilder); | ||
| WriteFrequentRenterPointstTo(statementElements.Sum(statementElmenet => statementElmenet.FrequentRenterPoints), statementBuilder); | ||
|
Comment on lines
+35
to
+36
Contributor
Author
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. Single Responsibility |
||
|
|
||
| return statementBuilder.ToString(); | ||
| } | ||
|
|
||
| private void WriteOwedAmountTo(double ownedAmount, StringBuilder statement) | ||
| { | ||
| statement.Append($"Amount owed is " + ownedAmount + "\n"); | ||
| } | ||
| private void WriteFrequentRenterPointstTo(double frequentRenterPoints, StringBuilder statement) | ||
| { | ||
| statement.Append($"You earned {frequentRenterPoints} frequent renter points"); | ||
| } | ||
|
|
||
| } | ||
| public class Rental { | ||
| private Movie movie; | ||
| private int daysRented; | ||
|
|
||
| public Rental (Movie movie, int daysRented) { | ||
| this.movie = movie; | ||
| this.daysRented = daysRented; | ||
| public class FrequentRenterPoints | ||
| { | ||
| public Rental Rental { get; set; } | ||
| public FrequentRenterPoints(Rental rental) | ||
| { | ||
| this.Rental = rental; | ||
| } | ||
|
|
||
| public Movie getMovie () { | ||
| return movie; | ||
| public int GetEarnedPoints() | ||
| { | ||
| if (EligibleForBonusPoints()) { return 2; } | ||
| return 1; | ||
| } | ||
|
|
||
| public int getDaysRented () { | ||
| return daysRented; | ||
| public bool EligibleForBonusPoints() | ||
| { | ||
| return Rental.getMovie().GetMovieRentalStrategy() is MovieNewReleaseRentalStrategy && | ||
| Rental.getDaysRented() > 1; | ||
| } | ||
|
|
||
| } | ||
|
Comment on lines
+52
to
72
Contributor
Author
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. Feature Envy |
||
| public class Movie { | ||
| public const int CHILDREN = 2; | ||
| public const int REGULAR = 0; | ||
| public const int NEW_RELEASE = 1; | ||
|
|
||
| public class Movie | ||
| { | ||
|
|
||
| private String title; | ||
| private int priceCode; | ||
| private MovieRentalStrategy movieRentalStrategy; | ||
|
|
||
| public Movie (String title, int priceCode) { | ||
| public Movie(String title, int priceCode, MovieRentalStrategy movieRentalStrategy) | ||
| { | ||
| this.title = title; | ||
| this.priceCode = priceCode; | ||
| this.movieRentalStrategy = movieRentalStrategy; | ||
| } | ||
|
|
||
| public String getTitle () { | ||
| public String getTitle() | ||
| { | ||
| return title; | ||
| } | ||
| public MovieRentalStrategy GetMovieRentalStrategy() | ||
| { | ||
| return movieRentalStrategy; | ||
| } | ||
|
|
||
| public int getPriceCode () { | ||
| public int getPriceCode() | ||
| { | ||
| return priceCode; | ||
| } | ||
|
|
||
| public void setPriceCode (int priceCode) { | ||
| public void setPriceCode(int priceCode) | ||
| { | ||
| this.priceCode = priceCode; | ||
| } | ||
| } | ||
|
|
||
| public MovieRentalStrategy getMovieRentalStrategy() | ||
| { | ||
| return movieRentalStrategy; | ||
| } | ||
| } | ||
|
|
||
| public class Rental | ||
| { | ||
| private Movie movie; | ||
| private int daysRented; | ||
|
|
||
| public Rental(Movie movie, int daysRented) | ||
| { | ||
| this.movie = movie; | ||
| this.daysRented = daysRented; | ||
| } | ||
| public Movie getMovie() | ||
| { | ||
| return movie; | ||
| } | ||
|
|
||
| public double GetAmount() | ||
| { | ||
| return movie.GetMovieRentalStrategy().GetRentAmount(this); | ||
| } | ||
| public int getDaysRented() | ||
| { | ||
| return daysRented; | ||
| } | ||
| } | ||
|
|
||
| public abstract class MovieRentalStrategy | ||
| { | ||
| public abstract double GetRentAmount(Rental rental); | ||
| } | ||
|
|
||
| public class MovieRegularRentalStrategy : MovieRentalStrategy | ||
| { | ||
| public override double GetRentAmount(Rental rental) | ||
| { | ||
| if (rental.getDaysRented() > 2) { return (rental.getDaysRented() - 2) * 1.5; } | ||
|
|
||
| return 0.0; | ||
| } | ||
| } | ||
|
|
||
| public class MovieNewReleaseRentalStrategy : MovieRentalStrategy | ||
| { | ||
| public override double GetRentAmount(Rental rental) | ||
| { | ||
| return rental.getDaysRented() * 3; | ||
| } | ||
| } | ||
|
|
||
| public class MovieChildrenRentalStrategy : MovieRentalStrategy | ||
| { | ||
| private const double BASE_AMOUNT = 1.5; | ||
| public override double GetRentAmount(Rental rental) | ||
| { | ||
| if (rental.getDaysRented() > 3) { return BASE_AMOUNT + ((rental.getDaysRented() - 3) * 1.5); } | ||
|
|
||
| return 0.0; | ||
| } | ||
| } | ||
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.
Useless, you could also have iterated directly over rental.