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 diff --git a/account.rb b/account.rb new file mode 100644 index 0000000..4094aff --- /dev/null +++ b/account.rb @@ -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 \ No newline at end of file diff --git a/country.rb b/country.rb new file mode 100644 index 0000000..1dc3471 --- /dev/null +++ b/country.rb @@ -0,0 +1,157 @@ +module War + + def win_war? country + return true if (country.army.to_i > 100) + return false + end + +end + +module Loan + + def loan_from_IMF? country + return true if country.state == "DEVELOPING" and country.gdp > 5.0 + return false + end + + def loan_from_WorldBank? country + return true if country.gdp > 8.0 and country.state == "DEVELOPED" + return false + end + +end + +module UN_seat + + def seat? country + return true if country.gdp > 6.0 and country.army > 100 and country.state == "DEVELOPED" and country.population > 100 + return false + end + +end + +class Country + + include War + include Loan + include UN_seat + + attr_reader :name, :population, :gdp, :states, :army, :state + + @@countries = {} + + def initialize(name, population, gdp, states, army, state) + @name = name + @population = population + @gdp = gdp + @states = states + @army = army + @state = state + end + + def self.add_country(name, population, gdp, states, army, state) + new_country = Country.new(name, population, gdp, states, army, state) + @@countries[name] = new_country + #puts @@countries + end + + def display country + puts country.name + puts "\nName : #{country.name} \nPopulation : #{country.population} \nGDP : #{country.gdp}% \nNo of states : #{country.states} \nArmy strength: #{country.army}\nState : #{country.state}" + end + + + while 1 + puts "------------------------------------\nEnter your choice\n1.Get loan from IMF\n2.Get loan from World Bank\n3.Have seat in the UN Security council.\n4.Win war\n5.Display country details\n6.Add new country\n7.Exit" + choice = gets.chomp.to_i + + if choice < 6 + present_country_flag = 0 + puts "Enter country name" + country_name = gets.chomp.upcase + if @@countries.has_key?(country_name) + present_country_flag = 1 + else + puts "Country not present" + end + end + + case choice + + when 1 + if present_country_flag == 1 + if @@countries[country_name].loan_from_IMF? @@countries[country_name] + puts "#{country_name} can get loan from IMF" + else + puts "#{country_name} cannot get loan from IMF" + end + end + + when 2 + if present_country_flag == 1 + if @@countries[country_name].loan_from_WorldBank? @@countries[country_name] + puts "#{country_name} can get loan from World Bank" + else + puts "#{country_name} cannot get loan from World Bank" + end + end + + when 3 + if present_country_flag == 1 + if @@countries[country_name].seat? @@countries[country_name] + puts "#{country_name} can get a seat in UN Security council" + else + puts "#{country_name} cannot get a seat in UN Security council" + end + end + + when 4 + if present_country_flag == 1 + if @@countries[country_name].win_war? @@countries[country_name] + puts "#{country_name} can win war" + else + puts "#{country_name} cannot win war" + end + end + + when 5 + if present_country_flag == 1 + @@countries[country_name].display @@countries[country_name] + end + + when 6 + puts "Enter name of country" + name = gets.chomp.upcase + puts "Enter population" + population = gets.chomp.to_i + puts "Enter name GDP" + gdp = gets.chomp.to_f + puts "Enter no of states in country" + states = gets.chomp.to_i + puts "Enter army strength" + army = gets.chomp.to_i + flag = 0 + while 1 + puts "Enter state of country\n1.developed\n2. developing\n" + state_choice = gets.chomp.to_i + if state_choice == 1 + state = "DEVELOPED" + flag = 1 + break + elsif state_choice == 2 + state = "DEVELOPING" + flag = 1 + break + else + puts "Invalid choice" + end + end + if flag == 1 + Country.add_country(name, population, gdp, states, army, state) + end + # country_info = {"name" => name, "population" => population, "GDP" => gdp, "states" => states, "army_strenght" => army, "state" => state} + when 7 + exit + end + end +end diff --git a/hangman.rb b/hangman.rb index b11ce91..fc83314 100644 --- a/hangman.rb +++ b/hangman.rb @@ -2,7 +2,6 @@ stages = 0 words=["JOSH", "SOFTWARE", "PIZZA", "PASTA", "LAPTOP", "MOBILE", "SCHOOL", "BOTTEL", "BUS", "CAT", "QUESTION", "PROGRAMMER", "KING"] - def find_index(word, character) index = 0 all_index = [] @@ -46,7 +45,7 @@ def check_word(curr_word, chances) if curr_word.include? letter index_all = find_index(curr_word, letter) - index_all.each do|a| + index_all.each do |a| new_word[a] = letter end @@ -65,16 +64,14 @@ def check_word(curr_word, chances) print_new_word(new_word) puts "\n\n****Your Guess is Correct!!!****\n\n" end - end + end chances end while(stages < 5) stages += 1 puts "stage : #{stages}" - curr_word = words[rand(words.length)] - chances = check_word(curr_word, chances) end