This commit is contained in:
parent
a95bf5e7a2
commit
fa94b9297f
4 changed files with 21 additions and 13 deletions
|
|
@ -1,11 +1,14 @@
|
|||
package movierental.MoviePriceCalculation;
|
||||
|
||||
public class ChildrenMoviePriceCalculation implements MoviePriceCalculationStrategy {
|
||||
private final static double BASE_AMOUNT = 1.5;
|
||||
private final static int DAYS_RENTED_THRESHOLD = 3;
|
||||
|
||||
@Override
|
||||
public double calculatePrice(int daysRented) {
|
||||
double thisAmount = 1.5;
|
||||
if (daysRented > 3) {
|
||||
thisAmount += (daysRented - 3) * 1.5;
|
||||
double thisAmount = BASE_AMOUNT;
|
||||
if (daysRented > DAYS_RENTED_THRESHOLD) {
|
||||
thisAmount += (daysRented - DAYS_RENTED_THRESHOLD) * BASE_AMOUNT;
|
||||
}
|
||||
return thisAmount;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package movierental.MoviePriceCalculation;
|
||||
|
||||
public class NewReleaseMoviePriceCalculation implements MoviePriceCalculationStrategy {
|
||||
private final static double BASE_AMOUNT = 3;
|
||||
@Override
|
||||
public double calculatePrice(int daysRented) {
|
||||
return daysRented * 3;
|
||||
return daysRented * BASE_AMOUNT;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
package movierental.MoviePriceCalculation;
|
||||
|
||||
public class RegularMoviePriceCalculation implements MoviePriceCalculationStrategy {
|
||||
private final static double BASE_AMOUNT = 2;
|
||||
private final static int DAYS_RENTED_THRESHOLD = 2;
|
||||
private final static double EXTRA_AMOUNT = 1.5;
|
||||
|
||||
@Override
|
||||
public double calculatePrice(int daysRented) {
|
||||
double thisAmount = 2;
|
||||
if (daysRented > 2) {
|
||||
thisAmount += (daysRented - 2) * 1.5;
|
||||
double thisAmount = BASE_AMOUNT;
|
||||
if (daysRented > DAYS_RENTED_THRESHOLD) {
|
||||
thisAmount += (daysRented - DAYS_RENTED_THRESHOLD) * EXTRA_AMOUNT;
|
||||
}
|
||||
return thisAmount;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ class RentalTest {
|
|||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"2, 0, 2.0", // regular movie, no overtime
|
||||
"3, 0, 3.5", // regular movie, with overtime
|
||||
"1, 1, 3.0", // new release movie, one day
|
||||
"2, 1, 6.0", // new release movie, two days
|
||||
"3, 2, 1.5", // children movie, no overtime
|
||||
"4, 2, 3.0" // children movie, with overtime
|
||||
"2, 0, 2.0", // regular movie, no overtime, should return 2.0
|
||||
"3, 0, 3.5", // regular movie, with overtime, should return 3.5
|
||||
"1, 1, 3.0", // new release movie, one day, should return 3.0
|
||||
"2, 1, 6.0", // new release movie, two days, should return 6.0
|
||||
"3, 2, 1.5", // children movie, no overtime, should return 1.5
|
||||
"4, 2, 3.0" // children movie, with overtime, should return 3.0
|
||||
})
|
||||
void should_return_correct_price_for_movie(int daysRented, int movie_type, double expected) {
|
||||
// Given
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue