add Programmyday form github
This commit is contained in:
37
WareHouseSolution/Program.cs
Normal file
37
WareHouseSolution/Program.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
namespace WareHouseSolution
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string[] name = { "OTTO", "HERTIE", "KAUFHOF", "COOP", "UDO" };
|
||||
Warenhaus[] kette = new Warenhaus[5];
|
||||
for (int i = 0; i < kette.Length; i++)
|
||||
{
|
||||
kette[i] = new Warenhaus(name[i], 10 * (i + 1), 100 * (i + 1));
|
||||
kette[i].PrintInfos();
|
||||
}
|
||||
Warenhaus.PrintInfosGesamt();
|
||||
Random rnd = new Random();
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
int warenhaus = rnd.Next(kette.Length);
|
||||
int aktion = rnd.Next(2);
|
||||
int anzahl = rnd.Next(1,6);
|
||||
if (aktion == 0)
|
||||
{
|
||||
kette[warenhaus].Einkauf(anzahl);
|
||||
}
|
||||
else
|
||||
{
|
||||
kette[warenhaus].Verkauf(anzahl);
|
||||
}
|
||||
}
|
||||
foreach (Warenhaus wh in kette)
|
||||
{
|
||||
wh.PrintInfos();
|
||||
}
|
||||
Warenhaus.PrintInfosGesamt();
|
||||
}
|
||||
}
|
||||
}
|
||||
10
WareHouseSolution/WareHouseSolution.csproj
Normal file
10
WareHouseSolution/WareHouseSolution.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>
|
||||
66
WareHouseSolution/Warenhaus.cs
Normal file
66
WareHouseSolution/Warenhaus.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WareHouseSolution
|
||||
{
|
||||
internal class Warenhaus
|
||||
{
|
||||
private string? name;
|
||||
private int warenbestand;
|
||||
private int kassenbestand;
|
||||
|
||||
private static int anzahl;
|
||||
private static int warenbestandGesamt;
|
||||
private static int kassenbestandGesamt;
|
||||
public Warenhaus(string name, int warenbestand, int kassenbestand)
|
||||
{
|
||||
this.name = name;
|
||||
this.warenbestand = warenbestand;
|
||||
this.kassenbestand = kassenbestand;
|
||||
}
|
||||
|
||||
public void PrintInfos()
|
||||
{
|
||||
Console.WriteLine($"Name: {name}");
|
||||
Console.WriteLine($"Warenbestand: {warenbestand}");
|
||||
Console.WriteLine($"Kassenbestand: {kassenbestand}");
|
||||
anzahl++;
|
||||
warenbestandGesamt += warenbestand;
|
||||
kassenbestandGesamt += kassenbestand;
|
||||
}
|
||||
public static void PrintInfosGesamt()
|
||||
{
|
||||
Console.WriteLine($"Anzahl: {anzahl}");
|
||||
Console.WriteLine($"Warenbestand: {warenbestandGesamt}");
|
||||
Console.WriteLine($"Kassenbestand: {kassenbestandGesamt}");
|
||||
}
|
||||
public void Einkauf(int anzahl)
|
||||
{
|
||||
if (kassenbestand >= 10 * anzahl)
|
||||
{
|
||||
kassenbestand -= 10 * anzahl;
|
||||
warenbestand += 1;
|
||||
warenbestand += anzahl;
|
||||
kassenbestandGesamt -= 10 * anzahl;
|
||||
warenbestandGesamt += anzahl;
|
||||
Console.WriteLine($"{name}: Es wurden {anzahl} Waren gekauft");
|
||||
}
|
||||
else { Console.WriteLine($"{name}: Für {anzahl} Waren ist nicht genug Geld vorhanden."); }
|
||||
}
|
||||
public void Verkauf(int anzahl)
|
||||
{
|
||||
if (anzahl > 0 && warenbestand >= anzahl)
|
||||
{
|
||||
kassenbestand += 20 * anzahl;
|
||||
warenbestand -= anzahl;
|
||||
kassenbestandGesamt += 20 * anzahl;
|
||||
warenbestandGesamt -= anzahl;
|
||||
Console.WriteLine($"{name}: Es wurden {anzahl} Waren verkauft.");
|
||||
}
|
||||
else { Console.WriteLine($"{name}: Es sind keine {anzahl} Waren vorhanden."); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user