Move charge and frequentrenterpoints calculations from Rental to Movie
authorMichael Welch <michaelgwelch@gmail.com>
Fri, 24 Feb 2012 14:53:12 +0000 (08:53 -0600)
committerMichael Welch <michaelgwelch@gmail.com>
Fri, 24 Feb 2012 14:53:12 +0000 (08:53 -0600)
RefactoringChapter1/Movie.cs
RefactoringChapter1/Rental.cs

index b418801..378248c 100644 (file)
@@ -26,6 +26,44 @@ namespace RefactoringChapter1
             get { return _title; }
         }
 
+        public double GetCharge(int daysRented)
+        {
+
+            double result = 0;
+            switch (PriceCode)
+            {
+                case Regular:
+                    result += 2;
+                    if (daysRented > 2)
+                    {
+                        result += (daysRented - 2) * 1.5;
+                    }
+                    break;
+
+                case NewRelease:
+                    result += daysRented * 3;
+                    break;
+
+                case Childrens:
+                    result += 1.5;
+                    if (daysRented > 3)
+                    {
+                        result += (daysRented - 3) * 1.5;
+                    }
+                    break;
+
+            }
+            return result;
+
+        }
+
+        public int GetFrequentRenterPoints(int daysRented)
+        {
+            return (PriceCode == NewRelease &&
+                    daysRented > 1)
+                       ? 2
+                       : 1;
+        }
 
     }
 }
index df2477c..6cf8888 100644 (file)
@@ -23,45 +23,12 @@ namespace RefactoringChapter1
 
         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;
-            }
+            get { return Movie.GetCharge(DaysRented); }
         }
 
         public int FrequentRenterPoints
         {
-            get
-            {
-
-                return (Movie.PriceCode == Movie.NewRelease &&
-                    DaysRented > 1) ? 2 : 1;
-
-            }
+            get { return Movie.GetFrequentRenterPoints(DaysRented); }
         }
     }