-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lynn Trickey's Stacks, Queues and Job Simulation #46
base: master
Are you sure you want to change the base?
Conversation
|
||
class JobSimulation | ||
attr_reader :workers, :waiting, :roll | ||
attr_reader :employed, :waiting, :waitlist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't change the variables that I put here. If this is the spec that's given to you then these are the names of the variables that will be expected in other places, so if you change it here, other programs expecting these names won't work properly. Also no adding variables (waitlist
) or removing variables (roll
)
@number += 1 | ||
end | ||
@employed | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine to break out this task into its own method - but if doing so, it should be a private method that is used within the class, but not available outside the class (which is what making it private does)
|
||
def give_jobs(jobs_available) | ||
@number = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine to make this variable and use it. But if doing so, it should be a local variable, not an instance variable, as it won't be (shouldn't be) used in other methods as well.
jobs_available.times do | ||
@employed.push("Worker \##{@number}") | ||
@number += 1 | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another solution that's a little easier to read is:
jobs_available.times do |i|
@employed.push("Worker \##{i+1}")
end
@waitlist.enqueue("Worker \##{@number}") | ||
@number += 1 | ||
end | ||
@waitlist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same note about style of loop and using |i|
here. Though this one is a little trickier to make sure that the numbering would start at 7, in this case, instead of 1. But it can be done with a little math.
|
||
def cycle | ||
die_roll = rand(1..6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be @roll as it's the variable that I indicated in the atrr_reader
Stacks and QueuesWhat We're Looking For
OPTIONAL JobSimulation
Overall this looks good! I just left some notes on some areas where you didn't exactly follow the skeleton that I provided and ended up altering the functionality of JobSimulation as a result. |
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation
Before the simulation starts
Employed: ["Worker #1", "Worker #2", "Worker #3", "Worker #4", "Worker #5", "Worker #6"]
Waitlist: ["Worker #7", "Worker #8", "Worker #9", "Worker #10"]
-------Cycle 1-------
Employed: ["Worker #1", "Worker #2", "Worker #3", "Worker #4", "Worker #7", "Worker #8"]
Waitlist: ["Worker #9", "Worker #10", "Worker #6", "Worker #5"]
-------Cycle 2-------
Employed: ["Worker #1", "Worker #2", "Worker #3", "Worker #9", "Worker #10", "Worker #6"]
Waitlist: ["Worker #5", "Worker #8", "Worker #7", "Worker #4"]
-------Cycle 3-------
Employed: ["Worker #1", "Worker #2", "Worker #3", "Worker #9", "Worker #10", "Worker #5"]
Waitlist: ["Worker #8", "Worker #7", "Worker #4", "Worker #6"]
-------Cycle 4-------
Employed: ["Worker #1", "Worker #2", "Worker #3", "Worker #8", "Worker #7", "Worker #4"]
Waitlist: ["Worker #6", "Worker #5", "Worker #10", "Worker #9"] |