Permalink
Browse files

Extract method `DetermineAmount()`

  • Loading branch information...
rdeneau committed Aug 26, 2018
1 parent 7c1f314 commit 8f7fe338ac247c8f87e4a2bba6ac0d8da8eff39b
Showing with 23 additions and 18 deletions.
  1. +23 −18 2_Uncle_Bob_Full/Soat.CleanCode.VideoStore.UncleBobFull/Statement.cs
@@ -52,43 +52,48 @@ private string RentalLines()
private string RentalLine(Rental rental)
{
var rentalLine = "";
var thisAmount = 0m;
var rentalAmount = DetermineAmount(rental);

//dtermines the amount for each line
FrequentRenterPoints++;

if (rental.Movie.PriceCode == Movie.NEW_RELEASE
&& rental.DaysRented > 1)
{
FrequentRenterPoints++;
}

rentalLine += "\t" + rental.Movie.Title + "\t" + rentalAmount.ToString("0.0", CultureInfo.InvariantCulture) + Environment.NewLine;
TotalAmount += rentalAmount;
return rentalLine;
}

private static decimal DetermineAmount(Rental rental)
{
var rentalAmount = 0m;
switch (rental.Movie.PriceCode)
{
case Movie.REGULAR:
thisAmount += 2;
rentalAmount += 2;
if (rental.DaysRented > 2)
{
thisAmount += (rental.DaysRented - 2) * 1.5m;
rentalAmount += (rental.DaysRented - 2) * 1.5m;
}

break;
case Movie.NEW_RELEASE:
thisAmount += rental.DaysRented * 3;
rentalAmount += rental.DaysRented * 3;
break;
case Movie.CHILDREN:
thisAmount += 1.5m;
rentalAmount += 1.5m;
if (rental.DaysRented > 3)
{
thisAmount += (rental.DaysRented - 3) * 1.5m;
rentalAmount += (rental.DaysRented - 3) * 1.5m;
}

break;
}

FrequentRenterPoints++;

if (rental.Movie.PriceCode == Movie.NEW_RELEASE
&& rental.DaysRented > 1)
{
FrequentRenterPoints++;
}

rentalLine += "\t" + rental.Movie.Title + "\t" + thisAmount.ToString("0.0", CultureInfo.InvariantCulture) + Environment.NewLine;
TotalAmount += thisAmount;
return rentalLine;
return rentalAmount;
}

private string Footer()

0 comments on commit 8f7fe33

Please sign in to comment.