From 1f8b401d4d59c1bdf795ea31f2bd96290dd11e93 Mon Sep 17 00:00:00 2001 From: sayalisheth Date: Sun, 22 Dec 2019 23:31:25 +0530 Subject: [PATCH 1/3] updated bank system --- account.rb | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 account.rb diff --git a/account.rb b/account.rb new file mode 100644 index 0000000..7eea775 --- /dev/null +++ b/account.rb @@ -0,0 +1,135 @@ +class Account + + attr_reader :acc_no, :name, :balance, :type + @@first_account_no = 100 + @@min_balance = 1000 + def initialize(name, amount, type) + @@first_account_no += 1 + @name = name + @acc_no = @@first_account_no + @balance = amount + @type = type + end + + def self.deposit(account_no, amount) + account_no[1] += amount + puts "Amount is deposited" + end + + def self.withdraw(account_no, amount) + if account_no[1] - amount < @@min_balance + puts "You can not withdraw" + else + account_no[1] -= amount + puts "Amount is withdrawl" + end + end + + def self.get_balance(account_no) + puts "\nCustomer name: #{account_no[0]}\nType of account : #{account_no[2]}\nYour current balance is #{account_no[1]}\n\n" + end + + def self.calculate_amount(account_no, months) + if account_no[2] == "saving" + SavingAccount.calculate_amount(account_no, months) + else + CurrentAccount.calculate_amount(account_no, months) + end + end + + def self.create_account(name, type, amount) + account_info = [] + if amount < @@min_balance + puts "Please enter amount greater than min_balance" + else + if type == "saving" + new_account = SavingAccount.new(name, amount) + + elsif type == "current" + new_account = CurrentAccount.new(name, amount) + else + puts "Not valid account type" + end + if type == "saving" or type == "current" + account_info << new_account.name + account_info << new_account.balance + account_info << new_account.type + #puts account_info + Accounts_all[new_account.acc_no] = account_info + end + end + +end + + +end + +class SavingAccount < Account + attr_accessor :ROI + @@ROI = 9.75 + def initialize(name, amount) + super(name, amount, "saving") + puts "----Your saving account is created----" + end + + def self.calculate_amount(account_no, months) + amt = account_no[1] * @@ROI * months / 100 + puts "You will get interest of Rs. #{amt} on balance of Rs. #{account_no[1]} for period of #{months} months with ROI #{@@ROI}" + end +end + +class CurrentAccount < Account + attr_accessor :ROI + @@ROI = 7.25 + def initialize(name, amount) + super(name, amount, "current") + puts "----Your current account is created----" + end + + def self.calculate_amount(account_no, months) + amt = account_no[1] * @@ROI * months / 1200 + puts "You will get interest of Rs. #{amt} on balance of Rs. #{@balance} for period of #{months} months with ROI #{@@ROI}" + end +end + +Accounts_all = {} +while 1 + puts "Enter your choice\n1.Create account\n2.Withdraw\n3.Deposit\n4.Check balance\n5.check ROI\n6.Exit" + choice = gets.chomp.to_i + if choice != 1 and choice <= 5 + puts "Enter account no" + acc_no = gets.chomp.to_i + end + case choice + when 1 + puts "Enter name of customer" + name = gets.chomp + puts "Enter account type(saving or current)" + type = gets.chomp.downcase + puts "Enter amount you want to depoist in your account first" + amount = gets.chomp.to_f + Account.create_account(name, type, amount) + puts Accounts_all + when 2 + puts "Enter amount you want to withdraw" + amount = gets.chomp.to_f + Account.withdraw(Accounts_all[acc_no], amount) + when 3 + puts "Enter amount you want to deposite" + amount = gets.chomp.to_f + Account.deposit(Accounts_all[acc_no], amount) + when 4 + Account.get_balance(Accounts_all[acc_no]) + when 5 + puts "Enter no of month " + months = gets.chomp.to_i + Account.calculate_amount(Accounts_all[acc_no], months) + when 6 + exit + end +end + + + + + From fe179c32f51a359c09e0b34e90d6a260f83cd66f Mon Sep 17 00:00:00 2001 From: sayalisheth Date: Tue, 24 Dec 2019 17:05:10 +0530 Subject: [PATCH 2/3] updated bank account system --- account.rb | 164 +++++++++++++++++++++++++++-------------------------- 1 file changed, 85 insertions(+), 79 deletions(-) diff --git a/account.rb b/account.rb index 7eea775..4094aff 100644 --- a/account.rb +++ b/account.rb @@ -1,135 +1,141 @@ + class Account - - attr_reader :acc_no, :name, :balance, :type - @@first_account_no = 100 + + attr_accessor :first_account_no, :min_balance, :acc_no, :name, :balance, :type + + @@first_account_no = 99 @@min_balance = 1000 + def initialize(name, amount, type) - @@first_account_no += 1 + @@first_account_no += 1 @name = name @acc_no = @@first_account_no @balance = amount @type = type end - def self.deposit(account_no, amount) - account_no[1] += amount - puts "Amount is deposited" - end - - def self.withdraw(account_no, amount) - if account_no[1] - amount < @@min_balance - puts "You can not withdraw" - else - account_no[1] -= amount - puts "Amount is withdrawl" - end + def calculate_amount(account, months, rate_of_interest) + amount = account.balance * rate_of_interest * months / 1200 end - def self.get_balance(account_no) - puts "\nCustomer name: #{account_no[0]}\nType of account : #{account_no[2]}\nYour current balance is #{account_no[1]}\n\n" + def deposit(account, amount) + account.balance += amount end - def self.calculate_amount(account_no, months) - if account_no[2] == "saving" - SavingAccount.calculate_amount(account_no, months) + def withdraw(account, amount) + if account.balance - amount < @@min_balance + return 0 else - CurrentAccount.calculate_amount(account_no, months) + account.balance -= amount + return 1 end end - def self.create_account(name, type, amount) - account_info = [] + def get_balance(account) + puts "\nCustomer name: #{account.name}\nAccount no : #{account.acc_no}\nType of account : #{account.type}\nYour current balance is #{account.balance}\n\n" + end + + def create_account(name, type, amount) if amount < @@min_balance puts "Please enter amount greater than min_balance" else - if type == "saving" + if type == ACCOUNT_TYPE_SAVING new_account = SavingAccount.new(name, amount) - - elsif type == "current" + elsif type == ACCOUNT_TYPE_CURRENT new_account = CurrentAccount.new(name, amount) else puts "Not valid account type" end - if type == "saving" or type == "current" - account_info << new_account.name - account_info << new_account.balance - account_info << new_account.type - #puts account_info - Accounts_all[new_account.acc_no] = account_info + if type == ACCOUNT_TYPE_SAVING or type == ACCOUNT_TYPE_CURRENT + Accounts[@@first_account_no] = new_account + puts Accounts end end - -end - - + end end class SavingAccount < Account attr_accessor :ROI @@ROI = 9.75 + def initialize(name, amount) - super(name, amount, "saving") + super(name, amount, ACCOUNT_TYPE_SAVING) puts "----Your saving account is created----" end - def self.calculate_amount(account_no, months) - amt = account_no[1] * @@ROI * months / 100 - puts "You will get interest of Rs. #{amt} on balance of Rs. #{account_no[1]} for period of #{months} months with ROI #{@@ROI}" + def calculate_amount(account, months) + #amount = super.calculate_amount(account, months, @@ROI) + amount = account.balance * @@ROI * months / 1200 + puts "You will get interest of Rs. #{amount} on balance of Rs. #{account.balance} for period of #{months} months with ROI #{@@ROI}" end end class CurrentAccount < Account attr_accessor :ROI @@ROI = 7.25 + def initialize(name, amount) - super(name, amount, "current") + super(name, amount, ACCOUNT_TYPE_CURRENT) puts "----Your current account is created----" end - def self.calculate_amount(account_no, months) - amt = account_no[1] * @@ROI * months / 1200 - puts "You will get interest of Rs. #{amt} on balance of Rs. #{@balance} for period of #{months} months with ROI #{@@ROI}" + def calculate_amount(account, months) + #amount = super.calculate_amount(account, months, @@ROI) + amount = account.balance * @@ROI * months / 1200 + puts "You will get interest of Rs. #{amount} on balance of Rs. #{account.balance} for period of #{months} months with ROI #{@@ROI}" end end -Accounts_all = {} +Accounts = Hash.new +ACCOUNT_TYPE_SAVING = "saving" +ACCOUNT_TYPE_CURRENT = "current" + while 1 - puts "Enter your choice\n1.Create account\n2.Withdraw\n3.Deposit\n4.Check balance\n5.check ROI\n6.Exit" + puts "______________________\nEnter your choice\n1.Create account\n2.Withdraw\n3.Deposit\n4.Check balance\n5.check ROI\n6.Exit" choice = gets.chomp.to_i if choice != 1 and choice <= 5 puts "Enter account no" acc_no = gets.chomp.to_i + if !Accounts.has_key? acc_no + puts "Account number does not exist" + flag = 0 + else + flag = 1 + end end - case choice - when 1 - puts "Enter name of customer" - name = gets.chomp - puts "Enter account type(saving or current)" - type = gets.chomp.downcase - puts "Enter amount you want to depoist in your account first" - amount = gets.chomp.to_f - Account.create_account(name, type, amount) - puts Accounts_all - when 2 - puts "Enter amount you want to withdraw" - amount = gets.chomp.to_f - Account.withdraw(Accounts_all[acc_no], amount) - when 3 - puts "Enter amount you want to deposite" - amount = gets.chomp.to_f - Account.deposit(Accounts_all[acc_no], amount) - when 4 - Account.get_balance(Accounts_all[acc_no]) - when 5 - puts "Enter no of month " - months = gets.chomp.to_i - Account.calculate_amount(Accounts_all[acc_no], months) - when 6 - exit - end -end - - - - + if flag == 1 or choice == 6 or choice == 1 + case choice + when 1 + puts "Enter name of customer" + name = gets.chomp + puts "Enter account type(saving or current)" + type = gets.chomp.downcase + puts "Enter amount you want to depoist in your account first" + amount = gets.chomp.to_f + Account.new("first",0,ACCOUNT_TYPE_SAVING).create_account(name, type, amount) + when 2 + puts "Enter amount you want to withdraw" + amount = gets.chomp.to_f + status=Accounts[acc_no].withdraw(Accounts[acc_no], amount) + if status == 1 + puts "Amount is withdrawl" + else + puts "You can not withdraw" + end + when 3 + puts "Enter amount you want to deposit" + amount = gets.chomp.to_f + Accounts[acc_no].deposit(Accounts[acc_no], amount) + puts "Amount is deposited" + when 4 + Accounts[acc_no].get_balance(Accounts[acc_no]) + when 5 + puts "Enter no of month " + months = gets.chomp.to_i + Accounts[acc_no].calculate_amount(Accounts[acc_no], months) + when 6 + exit + end + end +end \ No newline at end of file From 8b2c8e5aef1544c61d7c680111c272d2aab3ecf3 Mon Sep 17 00:00:00 2001 From: sayalisheth Date: Wed, 25 Dec 2019 11:21:13 +0530 Subject: [PATCH 3/3] updated foodorder system --- FoodOrder.rb | 112 +++++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 52 deletions(-) diff --git a/FoodOrder.rb b/FoodOrder.rb index 47cd61f..421faf5 100644 --- a/FoodOrder.rb +++ b/FoodOrder.rb @@ -1,67 +1,75 @@ class FoodOrder - @@Menu = ["ROTI", "RICE", "PANJABI THALI", "GUJARATHI THALI", "DOSA", "PIZZA", "PASTA"] - - def initialize(order, name) - @name=name - @order = order - confirm + @@Menu = {"ROTI"=>25, "RICE"=>100, "PANJABI THALI"=>150, "GUJARATHI THALI"=>160, "DOSA"=>100, "PIZZA"=>250, "PASTA"=>200} + @@food_orders = {} + def initialize(name, orders) + @@food_orders[name]=orders + confirm_food_oder + end + + def self.accept_food_oder + puts "Enter customer name" + name = gets.chomp + order_list = {} + bill = 0 + while 1 + FoodOrder.show_menu + puts "\nPress any key to continue\nPress n to stop\n\n" + key = gets.chomp + if key != 'n' + puts "Enter your order" + order = gets.chomp.upcase + if @@Menu.has_key?order + puts order + order_list[order] = @@Menu[order] + puts order_list + else + puts "Item is not avaliable" + end + else + order_list.each do |order| + bill += order[1] + end + if bill == 0 + puts "You do not order anything" + break + else + puts "Your order is:" + puts order_list + puts "---Your order is accepted----\n You have to pay Rs #{bill}" + customer = FoodOrder.new(name, order_list) + break + end + end + end + end def self.show_menu puts "-----Menu-----" - for i in 0..@@Menu.length do - puts @@Menu[i] - end + puts @@Menu end - def confirm - flag = 1 - for i in 0..@order.length-1 do - - if (!@@Menu.include? @order[i]) - puts "item is not avaliable now" - flag = 0 - break; - end - end - if flag == 1 - sleep(3) - puts "----Your order is confirmed----" - deliver - else - sleep(3) - puts "----Your order is not confirmed----" - end + def confirm_food_oder + sleep(3) + puts "----Your order is not confirmed----" + deliver_food_oder end - def deliver + def deliver_food_oder sleep(5) puts "----Your order is deliver----" + puts "\n#{@@food_orders}\n" end - end - -for i in 0..1 do - puts "Enter customer name" - name = gets.chomp - order_list = [] - while(1) - FoodOrder.show_menu - puts "Enter your order" - order = gets.chomp.upcase - order_list.push(order) - - puts "\nPress any key to continue\nPress n to stop\n\n" - key = gets.chomp - if key == "n" - puts "Your order is:" - for i in 0..order_list.length do - puts order_list[i] - end - puts "---Your order is accepted----" - break; - end +while 1 + puts "-------------------------\nYou want to order food?\nIf YES press y or if NO press n" + choice = gets.chomp.upcase + if choice == "Y" + FoodOrder.accept_food_oder + elsif choice == "N" + exit + else + puts "Invalid choice" end - customer = FoodOrder.new(order_list,name) -end \ No newline at end of file +end \ No newline at end of file