diff --git a/lib/park.rb b/lib/park.rb index e69de29..950ba9d 100644 --- a/lib/park.rb +++ b/lib/park.rb @@ -0,0 +1,44 @@ + + +class Park + attr_reader :name, + :price, + :vehicles, + :passengers, + :revenue, + :patron_name + + + def initialize(name, price) + @name = name + @price = price + @vehicles = [] + @passengers = [] + @patron_name = [] + @revenue = 0 + end + + def add_vehicle(vehicle) + @vehicles << vehicle + vehicle.passengers.each { |passenger| @passengers << passenger } + end + + def revenue + @revenue = @passengers.count * @price + end + + def patron_name + @patron_name = @passengers.map{|x| x.name} + end + + def minors + minors = @passengers.select {|age| !age.adult?} + return minors + end + + def adults + adults = @passengers.select {|age| age.adult?} + return adults + end + +end \ No newline at end of file diff --git a/lib/passenger.rb b/lib/passenger.rb index e69de29..def003a 100644 --- a/lib/passenger.rb +++ b/lib/passenger.rb @@ -0,0 +1,25 @@ + + +class Passenger + attr_reader :name, + :age, + :driver + + def initialize(passenger_info) + @name = passenger_info['name'] + @age = passenger_info['age'] + @driver = false + end + + def adult? + @age >= 18 ? true : false + end + + def driver? + return @driver + end + + def drive + @age >= 16 ? @driver = true : @driver = false + end +end \ No newline at end of file diff --git a/lib/vehicle.rb b/lib/vehicle.rb index e69de29..cda1e1b 100644 --- a/lib/vehicle.rb +++ b/lib/vehicle.rb @@ -0,0 +1,34 @@ + + +class Vehicle + attr_reader :year, + :make, + :model, + :speeding, + :passengers + + def initialize(year, make, model) + @year = year + @make = make + @model = model + @speeding = false + @passengers = [] + end + + def speeding? + @speeding + end + + def speed + @speeding = true + end + + def add_passenger(passenger) + @passengers << passenger + end + + def num_adults + adults = @passengers.find_all {|x| x.adult?} + return adults.count + end +end \ No newline at end of file diff --git a/spec/park_spec.rb b/spec/park_spec.rb new file mode 100644 index 0000000..d4b66c8 --- /dev/null +++ b/spec/park_spec.rb @@ -0,0 +1,124 @@ +require './spec/spec_helper.rb' + +# attr_reader and initialize park name and ticket price +# add a vehicle to ann array for the instance of that park +# -add_vehicle(course) +# -vehicles = [] + + +RSpec.describe Park do + before(:each) do + @park_1 = Park.new('Jackson Hole', 10) + + + @vehicle_1 = Vehicle.new("2001", "Honda", "Civic") + @charlie = Passenger.new({"name" => "Charlie", "age" => 18}) + @jude = Passenger.new({"name" => "Jude", "age" => 20}) + @taylor = Passenger.new({"name" => "Taylor", "age" => 12}) + + @vehicle_2 = Vehicle.new("1955", "VW", 'Beetle') + @patrick = Passenger.new({'name' => 'Patrick', 'age' => 24}) + + @vehicle_1.add_passenger(@charlie) + @vehicle_1.add_passenger(@jude) + @vehicle_1.add_passenger(@taylor) + + @vehicle_2.add_passenger(@patrick) + end + + describe 'initialize' do + it 'exists' do + expect(@park_1).to be_an_instance_of(Park) + end + + it 'has name' do + expect(@park_1.name).to eq('Jackson Hole') + end + + it 'has ticket price' do + expect(@park_1.price).to eq(10) + end + end + + describe 'vehicles entry to park' do + it 'adds vehicles to an array' do + expect(@park_1.vehicles).to eq([]) + + @park_1.add_vehicle(@vehicle_1) + @park_1.add_vehicle(@vehicle_2) + + expect(@park_1.vehicles).to eq([@vehicle_1, @vehicle_2]) + end + end + + describe 'adding to the park passengers' do + before(:each) do + @park_1.add_vehicle(@vehicle_1) + end + + it 'can add passengers' do + expect(@park_1.passengers).to eq([@charlie, @jude, @taylor]) + + @park_1.add_vehicle(@vehicle_2) + + expect(@park_1.passengers).to eq([@charlie, @jude, @taylor, @patrick]) + end + end + + describe 'revenue' do + it 'starts with 0' do + expect(@park_1.revenue).to eq(0) + end + + it 'can add revenue based on vehicle passengers' do + @park_1.add_vehicle(@vehicle_1) + @park_1.add_vehicle(@vehicle_2) + + expect(@park_1.revenue).to eq(40) + end + end + +end + +### iteration 4 + + +RSpec.describe Park do + before(:each) do + @park_1 = Park.new('Jackson Hole', 10) + + + @vehicle_1 = Vehicle.new("2001", "Honda", "Civic") + @charlie = Passenger.new({"name" => "Charlie", "age" => 18}) + @jude = Passenger.new({"name" => "Jude", "age" => 20}) + @taylor = Passenger.new({"name" => "Taylor", "age" => 12}) + + @vehicle_2 = Vehicle.new("1955", "VW", 'Beetle') + @patrick = Passenger.new({'name' => 'Patrick', 'age' => 24}) + + @vehicle_1.add_passenger(@charlie) + @vehicle_1.add_passenger(@jude) + @vehicle_1.add_passenger(@taylor) + + @vehicle_2.add_passenger(@patrick) + + @park_1.add_vehicle(@vehicle_1) + # @park_1.add_vehicle(@vehicle_2) + end + + it 'has names' do + expect(@park_1.patron_name).to eq(['Charlie', 'Jude', 'Taylor']) + @park_1.add_vehicle(@vehicle_2) + expect(@park_1.patron_name).to eq(['Charlie', 'Jude', 'Taylor', 'Patrick']) + end + + it 'has minors' do + expect(@park_1.minors).to eq([@taylor]) + end + + it 'has adults' do + expect(@park_1.adults).to eq([@charlie, @jude]) + end + + +end diff --git a/spec/passenger_spec.rb b/spec/passenger_spec.rb new file mode 100644 index 0000000..f91ae04 --- /dev/null +++ b/spec/passenger_spec.rb @@ -0,0 +1,39 @@ +require './spec/spec_helper.rb' + +RSpec.describe Passenger do + before(:each) do + @charlie = Passenger.new({"name" => "Charlie", "age" => 18}) + @taylor = Passenger.new({"name" => "Taylor", "age" => 12}) + end + + it 'initializes' do + expect(@charlie).to be_an_instance_of(Passenger) + expect(@taylor).to be_an_instance_of(Passenger) + end + it 'has name' do + expect(@charlie.name).to eq('Charlie') + expect(@taylor.name).to eq('Taylor') + end + + it 'has age' do + expect(@charlie.age).to eq(18) + expect(@taylor.age).to eq(12) + end + + it 'is an adult?' do + expect(@charlie.adult?).to eq(true) + expect(@taylor.adult?).to eq(false) + end + + it 'can drive' do + expect(@charlie.driver?).to eq(false) + expect(@taylor.driver?).to eq(false) + + @charlie.drive + @taylor.drive + + expect(@charlie.driver?).to eq(true) + expect(@taylor.driver?).to eq(false) + end + +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..da8bcb2 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,4 @@ +require 'pry' +require './lib/park.rb' +require './lib/passenger.rb' +require './lib/vehicle.rb' diff --git a/spec/vehicle_spec.rb b/spec/vehicle_spec.rb new file mode 100644 index 0000000..fe436cb --- /dev/null +++ b/spec/vehicle_spec.rb @@ -0,0 +1,56 @@ +require './spec/spec_helper.rb' + +RSpec.describe Vehicle do + before(:each) do + @vehicle = Vehicle.new("2001", "Honda", "Civic") + @charlie = Passenger.new({"name" => "Charlie", "age" => 18}) + @jude = Passenger.new({"name" => "Jude", "age" => 20}) + @taylor = Passenger.new({"name" => "Taylor", "age" => 12}) + end + + describe 'initialize' do + it 'exists' do + expect(@vehicle).to be_an_instance_of(Vehicle) + end + + it 'has vehicle info' do + expect(@vehicle.year).to eq('2001') + end + + it 'has a make' do + expect(@vehicle.make).to eq('Honda') + end + + it 'has a model' do + expect(@vehicle.model).to eq('Civic') + end + end + + describe 'methods' do + it 'is speeding' do + expect(@vehicle.speeding?).to eq(false) + + @vehicle.speed + + expect(@vehicle.speeding?).to eq(true) + end + + it 'adds passengers' do + expect(@vehicle.passengers).to eq([]) + + @vehicle.add_passenger(@charlie) + @vehicle.add_passenger(@jude) + @vehicle.add_passenger(@taylor) + + expect(@vehicle.passengers).to eq([@charlie, @jude, @taylor]) + end + + it 'counts the number of adults' do + @vehicle.add_passenger(@charlie) + @vehicle.add_passenger(@jude) + @vehicle.add_passenger(@taylor) + + expect(@vehicle.num_adults).to eq(2) + end + end +end \ No newline at end of file