package objects import ( "bufio" "fmt" "os" "strconv" "strings" ) type BankAccountController struct { model BankAccountModel view BankAccountView scanner *bufio.Scanner } func NewBankAccountController(model BankAccountModel, view BankAccountView) BankAccountController { return BankAccountController{ scanner: bufio.NewScanner(os.Stdin), model: model, view: view, } } func (bc *BankAccountController) Loop() { for { // Update View if err := bc.view.Update(); err != nil { fmt.Println("Error updating view:", err) return } // Eingabeaufforderung fmt.Print("Enter command: ") // Warte auf Benutzereingabe if !bc.scanner.Scan() { fmt.Println("Error reading input or EOF reached") break } scannedString := strings.TrimSpace(bc.scanner.Text()) if len(scannedString) == 0 { continue // Ignoriere leere Eingaben } fmt.Printf("First char: %c\n", scannedString[0]) // Befehl ausführen switch scannedString[0] { case '+': amount, err := strconv.ParseFloat(scannedString[1:], 64) if err != nil { panic(fmt.Sprintf("Failed to parse float: %v\n", err)) } bc.model.Deposit(amount) case '-': amount, err := strconv.ParseFloat(scannedString[1:], 64) if err != nil { panic(fmt.Sprintf("Failed to parse float: %v\n", err)) } bc.model.Withdraw(amount) default: fmt.Println("No command recognized") } } }