Skip to content

Commit 6cfe62f

Browse files
committed
Merge pull request #17 from intwominds/master
good work. let me know if you have any questions
2 parents f2b57bf + 7e83ed3 commit 6cfe62f

File tree

8 files changed

+284
-0
lines changed

8 files changed

+284
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Apartment
2+
attr_accessor :price, :sqft, :num_bathrooms, :num_bathrooms, :num_bathrooms, :occupants
3+
4+
def initialize(value, sqft, num_bedrooms, num_bathrooms)
5+
@value = value
6+
@sqft = sqft
7+
@num_bedrooms = num_bedrooms
8+
@num_bathrooms = num_bathrooms
9+
@occupants = []
10+
end
11+
12+
def to_s
13+
"Valued at $#{ @value }, for #{ @sqft } square feet and has #{ @occupants.length } occupants"
14+
end
15+
16+
def occupied?
17+
@occupants.any?
18+
end
19+
end
20+
21+
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Building
2+
attr_accessor :address, :style, :has_doorman, :has_evelator, :num_floors, :apartments
3+
4+
def initialize(address, style, has_doorman, has_evelator, num_floors)
5+
@address = address
6+
@style = style
7+
@has_doorman = has_doorman
8+
@has_evelator = has_evelator
9+
@num_floors = num_floors
10+
@apartments = {}
11+
end
12+
13+
def to_s
14+
"The #{ @style } building at #{ @address } has #{ @apartments.length } apartments and #{ @num_floors } floors"
15+
end
16+
17+
end
18+
+186
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
require 'pry'
2+
require 'pry-debugger'
3+
4+
require_relative 'apartment'
5+
require_relative 'building'
6+
require_relative 'tenant'
7+
8+
$building = []
9+
$apartments = []
10+
$tenants = []
11+
12+
def greet
13+
puts "============================="
14+
puts " WELCOME "
15+
puts "============================="
16+
puts "(a)partment, (b)uilding, (t)enant database, or, (q)uit? "
17+
greet = gets.chomp
18+
end
19+
20+
def director
21+
response = greet
22+
if response == 'a'
23+
apart_menu
24+
elsif response == 'b'
25+
building_menu
26+
elsif response == 't'
27+
tenant_menu
28+
elsif response == 'q'
29+
puts "Quitting.."
30+
Kernel.exit
31+
end
32+
end
33+
34+
def apart_menu
35+
puts "============================="
36+
puts " APARTMENT MANAGER "
37+
puts "============================="
38+
puts "(a)dd, (l)ist all, list a(v)ailable"
39+
apart_response = gets.chomp
40+
case apart_response
41+
when 'a'
42+
add_apart
43+
when 'l'
44+
list_apart
45+
when 'v'
46+
list_avail
47+
end
48+
end
49+
50+
def add_apart
51+
puts "What is the value?($) "
52+
value = gets.chomp
53+
puts "How many square feet? "
54+
sqft = gets.chomp
55+
puts "How many bedrooms? "
56+
num_bedrooms = gets.chomp
57+
puts "How many bathrooms? "
58+
num_bathrooms = gets.chomp
59+
60+
apt = Apartment.new(value, sqft, num_bedrooms, num_bathrooms)
61+
$apartments << apt
62+
end
63+
64+
def list_apart
65+
$apartments.each do |a|
66+
puts a
67+
end
68+
end
69+
70+
def list_avail
71+
end
72+
73+
def building_menu
74+
puts "============================="
75+
puts " BUILDING MANAGER "
76+
puts "============================="
77+
puts "(a)dd, (l)ist all"
78+
building_response = gets.chomp
79+
case building_response
80+
when 'a'
81+
add_building
82+
when 'l'
83+
list_building
84+
end
85+
end
86+
87+
def add_building
88+
puts "What's the address? "
89+
address = gets.chomp
90+
puts "What's the style? "
91+
style = gets.chomp
92+
puts "Is there a Doorman?(true/false) "
93+
has_doorman = gets.chomp
94+
puts "Is there an Elevator?(true/false) "
95+
has_evelator = gets.chomp
96+
puts "How many floors? "
97+
num_floors = gets.chomp
98+
99+
bui = Building.new(address, style, has_doorman, has_evelator, num_floors)
100+
$buildings << bui
101+
end
102+
103+
def list_building
104+
$buildings.each do |b|
105+
puts b
106+
end
107+
end
108+
109+
def tenant_menu
110+
puts "============================="
111+
puts " TENANT MANAGER "
112+
puts "============================="
113+
puts "(a)dd, (l)ist all, (m)ove, a(d)d to apartment, (r)emove"
114+
tenant_response = gets.chomp
115+
case tenant_response
116+
when 'a'
117+
add_tenant
118+
when 'l'
119+
list_tenant
120+
when 'm'
121+
when 'd'
122+
when 'r'
123+
end
124+
end
125+
126+
def add_tenant
127+
puts "Name? "
128+
name = gets.chomp
129+
puts "Age? "
130+
age = gets.chomp
131+
puts "Gender? "
132+
gender = gets.chomp
133+
134+
ten = Tenant.new(name, age, gender)
135+
$tenants << ten
136+
end
137+
138+
def list_tenant
139+
$tenants.each_with_index do |t, i|
140+
print "#{ i + 1 }) "
141+
puts t
142+
end
143+
end
144+
145+
def move_tenant
146+
list_tenant
147+
print "Please select a tenant number: "
148+
tenant_no = gets.to_i
149+
150+
puts "Here is your tenant:"
151+
tenant = $tenants[tenant_no - 1]
152+
puts tenant
153+
154+
list_apart
155+
print "Please select an apartment number: "
156+
apartment_no = gets.to_i
157+
$apartments[apartment_no - 1].occupants << tenant
158+
end
159+
160+
161+
director
162+
163+
164+
puts "Another entry?(y/n) "
165+
re_entry = gets.chomp
166+
167+
if re_entry == 'n'
168+
puts ' '
169+
else
170+
puts "How many entries would you like to make? "
171+
ent = gets.chomp.to_i
172+
173+
ent.times do
174+
director
175+
end
176+
end
177+
178+
179+
180+
181+
182+
# Seed data
183+
184+
185+
186+
binding.pry
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Buildings
2+
3+
address - string
4+
style - string | symbol
5+
has_doorman - boolean
6+
elevator - boolean
7+
apartments - array
8+
9+
10+
Apartment
11+
12+
price - decimanl / float
13+
sqft - integer
14+
num_beds - integer
15+
num_bathrooms - int
16+
renters - array
17+
18+
19+
Tenant
20+
21+
name - string
22+
age - integer
23+
gender - symbol
24+
25+
26+
h/w for tonight = build a menu system.
27+
28+
1. add a building - done
29+
- feature to list - done
30+
31+
2. add an apartment - done
32+
- feature to list - done
33+
- feature to list all apartments - done
34+
- feature to list all available
35+
36+
3. add a tenant - done
37+
- feature to list - done
38+
- feature to move tenants
39+
- feature to add tenants into an apartment
40+
- feature to completely remove tenants
41+
42+
43+
44+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Tenant
2+
attr_accessor :name, :age, :gender
3+
4+
def initialize(name, age, gender)
5+
@name = name
6+
@age = age
7+
@gender = gender
8+
end
9+
10+
def to_s
11+
"#{ @name } is a #{ @age } year old #{ @gender }"
12+
end
13+
14+
end

0 commit comments

Comments
 (0)