Commit of initial program InitialProgram
authorMichael Welch <michaelgwelch@gmail.com>
Mon, 6 Feb 2012 21:15:20 +0000 (15:15 -0600)
committerMichael Welch <michaelgwelch@gmail.com>
Mon, 6 Feb 2012 21:15:20 +0000 (15:15 -0600)
RefactoringChapter1/Customer.cs [new file with mode: 0644]
RefactoringChapter1/Movie.cs
RefactoringChapter1/RefactoringChapter1.csproj
RefactoringChapter1/Rental.cs [new file with mode: 0644]

diff --git a/RefactoringChapter1/Customer.cs b/RefactoringChapter1/Customer.cs
new file mode 100644 (file)
index 0000000..d990f04
--- /dev/null
@@ -0,0 +1,85 @@
+using System;
+using System.Collections.Generic;
+
+namespace RefactoringChapter1
+{
+       public class Customer
+       {
+               private string _name;
+               private List<Rental> rentals = new List<Rental> ();
+               
+               public Customer (string name)
+               {
+                       _name = name;
+               }
+               
+               public void AddRental (Rental rental)
+               {
+                       rentals.Add (rental);
+               }
+               
+               public string Name {
+                       get { return _name; }
+               }
+               
+               public string Statement ()
+               {
+                       double totalAmount = 0;
+                       int frequentRenterPoints = 0;
+                       string result = "Rental Record for " + Name + "\n";
+                       
+                       // determine ammounts for each line
+                       foreach (Rental rental in rentals) 
+                       {
+                               double thisAmount = 0;
+                               
+                               switch (rental.Movie.PriceCode) 
+                               {
+                               case Movie.Regular:
+                                       thisAmount += 2;
+                                       if (rental.DaysRented > 2) {
+                                               thisAmount += (rental.DaysRented - 2) * 1.5;
+                                       }
+                                       break;
+                                       
+                               case Movie.NewRelease:
+                                       thisAmount += rental.DaysRented * 3;
+                                       break;
+                                       
+                               case Movie.Childrens:
+                                       thisAmount += 1.5;
+                                       if (rental.DaysRented > 3) {
+                                               thisAmount += (rental.DaysRented - 3) * 1.5;
+                                       }
+                                       break;
+                                               
+                               }
+                               
+                               // add frequent renter points
+                               frequentRenterPoints++;
+                       
+                               // add bonus for a two day new release rental
+                               if (rental.Movie.PriceCode == Movie.NewRelease &&
+                                   rental.DaysRented > 1)
+                               {
+                                       frequentRenterPoints++;
+                               }
+                               
+                               // show figures for this rental
+                               result += "\t" + rental.Movie.Title + "\t" +
+                                       thisAmount + "\n";
+                               
+                               totalAmount += thisAmount;
+                       }
+                       
+                       // add footer lines
+                       result += "Amount owed is " + totalAmount + "\n";
+                       result += "You earned " + frequentRenterPoints + " frequent renter points";
+                       return result;
+                       
+
+                       
+               }
+       }
+}
+
index 072a1d6..350f5a2 100644 (file)
@@ -8,9 +8,27 @@ namespace RefactoringChapter1
                public const int Regular = 0;
                public const int NewRelease = 1;
                
-               public Movie ()
+               private string _title;
+               private int _priceCode;
+               
+               public Movie (string title, int priceCode)
+               {
+                       _title = title;
+                       _priceCode = priceCode;
+               }
+               
+               public int PriceCode 
+               { 
+                       get { return _priceCode; } 
+                       set { _priceCode = value; }
+               }
+               
+               public string Title 
                {
+                       get { return _title; } 
                }
+               
+               
        }
 }
 
index 22491ab..ed72d2e 100644 (file)
@@ -34,6 +34,8 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Movie.cs" />
+    <Compile Include="Rental.cs" />
+    <Compile Include="Customer.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
 </Project>
\ No newline at end of file
diff --git a/RefactoringChapter1/Rental.cs b/RefactoringChapter1/Rental.cs
new file mode 100644 (file)
index 0000000..13625c3
--- /dev/null
@@ -0,0 +1,28 @@
+using System;
+
+namespace RefactoringChapter1
+{
+       public class Rental
+       {
+               private Movie _movie;
+               private int _daysRented;
+               
+               
+               public Rental (Movie movie, int daysRented)
+               {
+                       _movie = movie;
+                       _daysRented = daysRented;
+               }
+               
+               public int DaysRented 
+               {
+                       get { return _daysRented; }
+               }
+               
+               public Movie Movie 
+               {
+                       get { return _movie; }
+               }
+       }
+}
+