-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacking_list.rb
138 lines (110 loc) · 3.3 KB
/
packing_list.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# INVENTORY MANAGEMENT PROGRAM
# Focus on use of classes/objects, methods, and all of the parts and pieces availabe to you.
# Write a program that does the following:
# 1. Lists several items.
# 2. Allows a user to select an item and view the inventory count,
# change the number of the inventory, delete the item altogether, or even change the name.
# 3. Create a new item and give the item an inventory count,.
# Have this item now show up in the list of items you can select.
# 4. Loops through until the user does not want to edit the list anymore.
# -------------------------------------------------------------------------------------------
class Vacation <String
# attr_accessor :list, :name, :number
def initialize
puts "Let's pack!"
end
# Set up hash with user input
def items
@list = Hash.new
puts "Press 'Enter' after each answer and when finished type 'done'."
while @name != "done"
puts "What's the name of your item?"
@name = gets.chomp.to_s
if @name == "done"
break
end
puts "How many of that item you want to take on your trip?"
@number = gets.chomp.to_i
@list[@name] = @number
end
puts @list
end
# View how many of 1 item in list.
def select
puts "Type in the name of the item."
answer = gets.chomp.to_s
puts "#{@list[answer]} #{answer}"
change
end
# Change number of item taking.
def count
puts "What item would you like to change the number of?"
answer = gets.chomp.to_s
puts "You currently have #{@list[answer]} #{answer}."
puts "How many would you like to pack?"
reply = gets.chomp.to_i
@list[answer] = reply
puts "Now you are packing #{@list[answer]} #{answer}."
change
end
# Change name of item.
def title
puts "What item would you like to change the name of?"
answer = gets.chomp.to_s
puts "What would you like to call it?"
reply = gets.chomp.to_s
@list[reply] = @list.delete answer
change
end
# Delete item.
def erase
puts "What item would you like to delete?"
answer = gets.chomp.to_s
@list.delete(answer)
puts @list
change
end
# Create new item.
def brand_new
puts "What would you like to add?"
name = gets.chomp.to_s
puts "How many #{name} would you like to add?"
number = gets.chomp.to_i
@list[name] = number
change
end
# Choose what to do with list.
def change
puts "Would you like to make a change or view an item from your packing list? ('yes' or 'no')"
answer = gets.chomp.to_s.downcase
if answer == "yes"
puts "To view your packing list type 1."
puts "To view how many of an item your taking type 2."
puts "To change the number of an item your packing type 3."
puts "To edit the name of an item type 4."
puts "To delete an item type 5."
puts "To add a new item type 6."
reply = gets.chomp.to_i
if reply == 1
puts @list
change
elsif reply == 2
select
elsif reply == 3
count
elsif reply == 4
title
elsif reply == 5
erase
elsif reply == 6
brand_new
end
end
end
end
# Initialize Class
packing_list = Vacation.new
# Collect user's list
packing_list.items
# Put user into loop to edit list.
packing_list.change