From 8ec390e5d41e91f8f20298dc9ee5ac4cfb9851bb Mon Sep 17 00:00:00 2001 From: Mary Morrison Date: Thu, 25 Aug 2016 10:35:19 -0700 Subject: [PATCH 1/3] completed Implementation of Stack --- Stack.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Stack.rb b/Stack.rb index 25da8b60..047d0929 100644 --- a/Stack.rb +++ b/Stack.rb @@ -2,19 +2,27 @@ class Stack def initialize @store = Array.new end - + def push(element) + @store.push(element) + # @store << element end - + def pop + return @store.pop end def top + return @store.last end - + def size + return @store.length end def empty? + return size == 0 + # return @store.empty? + # return @store.length == 0 end end From ae6f4c7ea6d9a5751c9aac8135237c89013e71aa Mon Sep 17 00:00:00 2001 From: Mary Morrison Date: Thu, 25 Aug 2016 10:43:34 -0700 Subject: [PATCH 2/3] completed Implementation of Queue --- Queue.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Queue.rb b/Queue.rb index 57ef609b..4a86bc1c 100644 --- a/Queue.rb +++ b/Queue.rb @@ -1,19 +1,28 @@ class Queue def initialize + @store = Array.new end - + def enqueue(element) + @store.push(element) + # option 2: @store.unshift(element) end - + def dequeue + return @store.shift + # option 2: return @store.pop end def front + return @store.first + # option 2: @store.last end - + def size + return @store.length end def empty? + return size == 0 end end From 46a67f73e66ec4bfc5bef164d05e8a00fdf0101e Mon Sep 17 00:00:00 2001 From: Mary Morrison Date: Tue, 30 Aug 2016 19:23:55 -0700 Subject: [PATCH 3/3] Mary Morrison C6 Brackets Job Simulation Final --- job-simulation.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/job-simulation.rb b/job-simulation.rb index 2c9c46d5..0b369882 100644 --- a/job-simulation.rb +++ b/job-simulation.rb @@ -13,3 +13,45 @@ require './Stack.rb' require './Queue.rb' + +class TerribleCompany + attr_reader :waiting_list, :current_employees + + def initialize(employees, applicants) + number_of_employees = 6 + number_of_applicants = 6 + + if number_of_employees > number_of_applicants + raise ArgumentError + end + + @applicants = Queue.new + number_of_applicants.times do |n| + @applicants.enqueue(i+1) + end + + @employees = Stack.new + number_of_employees.times do + @employees.push(@applicants.dequeue) + end + + end + + def employment_cycle + + (rand(6) + 1).times do + fire = @employees.pop + puts "The following employees have been cut from the team: #{ fire }." + @applicants.enqueue(fire) + end + + (rand(6) + 1).times do + hire = @applicants.dequeue + puts "The following applicants have been selected for employment: #{ hire }. + All current employees have job security...for the next 3 months" + @employees.push(hire) + end + + end + +end