Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 60 additions & 52 deletions FoodOrder.rb
Original file line number Diff line number Diff line change
@@ -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 [email protected] 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
end
141 changes: 141 additions & 0 deletions account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@

class Account

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
@name = name
@acc_no = @@first_account_no
@balance = amount
@type = type
end

def calculate_amount(account, months, rate_of_interest)
amount = account.balance * rate_of_interest * months / 1200
end

def deposit(account, amount)
account.balance += amount
end

def withdraw(account, amount)
if account.balance - amount < @@min_balance
return 0
else
account.balance -= amount
return 1
end
end

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 == ACCOUNT_TYPE_SAVING
new_account = SavingAccount.new(name, amount)
elsif type == ACCOUNT_TYPE_CURRENT
new_account = CurrentAccount.new(name, amount)
else
puts "Not valid account type"
end
if type == ACCOUNT_TYPE_SAVING or type == ACCOUNT_TYPE_CURRENT
Accounts[@@first_account_no] = new_account
puts Accounts
end
end
end
end

class SavingAccount < Account
attr_accessor :ROI
@@ROI = 9.75

def initialize(name, amount)
super(name, amount, ACCOUNT_TYPE_SAVING)
puts "----Your saving account is created----"
end

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, ACCOUNT_TYPE_CURRENT)
puts "----Your current account is created----"
end

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 = Hash.new
ACCOUNT_TYPE_SAVING = "saving"
ACCOUNT_TYPE_CURRENT = "current"

while 1
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

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