Move the calculation for the amount from Customer to Rental class MoveAmountCalculation
authorMichael Welch <michaelgwelch@gmail.com>
Mon, 6 Feb 2012 21:56:04 +0000 (15:56 -0600)
committerMichael Welch <michaelgwelch@gmail.com>
Mon, 6 Feb 2012 21:56:04 +0000 (15:56 -0600)
RefactoringChapter1/Customer.cs
RefactoringChapter1/Rental.cs

index ab36d7a..f397ccd 100644 (file)
@@ -31,7 +31,7 @@ namespace RefactoringChapter1
                        // determine ammounts for each line
                        foreach (Rental rental in rentals)
                        {
-                               double thisAmount = AmountFor(rental);
+                               double thisAmount = rental.Charge;
                                
                                // add frequent renter points
                                frequentRenterPoints++;
@@ -59,34 +59,7 @@ namespace RefactoringChapter1
                        
                }
                
-               private double AmountFor (Rental rental)
-               {
-                       double result = 0;
-                       switch (rental.Movie.PriceCode)
-                       {
-                       case Movie.Regular:
-                               result += 2;
-                               if (rental.DaysRented > 2)
-                               {
-                                       result += (rental.DaysRented - 2) * 1.5;
-                               }
-                               break;
-                                       
-                       case Movie.NewRelease:
-                               result += rental.DaysRented * 3;
-                               break;
-                                       
-                       case Movie.Childrens:
-                               result += 1.5;
-                               if (rental.DaysRented > 3)
-                               {
-                                       result += (rental.DaysRented - 3) * 1.5;
-                               }
-                               break;
-                                               
-                       }
-                       return result;
-               }
+
        }
 }
 
index 13625c3..e624163 100644 (file)
@@ -7,7 +7,6 @@ namespace RefactoringChapter1
                private Movie _movie;
                private int _daysRented;
                
-               
                public Rental (Movie movie, int daysRented)
                {
                        _movie = movie;
@@ -23,6 +22,40 @@ namespace RefactoringChapter1
                {
                        get { return _movie; }
                }
+               
+               public double Charge 
+               {
+                       get 
+                       {
+                               double result = 0;
+                               switch (Movie.PriceCode)
+                               {
+                               case Movie.Regular:
+                                       result += 2;
+                                       if (DaysRented > 2)
+                                       {
+                                               result += (DaysRented - 2) * 1.5;
+                                       }
+                                       break;
+                                       
+                               case Movie.NewRelease:
+                                       result += DaysRented * 3;
+                                       break;
+                                       
+                               case Movie.Childrens:
+                                       result += 1.5;
+                                       if (DaysRented > 3)
+                                       {
+                                               result += (DaysRented - 3) * 1.5;
+                                       }
+                                       break;
+                                               
+                               }
+                               return result;
+                       }
+               }
        }
+       
+       
 }