From 732d29fefeabedad33b9dcc0d82ff9ab7ea91e75 Mon Sep 17 00:00:00 2001 From: janik Date: Thu, 25 Nov 2021 12:12:51 +0100 Subject: [PATCH] . --- 12fi5/AEuP/Bank/bank.ps1 | 84 ++++++++++++++++++++++++++++++++-------- 1 file changed, 68 insertions(+), 16 deletions(-) diff --git a/12fi5/AEuP/Bank/bank.ps1 b/12fi5/AEuP/Bank/bank.ps1 index b99dac4..48f1c05 100644 --- a/12fi5/AEuP/Bank/bank.ps1 +++ b/12fi5/AEuP/Bank/bank.ps1 @@ -94,11 +94,12 @@ class bank { } [void]übersicht() { + Write-Host "Übersicht" foreach ($kunde in $this.kunden) { Write-Host $kunde.name foreach ($konto in $this.konten) { if ($konto.kunde -eq $kunde) { - Write-Host $konto.guthaben + Write-Host " " $konto.guthaben } } } @@ -115,6 +116,10 @@ class cui { } [konto]select_konto([string]$use) { + if ($this.bank.konten.count -eq 0) { + Write-Host "Es sind keine Konten vorhanden!" + return $null + } Write-Host "Wähle ein Konto" $use for ($i = 0; $i -lt $this.bank.konten.count; $i += 1) { Write-Host "Konto" $i "("$this.bank.konten[$i].guthaben") von" $this.bank.konten[$i].kunde.name @@ -122,31 +127,78 @@ class cui { return $this.bank.konten[$(Read-Host "Auswahl")] } - run() { - $bname = Read-Host "Wähle einen Banknamen:" + [kunde]select_kunde([string]$use) { + if ($this.bank.kunden.count -eq 0) { + Write-Host "Es sind keine Kunden vorhanden!" + return $null + } + Write-Host "Wähle einen Kunden" $use + for ($i = 0; $i -lt $this.bank.kunden.count; $i += 1) { + Write-Host "Kunde" $i ":" $this.bank.kunden[$i].name + } + return $this.bank.kunden[$(Read-Host "Auswahl")] + } + + [int]run() { + $bname = Read-Host "Wähle einen Banknamen" $this.bank = [bank]::new($bname) - while ($this.state -ne -1) { + while ($true) { Write-Host "Wähle eine Aktion aus:" Write-Host "1: Kunde anlegen" Write-Host "2: Konto anlegen" Write-Host "3: Einzahlen" Write-Host "4: Auszahlen" Write-Host "5: Überweißen" + Write-Host "6: Übersicht" Write-Host "0: Beenden" + $cmd = Read-Host "Aktion" + switch ($cmd) { + 0 { + return 0 + } + 1 { + $this.bank.neukunde( + $(Read-Host "Vorname"), + $(Read-Host "Nachname") + ) + } + 2 { + $k = $this.select_kunde("als Kontobesitzer") + if ($null -ne $k) { + $this.bank.konto_erstellen($k) + } + } + 3 { + $k = $this.select_konto("für das Einzahlen") + if ($null -ne $k) { + $amount = Read-Host "Menge" + $this.bank.einzahlen($k, $amount) + } + } + 4 { + $k = $this.select_konto("für das Auszahlen") + if ($null -ne $k) { + $amount = Read-Host "Menge" + $this.bank.auszahlen($k, $amount) + } + } + 5 { + $von = $this.select_konto("als Quelle") + if ($null -ne $von) { + $nach = $this.select_konto("als Ziel") + $amount = Read-Host "Menge" + $this.bank.überweisen($von, $nach, $amount) + } + } + 6 { + $this.bank.übersicht() + Read-Host "Press any key" + } + } } + return -1 } } -#Tests -$bank = [bank]::new("Benannte Bank") -$kunde1 = $bank.neukunde("Kunde", "Kundengesicht") -$konto1 = $bank.konto_erstellen($kunde1) -$kunde2 = $bank.neukunde("Anderes", "Kundengesicht") -$konto2 = $bank.konto_erstellen($kunde2) - -$bank.überweisen($konto1, $konto2, 150) -$bank.übersicht() - $cui = [cui]::new() -$cui.bank = $bank -$cui.select_konto("Test") \ No newline at end of file +$cui.run() \ No newline at end of file