我創建了一些基於一些在線教程的會計程序,但該程序似乎不起作用。我對Ruby相當陌生,但我會採取任何幫助和建議,我可以得到!在此先感謝所有!Ruby - 會計計劃問題
class Account
attr_reader :name, :check_account, :save_account
def initialize(name, check_account, save_account)
@name = name
@check_account = check_account
@save_account = save_account
end
def display_balance(pin_number)
puts "Enter pin please\n"
input = gets.chomp
if input == pin
main_menu
else
pin_error
end
end
def main_menu
puts "Welcome back #{name}!\n
What would you like to do?\n
Display balance (1)\n
Make a withdraw (2)\n
Make a deposit (3)\n
Quit (4)\n"
input = gets.chomp
case option
when 1
balance
when 2
withdraw
when 3
deposit
else
exit
end
end
def balance
puts "Which account do you wish to access? Checking or Savings?\n"
input = gets.chomp
if input =~ /checking/i
puts "Checking Balance: $#{check_account}."
else if input =~ /savings/i
puts "Savings Balance: $#{save_account}."
else
main_menu
end
end
end
def withdraw(pin_number, amount)
puts "Enter your PIN please\n"
input - gets.chomp
case withdraw
when check_account
@check_account -= amount
puts "You withdrew $#{amount} and now have $#{check_account} in your Checking."
when save_account
@save_account -= amount
puts "You withdrew $#{amount} and now have $#{save_account} in your Savings."
else
pin_error
end
end
def deposit
puts "What account do you want to deposit into? Checking or Savings?"
input = gets.chomp
if input =~ /checking/i
@check_account += amount
puts "You deposited $#{amount} adding up to a total of $#{check_account} in your Checking."
else if input =~ /savings/i
@save_account += amount
puts "You deposited $#{amount} adding up to a total of $#{save_account} in your Savings."
else
main_menu
end
end
end
private
def pin
@pin =1234
end
def pin_error
"Access denied: incorrect PIN."
end
def amount_error
"Access denied: incorrect amount."
end
end
my_account = Account.new("Andrew", 100_000, 250_000)
my_account.display
你似乎在你的問題中缺少一個問題。 – Amadan