您可以帮我计算每种付款类型的总额,例如签证,万事达卡和贝宝。我已经创建了接口IPay并在Mastercard,Visa和PayPal类中继承它。它显示每个客户的详细信息以及订单数量和付款类型。我需要为每种付款类型计算总付款。谢谢。C#如何计算每种付款方式的总额
public class Program
{
public static void Main()
{
Customer[] custArray = new Customer[3];
// First Customer
custArray[0] = new Customer() { FirstName = "Adam", LastName = "Miles", Orders = new Order[2] };
custArray[0].Orders[0] = new Order() { Description = "Shoes", Price = 19.99M, Quantity = 1, Pay = new MasterCard() };
custArray[0].Orders[1] = new Order() { Description = "Gloves", Price = 29.99M, Quantity = 2,Pay = new Visa() };
// Second Customer
custArray[1] = new Customer() { FirstName = "Andrew", LastName = "Hart", Orders = new Order[2] };
custArray[1].Orders[0] = new Order() { Description = "Jacket", Price = 39.99M, Quantity = 1,Pay = new MasterCard() };
custArray[1].Orders[1] = new Order() { Description = "Socks", Price = 49.99M, Quantity = 1,Pay = new Paypal() };
foreach (var customer in custArray)
{
if (customer == null) continue;
Console.WriteLine("Customer:\n");
Console.WriteLine("{0, 15} {1, 17}", "First Name", "Last Name");
Console.WriteLine("{0, 10} {1, 20}", customer.FirstName, customer.LastName);
Console.WriteLine("Orders:\n");
foreach (var order in customer.Orders)
{
if (order == null) continue;
Console.WriteLine("{0, 10} {1, 10} {2, 10}{3, 15}", order.Description, order.Price, order.Quantity, order.Pay);
Console.WriteLine("\n\n");
decimal total = order.Price * order.Quantity;
Console.WriteLine("Total :", total);
if (order.Pay== new MasterCard())
{
total = total++;
Console.WriteLine("Visa Total", total);
}
else if (order.Pay == new Visa())
{
total = total++;
Console.WriteLine("Visa Total", total);
}
else if (order.Pay == new MasterCard())
{
total = total++;
Console.WriteLine("Visa Total", total);
}
}
Console.WriteLine("\n\n");
}
Console.ReadLine();
}
}
class Customer
{
public string FirstName;
public string LastName;
public Order[] Orders;
}
class Order
{
public string Description;
public decimal Price;
public int Quantity;
public IPay Pay;
// Payment type p=new pay
}
interface IPay
{
void PayType();
}
class MasterCard : IPay
{
public void PayType { get; set; }
}
class Paypal : IPay
{
public void PayType { get; set; }
}
public class Visa : IPay
{
public void PayType {get;set;}
}
你的问题开始,当你做'order.Pay ==新万事达()'。我诚实地不敢通过这种编程水平的代码来处理真钱(老实说,没有冒犯)。 – SimpleVar 2015-02-23 05:53:48
还有更多的问题。界面被美化paytype和执行它decorared财产?那太无效了? – Amit 2015-02-23 06:05:46
刚刚学习编程,这是我目前正在做的任务,并且无法弄清楚在循环条件下使用什么。 – xyz 2015-02-23 06:06:06