我目前正在製作一個項目,要求我爲小企業製作節目(在這種情況下是一個小電影院),我可以在這裏爲各種產品和客戶錄製和打印收據。尋找班級指導
我到目前爲止是一系列記錄客戶想要訂購的代碼。
我該如何着手製作另一個存儲並計算價格的課程,並向控制檯輸出收據的樣子?
我不是要求答案,只是一些指導。
namespace RecieptApp
{
class Reciept
{
public void Main()
{
double DoubleDiscount;
int IntFoodOrdered;
int IntDrinkOrdered;
double DoubleFoodSize;
double DoubleDrinkSize;
int ACustomer;
int BCustomer;
string CustomerDescription;
string FoodDescription;
string DrinkDescription;
Console.Write("How many adults: ");
ACustomer = Console.Read();
Console.Write("How many kids: ");
BCustomer = Console.Read();
while (true)
{
Console.Write("Are you a government employee, current or retired military, or classified disabled? (Please answer yes or no) :");
string input1 = Console.ReadLine();
if (input1 == "yes")
{
DoubleDiscount = .15;
CustomerDescription = "Special Discount";
}
else
{
break;
}
}
while (true)
{
Console.WriteLine("Would you like to order some popcorn?");
string FoodInput1 = Console.ReadLine();
if (FoodInput1 == "yes")
{
Console.WriteLine("How many would you like?");
int.TryParse(Console.ReadLine(), out IntFoodOrdered);
while (true)
{
Console.WriteLine("And would you like that in small or large?");
string FoodInput2 = Console.ReadLine();
if (FoodInput2 == "small")
{
DoubleFoodSize = 3.75;
FoodDescription = "S";
}
else
{
DoubleFoodSize = 6.75;
FoodDescription = "L";
}
}
}
else
{
break;
}
}
while (true)
{
Console.WriteLine("Would you like to order a drink?");
string DrinkInput1 = Console.ReadLine();
if (DrinkInput1 == "yes")
{
Console.WriteLine("How many would you like?");
int.TryParse(Console.ReadLine(), out IntDrinkOrdered);
while (true)
{
Console.WriteLine("And Would you like that in small or large?");
string DrinkInput2 = Console.ReadLine();
if (DrinkInput2 == "small")
{
DoubleDrinkSize = 2.75;
DrinkDescription = "S";
}
else
{
DoubleDrinkSize = 5.75;
DrinkDescription = "L";
}
}
}
}
//This is where the other class would go in
//I just dont know how to go about it so that it would minimized the amount of code I have //to write
RecieptList Items = new RecieptList();
Items.AddProduct(ACustomer);
Items.AddProduct(BCustomer);
Items.AddProduct(CustomerDescription);
Items.AddProduct(FoodDescription);
Items.AddProduct(DrinkDescription);
}
}
}
('e'在'e'之前,'c'後面除外)。至少,您需要添加一個'price'變量,並在每次購買時添加。那不需要在另一個類 – mcalex
。你可以看看[這篇文章](http://social.msdn.microsoft.com/Forums/en/windowsgeneraldevelopmentissues/thread/0b802bd6-25ea-4a1f-8cb1-a1fabbb05356)的一些想法。如果你可以得到一個[Headfirstc#](http://www.headfirstlabs.com/books/hfcsharp/),它可以爲類,對象,方法提供美麗的指導。 :-) – bonCodigo