test
unknown
csharp
5 months ago
2.5 kB
1
Indexable
using System; using System.Collections.Generic; namespace VideoStore { class Customer { private string name; private Dictionary<Movie, int> rentals = new LinkedHashMap<Movie, int>(); // preserves order of elements public Customer(string name) { this.name = name; } public void AddRental(Movie m, int d) { rentals.Add(m, d); } public string GetName() { return name; } public string Statement() { double totalAmount = 0; int frequentRenterPoints = 0; string result = "Rental Record for " + GetName() + "\n"; // loop over each movie rental foreach (var entry in rentals) { Movie each = entry.Key; int dr = entry.Value; double thisAmount = 0; // determine amounts for every line switch (each.GetPriceCode()) { case Movie.REGULAR: thisAmount += 2; if (dr > 2) thisAmount += (dr - 2) * 1.5; break; case Movie.NEW_RELEASE: thisAmount += dr * 3; break; case Movie.CHILDRENS: thisAmount += 1.5; if (dr > 3) thisAmount += (dr - 3) * 1.5; break; } // add frequent renter points frequentRenterPoints++; // add bonus for a two-day new release rental if (each.GetPriceCode() != null && each.GetPriceCode() == Movie.NEW_RELEASE && dr > 1) { frequentRenterPoints++; } // show figures line for this rental result += "\t" + each.GetTitle() + "\t" + thisAmount + "\n"; totalAmount += thisAmount; } // add footer lines result += "Amount owed is " + totalAmount + "\n"; result += "You earned " + frequentRenterPoints + " frequent renter points"; return result; } } }
Editor is loading...
Leave a Comment