Aufgaben Tag 2 abgeschlossen
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
namespace Tag_2_Aufgaben;
|
||||
|
||||
public class Artikel
|
||||
{
|
||||
private static uint nextId = 1;
|
||||
private readonly uint id;
|
||||
private readonly string bezeichnung;
|
||||
private readonly uint einkaufspreis;
|
||||
private readonly uint gewinn;
|
||||
|
||||
public Artikel(string bezeichnung, uint einkaufspreis, uint gewinn)
|
||||
{
|
||||
id = nextId++;
|
||||
this.bezeichnung = bezeichnung;
|
||||
this.einkaufspreis = einkaufspreis;
|
||||
this.gewinn = gewinn;
|
||||
}
|
||||
|
||||
public uint GetId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public string GetBezeichnung()
|
||||
{
|
||||
return bezeichnung;
|
||||
}
|
||||
|
||||
public uint GetEinkaufspreis()
|
||||
{
|
||||
return einkaufspreis;
|
||||
}
|
||||
|
||||
public uint GetGewinn()
|
||||
{
|
||||
return gewinn;
|
||||
}
|
||||
|
||||
public uint GetVerkaufspreis()
|
||||
{
|
||||
return einkaufspreis + gewinn;
|
||||
}
|
||||
}
|
||||
|
||||
public class Warenkorb
|
||||
{
|
||||
private List<WarenkorbItem> items = new List<WarenkorbItem>();
|
||||
|
||||
public void AddItem(Artikel artikel, uint anzahl)
|
||||
{
|
||||
foreach (var item in items){
|
||||
if (item.artikel == artikel) {
|
||||
item.Add(anzahl);
|
||||
return;
|
||||
}
|
||||
}
|
||||
items.Add(new WarenkorbItem(artikel, anzahl));
|
||||
}
|
||||
|
||||
public void RemoveItem(Artikel artikel, uint anzahl)
|
||||
{
|
||||
foreach (var item in items){
|
||||
if (item.artikel == artikel) {
|
||||
item.Remove(anzahl);
|
||||
if(item.GetAnzahl() == 0){
|
||||
items.Remove(item);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public uint GetGesamtpreis()
|
||||
{
|
||||
uint preis = 0;
|
||||
foreach (var item in items){
|
||||
preis += item.GetGesamtpreis();
|
||||
}
|
||||
return preis;
|
||||
}
|
||||
|
||||
private class WarenkorbItem
|
||||
{
|
||||
public readonly Artikel artikel;
|
||||
private uint anzahl;
|
||||
|
||||
public WarenkorbItem(Artikel artikel, uint anzahl)
|
||||
{
|
||||
this.artikel = artikel;
|
||||
this.anzahl = anzahl;
|
||||
}
|
||||
|
||||
public uint GetAnzahl()
|
||||
{
|
||||
return anzahl;
|
||||
}
|
||||
|
||||
public void Add(uint anzahl)
|
||||
{
|
||||
this.anzahl += anzahl;
|
||||
}
|
||||
|
||||
public void Remove(uint anzahl)
|
||||
{
|
||||
if (this.anzahl < anzahl){
|
||||
anzahl = this.anzahl;
|
||||
}
|
||||
this.anzahl -= anzahl;
|
||||
}
|
||||
|
||||
public uint GetGesamtpreis()
|
||||
{
|
||||
return anzahl * artikel.GetVerkaufspreis();
|
||||
}
|
||||
}
|
||||
}
|
||||
+64
-21
@@ -6,31 +6,74 @@ internal class Song
|
||||
private string interpret;
|
||||
private int dauerSekunden;
|
||||
|
||||
public string getTitel(){
|
||||
return titel;
|
||||
}
|
||||
|
||||
public string getInterpret(){
|
||||
return interpret;
|
||||
}
|
||||
|
||||
public int getDauerSekunden(){
|
||||
return dauerSekunden;
|
||||
}
|
||||
|
||||
public void setTitel(string titel){
|
||||
public Song(string titel, string interpret, int dauerSekunden)
|
||||
{
|
||||
this.titel = titel;
|
||||
}
|
||||
|
||||
public void setInterpret(string interpret){
|
||||
this.interpret = interpret;
|
||||
}
|
||||
|
||||
public void setDauerSekunden(int dauerSekunden){
|
||||
this.dauerSekunden = dauerSekunden;
|
||||
}
|
||||
|
||||
public void spielen() {
|
||||
Console.WriteLine("{0} von {1} ({2}:{3} Minuten)", titel, interpret, dauerSekunden/60, dauerSekunden%60);
|
||||
public string GetTitel()
|
||||
{
|
||||
return titel;
|
||||
}
|
||||
|
||||
public string GetInterpret()
|
||||
{
|
||||
return interpret;
|
||||
}
|
||||
|
||||
public int GetDauerSekunden()
|
||||
{
|
||||
return dauerSekunden;
|
||||
}
|
||||
|
||||
public void SetTitel(string titel)
|
||||
{
|
||||
this.titel = titel;
|
||||
}
|
||||
|
||||
public void SetInterpret(string interpret)
|
||||
{
|
||||
this.interpret = interpret;
|
||||
}
|
||||
|
||||
public void SetDauerSekunden(int dauerSekunden)
|
||||
{
|
||||
this.dauerSekunden = dauerSekunden;
|
||||
}
|
||||
|
||||
public void Spielen()
|
||||
{
|
||||
Console.WriteLine("{0} von {1} ({2}:{3} Minuten)", titel, interpret, dauerSekunden/60, (dauerSekunden%60).ToString("D2"));
|
||||
}
|
||||
}
|
||||
|
||||
internal class Robot
|
||||
{
|
||||
public int batterieLaufzeit;
|
||||
public string aufgabe;
|
||||
|
||||
public Robot(int batterieLaufzeit, string aufgabe)
|
||||
{
|
||||
this.batterieLaufzeit = batterieLaufzeit;
|
||||
this.aufgabe = aufgabe;
|
||||
}
|
||||
|
||||
public bool IstBatterieLaufzeitNiedrig()
|
||||
{
|
||||
return batterieLaufzeit < 2;
|
||||
}
|
||||
|
||||
public void FühreAufgabeAus()
|
||||
{
|
||||
if (IstBatterieLaufzeitNiedrig()) {
|
||||
Console.WriteLine("Ich muss aufgeladen werden");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine(aufgabe);
|
||||
batterieLaufzeit--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,40 @@
|
||||
using Tag_2_Aufgaben;
|
||||
|
||||
var song = new Song();
|
||||
var song = new Song("Hallo", "C#", 122);
|
||||
song.Spielen();
|
||||
|
||||
var robot = new Robot(5, "Ich reiche Butter");
|
||||
for (var i = 0; i < 5; i++){
|
||||
robot.FühreAufgabeAus();
|
||||
}
|
||||
|
||||
var pizza = new Artikel("Pizza", 300, 400);
|
||||
var baguette = new Artikel("Baguette", 60, 60);
|
||||
var spaghetti = new Artikel("Spaghetti", 250, 400);
|
||||
|
||||
var korb = new Warenkorb();
|
||||
|
||||
korb.AddItem(pizza, 5);
|
||||
korb.AddItem(pizza, 5);
|
||||
korb.RemoveItem(pizza, 2);
|
||||
|
||||
Console.WriteLine(korb.GetGesamtpreis());
|
||||
|
||||
|
||||
korb = new Warenkorb();
|
||||
|
||||
korb.AddItem(pizza, 5);
|
||||
korb.AddItem(pizza, 5);
|
||||
korb.RemoveItem(pizza, 12);
|
||||
|
||||
Console.WriteLine(korb.GetGesamtpreis());
|
||||
|
||||
|
||||
korb = new Warenkorb();
|
||||
|
||||
korb.AddItem(pizza, 5);
|
||||
korb.AddItem(spaghetti, 1);
|
||||
korb.AddItem(baguette, 3);
|
||||
|
||||
Console.WriteLine(korb.GetGesamtpreis());
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("Aufgaben")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+3e3cf7d27baac4eda0cf31c767ba07a79f235bec")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+abce04f922245af199e8f229995381e903c916dc")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("Aufgaben")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("Aufgaben")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -1 +1 @@
|
||||
09a60c84e110a6c48c4a16b436739b1f04033328ffe663f7c0177d9865f5dd54
|
||||
22e33e2bfdc3bca03872763fea4d703741aa305af458e26d2c54c12abfec8325
|
||||
|
||||
@@ -1 +1 @@
|
||||
75b87e383ff15e0ef98f29f2fbc381d4a396ab05af628df287cc53c53957d488
|
||||
edd0f5538d1d0d317a1df17a870a95c5b1303178b6e44ad1607644a7d90588b3
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Aufgaben/obj/Debug/net10.0/Aufgaben.GeneratedMSBuildEditorConfig.editorconfig
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Aufgaben/obj/Debug/net10.0/Aufgaben.AssemblyInfoInputs.cache
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Aufgaben/obj/Debug/net10.0/Aufgaben.AssemblyInfo.cs
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Aufgaben/obj/Debug/net10.0/Aufgaben.csproj.CoreCompileInputs.cache
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Aufgaben/bin/Debug/net10.0/Aufgaben
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Aufgaben/bin/Debug/net10.0/Aufgaben.deps.json
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Aufgaben/bin/Debug/net10.0/Aufgaben.runtimeconfig.json
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Aufgaben/bin/Debug/net10.0/Aufgaben.dll
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Aufgaben/bin/Debug/net10.0/Aufgaben.pdb
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Aufgaben/obj/Debug/net10.0/Aufgaben.GeneratedMSBuildEditorConfig.editorconfig
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Aufgaben/obj/Debug/net10.0/Aufgaben.AssemblyInfoInputs.cache
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Aufgaben/obj/Debug/net10.0/Aufgaben.AssemblyInfo.cs
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Aufgaben/obj/Debug/net10.0/Aufgaben.csproj.CoreCompileInputs.cache
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Aufgaben/obj/Debug/net10.0/Aufgaben.dll
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Aufgaben/obj/Debug/net10.0/refint/Aufgaben.dll
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Aufgaben/obj/Debug/net10.0/Aufgaben.pdb
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user