Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Lynn Trickey's Stacks, Queues and Job Simulation #46

wants to merge 3 commits into from

Conversation

ltrickey
Copy link

@ltrickey ltrickey commented Mar 1, 2017

Stacks and Queues

Thanks for doing some brain yoga. You are now submitting this assignment!

Comprehension Questions

Question Answer
What is an ADT? ADT is a type (class?) of data types. It stands for Abstract Data Types. Each of these different types of Data also have specific rules about how you can store information and interact with or access that information.
Describe a Stack A stack is a data type with last in first out logic. You enter pieces of data into the stack and can only access or remove the lass piece entered and stored. You must remove that piece of data to access any other data in the stack which is "beneath" it.
What are the 5 methods in Stack and what does each do? push adds data. pop removes the last piece of data added. empty? checks if the stack is empty. top reads/accesses the very last piece of data entered but does not remove it. size accesses how many things are stored in the stack.
Describe a Queue A queue is a data type where data is stored and accessed with first in first out logic, meaning the only piece of data that can be accessed is the first thing entered. You must remove this first object to then access the next object entered, etc.
What are the 5 methods in Queue and what does each do? enqueue adds a piece of data to the queue, dequeue removes the first thing added (or the earliest thing added if that first piece has been removed). Empty? checks if the queue is empty. Front will access the first or earliest piece of data and read/return it but won't remove it. Size will tell you how many things are stored in the queue.
What is the difference between implementing something and using something? implementing is creating a class or method, meaning writing how the behavior will work, what elements go into it. Using is actually calling an instance of that class, or calling that method on an object.

OPTIONAL JobSimulation

Question Answer
Did you include a sample run of your code as a comment? Pasting it here:

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"] |


class JobSimulation
attr_reader :workers, :waiting, :roll
attr_reader :employed, :waiting, :waitlist

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

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

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

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

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)

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

@sudocrystal
Copy link

Stacks and Queues

What We're Looking For

Feature Feedback
Implementation of Stack looks complete yes
Implementation of Queue looks complete yes

OPTIONAL JobSimulation

Extension Feedback
Does the code solve the problem to specification? no
Is the code easy to follow? yes
Does the output look good? yes
Were provided variables and methods used appropriately and not altered in name or definition? no
Were any new variables and/or methods made private to the class? no

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants