Permalink
Browse files

Extract `Initiliaze()`

- Create missing method `Initiliaze()` _(Java to C# conversion mistake - Uncle Bob extracted it at this point)_
- Rename `each` to `rental`
  • Loading branch information...
rdeneau committed Aug 21, 2018
1 parent d112c36 commit dddb891374a5869b90acc8058bbebd48aa9b5429
Showing with 17 additions and 10 deletions.
  1. +17 −10 2_Uncle_Bob_Full/Soat.CleanCode.VideoStore.UncleBobFull/Statement.cs
@@ -23,42 +23,43 @@ public void AddRental(Rental rental)

public string Generate()
{
Initialize();
var result = "Rental Record for " + CustomerName + "\n";
foreach (var each in _rentals)
foreach (var rental in _rentals)
{
var thisAmount = 0m;

//dtermines the amount for each line
switch (each.Movie.PriceCode)
switch (rental.Movie.PriceCode)
{
case Movie.REGULAR:
thisAmount += 2;
if (each.DaysRented > 2)
if (rental.DaysRented > 2)
{
thisAmount += (each.DaysRented - 2) * 1.5m;
thisAmount += (rental.DaysRented - 2) * 1.5m;
}
break;
case Movie.NEW_RELEASE:
thisAmount += each.DaysRented * 3;
thisAmount += rental.DaysRented * 3;
break;
case Movie.CHILDREN:
thisAmount += 1.5m;
if (each.DaysRented > 3)
if (rental.DaysRented > 3)
{
thisAmount += (each.DaysRented - 3) * 1.5m;
thisAmount += (rental.DaysRented - 3) * 1.5m;
}
break;
}

FrequentRenterPoints++;

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

result += "\t" + each.Movie.Title + "\t" + thisAmount.ToString("0.0", CultureInfo.InvariantCulture) + "\n";
result += "\t" + rental.Movie.Title + "\t" + thisAmount.ToString("0.0", CultureInfo.InvariantCulture) + "\n";
TotalAmount += thisAmount;
}

@@ -67,5 +68,11 @@ public string Generate()

return result;
}

private void Initialize()
{
FrequentRenterPoints = 0;
TotalAmount = 0m;
}
}
}

0 comments on commit dddb891

Please sign in to comment.