add Programmyday form github
This commit is contained in:
32
Warenkorb/Article.cs
Normal file
32
Warenkorb/Article.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Warenkorb
|
||||
{
|
||||
abstract class Article
|
||||
{
|
||||
private int articleNumber;
|
||||
private double price;
|
||||
public Article(int articleNumber, double price)
|
||||
{
|
||||
this.articleNumber = articleNumber;
|
||||
this.price = price;
|
||||
}
|
||||
public virtual double GetPrice()
|
||||
{
|
||||
return this.price;
|
||||
}
|
||||
public virtual int GetarticleNumber()
|
||||
{
|
||||
return this.articleNumber;
|
||||
}
|
||||
public virtual void PrintInfo()
|
||||
{
|
||||
Console.WriteLine($"Artikelnummer: {GetarticleNumber()}");
|
||||
Console.WriteLine($"Nettopreis: {this.price:C2}");
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Warenkorb/Books.cs
Normal file
36
Warenkorb/Books.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Warenkorb
|
||||
{
|
||||
internal class Books : Article
|
||||
{
|
||||
private string author;
|
||||
private string title;
|
||||
private string yearOfPublishing;
|
||||
private double vat = 1.07;
|
||||
|
||||
//Books(int articleNumber, double price,)
|
||||
public Books(int articleNumber, double price, string author, string title, string yearOfPublishing) : base(articleNumber, price)
|
||||
{
|
||||
this.author = author;
|
||||
this.title = title;
|
||||
this.yearOfPublishing = yearOfPublishing;
|
||||
}
|
||||
public override double GetPrice()
|
||||
{
|
||||
return base.GetPrice()*vat;
|
||||
}
|
||||
public override void PrintInfo()
|
||||
{
|
||||
base.PrintInfo();
|
||||
Console.WriteLine($"Brutto: {GetPrice():C2}");
|
||||
Console.WriteLine($"Autor: {this.author}");
|
||||
Console.WriteLine($"Titel: {this.title}");
|
||||
Console.WriteLine($"Erscheinungsjahr: {this.yearOfPublishing}");
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Warenkorb/DvDs.cs
Normal file
34
Warenkorb/DvDs.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Warenkorb
|
||||
{
|
||||
internal class DvDs : Article
|
||||
{
|
||||
private string filmTitle;
|
||||
private int duration;
|
||||
private string countryCode;
|
||||
private const double vat = 1.19;
|
||||
public DvDs(int articleNumber, double price, string filmTitle, int duration, string countryCode) : base(articleNumber, price)
|
||||
{
|
||||
this.filmTitle = filmTitle;
|
||||
this.duration = duration;
|
||||
this.countryCode = countryCode;
|
||||
}
|
||||
public override double GetPrice()
|
||||
{
|
||||
return base.GetPrice()*vat;
|
||||
}
|
||||
public override void PrintInfo()
|
||||
{
|
||||
base.PrintInfo();
|
||||
Console.WriteLine($"Brutto: {GetPrice():C2}");
|
||||
Console.WriteLine($"Film Titel: {this.filmTitle}");
|
||||
Console.WriteLine($"Spieldauer: {this.duration} min");
|
||||
Console.WriteLine($"LänderCode: {this.countryCode}");
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Warenkorb/Program.cs
Normal file
27
Warenkorb/Program.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Warenkorb
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
//Books book1 = new Books(1234, 25.90, "Grimm", "Grimmig", "Grimme Tag");
|
||||
//DvDs dvd1 = new DvDs(1235, 30, "Grimm", 120, "de");
|
||||
//book1.PrintInfo();
|
||||
//Console.WriteLine();
|
||||
//dvd1.PrintInfo();
|
||||
//Console.WriteLine();
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
Article a1 = new Books(12345, 25.79, "J.K.Rowlling", "Harry Potsau und das Schwein des Weizen", "Pride day 1970");
|
||||
Article a2 = new DvDs(12122, 89.00, "Der lange Lurch", 5, "fr");
|
||||
Shoppingcart cart1 = new Shoppingcart();
|
||||
|
||||
cart1.AddArticle(a1);
|
||||
cart1.AddArticle(a2);
|
||||
cart1.PrintInfo();
|
||||
cart1.PrintTotalPrice();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------------
|
||||
}
|
||||
}
|
||||
10
Warenkorb/Warenkorb.csproj
Normal file
10
Warenkorb/Warenkorb.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user