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

final commit. #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions Queue.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
class Queue
# First In First Out
attr_accessor :store
def initialize
@store = Array.new
end

def dequeue
grab = @store[0]
@store = @store.drop(1)
grab
end

def enqueue(element)
@store << element
end

def size
@store.length
end

def empty?
size == 0
end

def to_s
@store.to_s
end
end
23 changes: 18 additions & 5 deletions Stack.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
class Stack
# Last In First Out
attr_reader :store
def initialize
@store = Array.new
end

def pop
end


def push(element)
@store << element
end

def pop
@store.pop
end

def size
@store.length
end

def empty?
size == 0
end

def to_s
@store.to_s
end
end
53 changes: 53 additions & 0 deletions job-simulation.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,57 @@
require './Stack.rb'
require './Queue.rb'

# A company has six hiring positions with more people wanting jobs than the number of available positions. The company managers decide in order to give more people an opportunity to make money; they will allow people to work in three-month intervals. The first five people on the waiting list will be hired in the order that they are on the waiting list. The first six people will keep these positions for three months. At the end of three months, the manager will roll a dice to determine the number of people who will lose their jobs. The company will use the policy of last-hired-first-fired. For example, if the dice roll is 3, the last 3 people hired will lose their jobs to the first 3 people on the waiting list. People losing their jobs will be placed on the back of the waiting list in the order that they are fired. This process will continue for every three-month interval.

module Employment
class Employees
def self.get_employees(n)
employees = Stack.new
empl_id = 1
n.times do |employee|
employees.push("empl" + "#{empl_id}")
empl_id += 1
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use employee in place of empl_id here and then remove that counter.

employees
end
end

class Sad_Job_Cycle
def initialize(employees, job_count)
@hired = Stack.new
@waitlist = Queue.new
print "\nemployees: #{employees}\n"
employees.size.times do
employee = employees.pop
print "\nemployee: #{employee}"
@waitlist.enqueue(employee)
end
hire(job_count)
end

def fire(number)
number.times do
fired_person = @hired.pop
@waitlist.enqueue(fired_person)
end
end

def hire(number)
number.times do
hired_person = @waitlist.dequeue
@hired.push(hired_person)
end
end

def roll_die
([email protected]).to_a.sample
end

def rotate
number = roll_die
fire(number)
hire(number)
print number
end
end
end