forked from denalove/votersim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuman.rb
110 lines (95 loc) · 2.79 KB
/
human.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
class Human
attr_accessor :type, :name, :party
attr_writer :vote
def initialize(type, name, party)
@type = type
@name = name
@party = party
@vote = ""
@votes = 0
@candidate = false
# @votes = 0
end
#--------------------------------------------------------------------------------------------------------
#methods for instance variables
#--------------------------------------------------------------------------------------------------------
def type
@type
end
def party
@party
end
def name
@name
end
def voters_choice
@vote
end
def update_vote(new_vote)
@vote = new_vote
end
# def total_votes
# @votes
# end
#--------------------------------------------------------------------------------------------------------
#--------------------------------------------------------------------------------------------------------
#class methods
#--------------------------------------------------------------------------------------------------------
#updates human with new info
def update(name, party)
@name = name
@party = party
end
#declares human as a candidate or not
def candidate?
@candidate = true if @type == "politician"
end
#method to check get who the human will vote for, if its a politician- it will vote for itself
def will_vote?(x)
if @type == "politician"
@vote = @party
@votes = 1
else
@vote = x
end
end
def add_vote
@votes +=1
end
#--------------------------------------------------------------------------------------------------------
#***********************************************************************************************************
end
#END CLASS--------------------------------------------------------------------------------------------------
class HumanList
def initialize
@list = []
end
#--------------------------------------------------------------------------------------------------------
#methods for instance variables
#--------------------------------------------------------------------------------------------------------
def voters
@voter
end
def show_list
@list
end
#--------------------------------------------------------------------------------------------------------
#--------------------------------------------------------------------------------------------------------
#class methods
#--------------------------------------------------------------------------------------------------------
def make_list(user_list)
@list = user_list
@list.each do |x|
if x.type != "politician"
@voter << x
end
end
end
def show_votes
@list.each do |x|
p x.voters_choice
end
end
#***********************************************************************************************************
end
#END CLASS--------------------------------------------------------------------------------------------------