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.
Binary file not shown.
Binary file not shown.
@@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("Tag 2")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a1b96f6869d673e84959fa00494734298395b45d")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+abce04f922245af199e8f229995381e903c916dc")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("Tag 2")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("Tag 2")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -1 +1 @@
|
||||
116d5cd724e53d9a82cfc43aa9c77bbf0f01f4a6ad4d601983e408087cf1a186
|
||||
52f0edba10144f9537e13f5c93344c17aa2d86ae265e940bf7745455c4184cf0
|
||||
|
||||
@@ -10,7 +10,7 @@ build_property.PlatformNeutralAssembly =
|
||||
build_property.EnforceExtendedAnalyzerRules =
|
||||
build_property._SupportedPlatformList = Linux,macOS,Windows
|
||||
build_property.RootNamespace = Tag_2
|
||||
build_property.ProjectDir = /home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/
|
||||
build_property.ProjectDir = /home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/
|
||||
build_property.EnableComHosting =
|
||||
build_property.EnableGeneratedComInterfaceComImportInterop =
|
||||
build_property.EffectiveAnalysisLevelStyle = 10.0
|
||||
|
||||
Binary file not shown.
@@ -12,3 +12,17 @@
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/obj/Debug/net10.0/Tag 2.pdb
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/obj/Debug/net10.0/Tag 2.genruntimeconfig.cache
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/obj/Debug/net10.0/ref/Tag 2.dll
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/bin/Debug/net10.0/Tag 2
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/bin/Debug/net10.0/Tag 2.deps.json
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/bin/Debug/net10.0/Tag 2.runtimeconfig.json
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/bin/Debug/net10.0/Tag 2.dll
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/bin/Debug/net10.0/Tag 2.pdb
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/obj/Debug/net10.0/Tag 2.GeneratedMSBuildEditorConfig.editorconfig
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/obj/Debug/net10.0/Tag 2.AssemblyInfoInputs.cache
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/obj/Debug/net10.0/Tag 2.AssemblyInfo.cs
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/obj/Debug/net10.0/Tag 2.csproj.CoreCompileInputs.cache
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/obj/Debug/net10.0/Tag 2.dll
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/obj/Debug/net10.0/refint/Tag 2.dll
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/obj/Debug/net10.0/Tag 2.pdb
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/obj/Debug/net10.0/Tag 2.genruntimeconfig.cache
|
||||
/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/obj/Debug/net10.0/ref/Tag 2.dll
|
||||
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
b2c0c7e2ca0342c0451e8e9ddd520412ad38b339c12c1b44a881180440d1f5c7
|
||||
7afd1c2db4566446b92910542786ee2500f5288eec68d7a05d226b15ae00effc
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,17 +1,17 @@
|
||||
{
|
||||
"format": 1,
|
||||
"restore": {
|
||||
"/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Tag 2.csproj": {}
|
||||
"/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/Tag 2.csproj": {}
|
||||
},
|
||||
"projects": {
|
||||
"/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Tag 2.csproj": {
|
||||
"/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/Tag 2.csproj": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Tag 2.csproj",
|
||||
"projectUniqueName": "/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/Tag 2.csproj",
|
||||
"projectName": "Tag 2",
|
||||
"projectPath": "/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Tag 2.csproj",
|
||||
"projectPath": "/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/Tag 2.csproj",
|
||||
"packagesPath": "/home/wbs/.nuget/packages/",
|
||||
"outputPath": "/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/obj/",
|
||||
"outputPath": "/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/obj/",
|
||||
"projectStyle": "PackageReference",
|
||||
"configFilePaths": [
|
||||
"/home/wbs/.nuget/NuGet/NuGet.Config"
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
"project": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Tag 2.csproj",
|
||||
"projectUniqueName": "/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/Tag 2.csproj",
|
||||
"projectName": "Tag 2",
|
||||
"projectPath": "/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Tag 2.csproj",
|
||||
"projectPath": "/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/Tag 2.csproj",
|
||||
"packagesPath": "/home/wbs/.nuget/packages/",
|
||||
"outputPath": "/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/obj/",
|
||||
"outputPath": "/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/obj/",
|
||||
"projectStyle": "PackageReference",
|
||||
"configFilePaths": [
|
||||
"/home/wbs/.nuget/NuGet/NuGet.Config"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"version": 2,
|
||||
"dgSpecHash": "osM1fto+lxk=",
|
||||
"dgSpecHash": "gybfutLePag=",
|
||||
"success": true,
|
||||
"projectFilePath": "/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Tag 2.csproj",
|
||||
"projectFilePath": "/home/wbs/Dokumente/Programmierung/wbs-csharp/Tag 2/Unterricht/Tag 2.csproj",
|
||||
"expectedPackageFiles": [],
|
||||
"logs": []
|
||||
}
|
||||
Reference in New Issue
Block a user