Please make the necessary changes within the class structures, as right now they
ID: 3776567 • Letter: P
Question
Please make the necessary changes within the class structures, as right now they both just state :I have to stay home!. Simply writing a series of puts commands will be incorrect.
Here's the current code I have:
class Rookie
@@bling=0
def initialize(id, name)
@id=id
@name=name
@food=5
@bling=0
end
def weekend
if @@bling<5
puts "I have to stay home!"
else
puts "Let's Party!"
end
end
end
class Level2
@@bling=10
def initialize(id, name)
@id=id
@name=name
@food=5
@bling=10
end
end
player1=Rookie.new("1", "Mary")
player2=Rookie.new("2", "Paul")
print "Mary says: "
player1.weekend
print "Paul says: "
player2.weekend
Explanation / Answer
class Rookie
@@bling=0
def initialize(id, name)
@id=id
@name=name
@food=5
@bling=0
end
def weekend
if @@bling<5
puts "I have to stay home!"
else
puts "Let's Party!"
end
end
end
class Level2
@@bling=10
def initialize(id, name)
@id=id
@name=name
@food=5
@bling=10
end
def weekend
if @@bling<5
puts "I have to stay home!"
else
puts "Let's Party!"
end
end
end
player1=Level2.new("1", "Mary")
player2=Rookie.new("2", "Paul")
print "Mary says: "
player1.weekend
print "Paul says: "
player2.weekend
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.