Как сделать рефакторинг - C#
Формулировка задачи:
как сделать рефакторинг? помогите пожалуйста, очень прошу
Customer.cs
Movie.cs
Program.cs
Rental.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rifactoring
{
class Customer
{
private string name = null;
private List<Rental> rentals = new List<Rental>();
public Customer(string name)
{
this.name = name;
}
public string Statement()
{
double totalAmount = 0;
int frequentRenterPoints = 0;
string result = string.Format("Учет аренды для {0}:", name);
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.New_Release:
thisAmount += rental.DaysRented * 3;
break;
case Movie.Childrens:
if (rental.DaysRented > 3)
thisAmount += (rental.DaysRented - 3) * 1.5;
break;
}
frequentRenterPoints++;
if ((rental.Movie.PriceCode == Movie.New_Release) && (rental.DaysRented>1))
frequentRenterPoints++;
result += "\t" + rental.Movie.Title + "\t" + thisAmount;
totalAmount += thisAmount;
}
result += "Сумма составляет" + totalAmount + "\n";
result += "Вы заработали" + frequentRenterPoints + "очков за активность";
return result;
}
//Свойства
public Rental Rentals
{
set { this.rentals.Add(value); }
}
public string Name
{
get { return this.name; }
}
}
}using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rifactoring
{
class Movie
{
public const int Childrens = 2;
public const int Regular = 0;
public const int New_Release = 1;
private string title = null;
private int priceCode = 0;
public Movie(String title, int priceCode)
{
this.title = title;
this.priceCode = priceCode;
}
//свойства
public int PriceCode
{
get {return this.priceCode;}
set { this.priceCode = value;}
}
public string Title
{
get { return this.title; }
}
}
}using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rifactoring
{
class Program
{
static void Main()
{
Customer customer = new Customer("Alex");
Movie movie = new Movie("Matrix", 1);
Rental rental = new Rental(movie, 2);
customer.Rentals = rental;
Console.WriteLine(customer.Statement());
Console.ReadKey();
}
}
}using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rifactoring
{
class Rental
{
private Movie movie = null;
private int daysRented = 0;
public Rental(Movie movie, int daysRented)
{
this.movie = movie;
this.daysRented = daysRented;
}
public int DaysRented
{
get { return daysRented; }
}
public Movie Movie
{
get { return movie; }
}
}
}Решение задачи: «Как сделать рефакторинг»
textual
Листинг программы
//Свойства
public Rental Rentals
{
set { this.rentals.Add(value); }
}