From 2929f7a93d93c0084cf419dd0b0ac0ce9702f688 Mon Sep 17 00:00:00 2001 From: berkayalan Date: Tue, 16 Apr 2024 12:16:10 +0200 Subject: [PATCH 1/3] banking example created --- projects/banking/main.go | 92 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/projects/banking/main.go b/projects/banking/main.go index e69de29..0e1af53 100644 --- a/projects/banking/main.go +++ b/projects/banking/main.go @@ -0,0 +1,92 @@ +package main + +import ( + "fmt" +) + +type Account struct { + AccountOwner string + AccountName string + AccountID string + IsActive bool + Currency string + Amount float64 +} + +type Tenant struct { + TenantID string + TenantName string + IsActive bool + AccountID array +} + +type IAtm interface { + WithdrawMoney() float64 + AddMoney() float64 + ShowDetails() string +} + +func (a Account) WithdrawMoney() float64 { + + var amount float64 + + fmt.Println("Please enter how much money you want to withdraw.") + + fmt.Scanln(&amount) + + rest_amount := a.Amount - amount + + fmt.Printf("%v %v left in your account.", rest_amount, a.Currency) + + return rest_amount + +} + +func (a Account) AddMoney() float64 { + + var amount float64 + + fmt.Println("Please enter how much money you want to add.") + + fmt.Scanln(&amount) + + new_amount := a.Amount - amount + + fmt.Printf("New amount in your account is %v %v.", new_amount, a.Currency) + + return new_amount + +} + +func (a Account) ShowDetails() string { + + return "cxfsa" + +} + +func (a Tenant) ShowDetails() string { + + return "cxfsa" + +} + +func main() { + + a1 := Account{AccountOwner: "Berkay Alan", AccountName: "Saving", + AccountID: "1155", IsActive: true, Currency: "€", Amount: 5000} + a2 := Account{AccountOwner: "Berkay Alan", AccountName: "PocketMoney", + AccountID: "1156", IsActive: true, Currency: "€", Amount: 1366.44} + a3 := Account{AccountOwner: "Evgeny Keck", AccountName: "Investment", + AccountID: "6567", IsActive: true, Currency: "€", Amount: 17977} + a4 := Account{AccountOwner: "Evgeny Keck", AccountName: "Holiday", + AccountID: "6578", IsActive: false, Currency: "€", Amount: 300} + + all_accounts := [4]Account{a1, a2, a3, a4} + + t1 := Tenant{TenantID: "22975", TenantName: "Berkay Alan", IsActive: true, AccountID: [2]string{"1155", "1156"}} + t2 := Tenant{TenantID: "66734", TenantName: "Evgeny Keck", IsActive: true, AccountID: [2]string{"6567", "6578"}} + t3 := Tenant{TenantID: "43254", TenantName: "Saang Kell", IsActive: false, AccountID: [1]string{"3245"}} + + all_tenants := [3]Tenant{t1, t2, t3} + +} From 4a5e32d1fc507acebb25842d8c9b7d3c877e5305 Mon Sep 17 00:00:00 2001 From: berkayalan Date: Tue, 16 Apr 2024 17:08:01 +0200 Subject: [PATCH 2/3] new transaction added --- projects/banking/main.go | 66 +++++++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 8 deletions(-) diff --git a/projects/banking/main.go b/projects/banking/main.go index 0e1af53..13d40c1 100644 --- a/projects/banking/main.go +++ b/projects/banking/main.go @@ -6,6 +6,7 @@ import ( type Account struct { AccountOwner string + TenantID string AccountName string AccountID string IsActive bool @@ -17,7 +18,6 @@ type Tenant struct { TenantID string TenantName string IsActive bool - AccountID array } type IAtm interface { @@ -72,21 +72,71 @@ func (a Tenant) ShowDetails() string { func main() { - a1 := Account{AccountOwner: "Berkay Alan", AccountName: "Saving", + /* a1 := Account{TenantID: "22975", AccountOwner: "Berkay Alan", AccountName: "Saving", AccountID: "1155", IsActive: true, Currency: "€", Amount: 5000} - a2 := Account{AccountOwner: "Berkay Alan", AccountName: "PocketMoney", + a2 := Account{TenantID: "22975", AccountOwner: "Berkay Alan", AccountName: "PocketMoney", AccountID: "1156", IsActive: true, Currency: "€", Amount: 1366.44} - a3 := Account{AccountOwner: "Evgeny Keck", AccountName: "Investment", + a3 := Account{TenantID: "66734", AccountOwner: "Evgeny Keck", AccountName: "Investment", AccountID: "6567", IsActive: true, Currency: "€", Amount: 17977} - a4 := Account{AccountOwner: "Evgeny Keck", AccountName: "Holiday", + a4 := Account{TenantID: "66734", AccountOwner: "Evgeny Keck", AccountName: "Holiday", AccountID: "6578", IsActive: false, Currency: "€", Amount: 300} all_accounts := [4]Account{a1, a2, a3, a4} - t1 := Tenant{TenantID: "22975", TenantName: "Berkay Alan", IsActive: true, AccountID: [2]string{"1155", "1156"}} - t2 := Tenant{TenantID: "66734", TenantName: "Evgeny Keck", IsActive: true, AccountID: [2]string{"6567", "6578"}} - t3 := Tenant{TenantID: "43254", TenantName: "Saang Kell", IsActive: false, AccountID: [1]string{"3245"}} + t1 := Tenant{TenantID: "22975", TenantName: "Berkay Alan", IsActive: true} + t2 := Tenant{TenantID: "66734", TenantName: "Evgeny Keck", IsActive: true} + t3 := Tenant{TenantID: "43254", TenantName: "Saang Kell", IsActive: false} all_tenants := [3]Tenant{t1, t2, t3} + fmt.Printf("%v\n ", all_accounts) + fmt.Printf("%v\n ", all_tenants) */ + + transaction := GetTransaction() + + choose_count := 0 + + for choose_count <= 3 { + for transaction > 0 && transaction <= 5 { + if transaction == 5 { + choose_count += 1 + if choose_count < 3 { + fmt.Println("You made a wrong choose! Please try again.") + transaction = GetTransaction() + continue + } else if choose_count == 3 { + fmt.Println("You made 3 wrong choose! Your account is suspected!") + break + } + break + } else { + switch transaction { + case 1: + fmt.Println("1") + continue + case 2: + fmt.Println("2") + case 3: + fmt.Println("3") + case 4: + break + } + break + } + } + } +} + +func GetTransaction() int { + + var transaction int + + fmt.Println("Please select what you want to do.\n1 : Show my user details \n2 : Withdraw Money\n3 : Add Money\n4 : Exit") + + fmt.Scanln(&transaction) + if transaction > 0 && transaction <= 4 { + return transaction + } else { + return 5 // Error Code + } } From 828e8f60164689dbbdd614ffbc32261525585373 Mon Sep 17 00:00:00 2001 From: berkayalan Date: Thu, 18 Apr 2024 18:38:53 +0200 Subject: [PATCH 3/3] example developed --- projects/banking/main.go | 48 +++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/projects/banking/main.go b/projects/banking/main.go index 13d40c1..cd93100 100644 --- a/projects/banking/main.go +++ b/projects/banking/main.go @@ -93,37 +93,29 @@ func main() { fmt.Printf("%v\n ", all_tenants) */ transaction := GetTransaction() - - choose_count := 0 - - for choose_count <= 3 { - for transaction > 0 && transaction <= 5 { - if transaction == 5 { - choose_count += 1 - if choose_count < 3 { - fmt.Println("You made a wrong choose! Please try again.") - transaction = GetTransaction() - continue - } else if choose_count == 3 { - fmt.Println("You made 3 wrong choose! Your account is suspected!") - break - } - break - } else { - switch transaction { - case 1: - fmt.Println("1") - continue - case 2: - fmt.Println("2") - case 3: - fmt.Println("3") - case 4: - break - } + choose_count := 1 + + for choose_count < 3 { + if transaction == 5 { + choose_count += 1 + fmt.Printf("Your Selection is %v\n", transaction) + fmt.Println("Your selection is wrong. Please select again") + fmt.Println(choose_count) + transaction = GetTransaction() + continue + } else { + switch transaction { + case 1: + fmt.Println("1") + case 2: + fmt.Println("2") + case 3: + fmt.Println("3") + case 4: break } } + // break } }