add Programmyday form github
This commit is contained in:
88
Warenkorb/Shoppingcart.cs
Normal file
88
Warenkorb/Shoppingcart.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Warenkorb
|
||||
{
|
||||
internal class Shoppingcart
|
||||
{
|
||||
//private Article[] articles;
|
||||
//private double salesVolume;
|
||||
//private double priceVolume;
|
||||
|
||||
//public Shoppingcart(int count)
|
||||
//{
|
||||
// articles = new Article[count];
|
||||
//}
|
||||
//public void AddArticle(Article article)
|
||||
//{
|
||||
// for (int i = 0; i < articles.Length; i++)
|
||||
// {
|
||||
// if (articles[i] is null)
|
||||
// {
|
||||
// articles[i] = article;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//public void PrintTotalPrice()
|
||||
//{
|
||||
// foreach (Article item in articleses)
|
||||
// {
|
||||
// if (item is not null)
|
||||
// {
|
||||
// this.priceVolume += item.GetPrice();
|
||||
// }
|
||||
// }
|
||||
// Console.WriteLine($"Stückzahl: {salesVolume}");
|
||||
// Console.WriteLine($"Gesamtpreis: {this.priceVolume}");
|
||||
//}
|
||||
//public void PrintInfo()
|
||||
//{
|
||||
// foreach (Article item in articleses)
|
||||
// {
|
||||
// if (item is not null)
|
||||
// {
|
||||
// item.PrintInfo();
|
||||
// Console.WriteLine();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//---------------------------------------------------------------------------------------
|
||||
private double totalPrice;
|
||||
List<Article> articles = new List<Article>();
|
||||
public void AddArticle(Article article)
|
||||
{
|
||||
articles.Add(article);
|
||||
}
|
||||
public void RemoveArticle(Article article)
|
||||
{
|
||||
articles.Remove(article);
|
||||
}
|
||||
public void PrintTotalPrice()
|
||||
{
|
||||
int cnt = 0;
|
||||
foreach (Article item in articles)
|
||||
{
|
||||
this.totalPrice += item.GetPrice();
|
||||
cnt++;
|
||||
}
|
||||
Console.WriteLine($"Stückzahl: {cnt}");
|
||||
Console.WriteLine($"Gesamtpreis: {this.totalPrice:C2}");
|
||||
}
|
||||
|
||||
public void PrintInfo()
|
||||
{
|
||||
foreach (Article item in articles)
|
||||
{
|
||||
item.PrintInfo();
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------------
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user