-
Notifications
You must be signed in to change notification settings - Fork 0
/
foodie.rb
97 lines (87 loc) · 1.71 KB
/
foodie.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
class Order
attr_accessor :items, :oid, :cust_nm, :status
@@ocnt=1
def initialize
@oid=@@ocnt
@cust_nm
@status
@items=Hash.new
end
end
class OrderManager
@@menu={"PavBhaji"=>70,"MDosa"=>40,"ChholeBhature"=>80,"Pulav"=>60}
def initialize
puts "System Started..."
@orders = Array.new
end
public
def newOrder
order=Order.new
print "Customer Name: "
order.cust_nm = gets.chomp
flag = "Y"
while flag=="Y"||flag=="y"
print "Dish name: "
dnm = gets.chomp
if @@menu.has_key?(dnm)
price = @@menu[dnm]
order.items.store(dnm,price)
print "Do you want to add more item: "
flag = gets.chomp
else
print "Do you want to try another dish: "
flag = gets.chomp
end
end
order.status="Confirmed"
@orders << order
end
public
def changeStatus(id)
if @orders[id]
print "Enter new status: "
@orders[id].status = gets.chomp
end
end
public
def displayOrder(id)
if @orders[id]
total=0
puts "O_id: #{@orders[id].oid}"
puts "Customer: #{@orders[id].cust_nm}"
puts "----Ordered Item(s)----"
@orders[id].items.each do |key,val|
puts " #{key} Rs.#{val}"
total+=val
end
puts "Total Amount: #{total}"
puts "Status: #{@orders[id].status}"
end
end
end
O1=OrderManager.new
ch="Y"
while ch=="Y"||ch=="y"
puts "----Order Management System----"
puts "\t1.Take Order"
puts "\t2.Change Status"
puts "\t3.Display Order"
puts "Which Operation: "
op = gets.to_i
case op
when 1
O1.newOrder
when 2
print "Enter O_id: "
id = gets.to_i
O1.changeStatus(id)
when 3
print "Enter O_id: "
id = gets.to_i-1
O1.displayOrder(id)
else
puts "Invalid Operation"
end
puts "Do you want to Continue?..."
ch = gets.chomp
end