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

Beverly Green IC - passengers_and_vehicles_2412 #6

Open
wants to merge 2 commits into
base: main
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
39 changes: 39 additions & 0 deletions lib/park.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class Park
attr_reader :name, :admission_price, :vehicles_in_park, :passengers_in_park

def initialize(park_details)
@name = park_details["name"]
@admission_price = park_details["admission price"]
@vehicles_in_park = []
@passengers_in_park = []
end

def add_vehicle(vehicle)
@vehicles_in_park << vehicle
end

def add_passenger(passenger)
@passengers_in_park << passenger
end

def revenue
total = @passengers_in_park.find_all { |passenger| passenger.adult?}
total.count
(total.count)*(@admission_price)
end

def patron_names
names = @passengers_in_park.map { |passenger| passenger.name}
names.sort
end

def minors
minors = @passengers_in_park.find_all { |passenger| !passenger.adult?}
minors.map { |passenger| passenger.name }
end

def adults
adults = @passengers_in_park.find_all { |passenger| passenger.adult?}
adults.map { |passenger| passenger.name }
end
end
33 changes: 33 additions & 0 deletions lib/passenger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'pry'
class Passenger
attr_reader :name, :age, :drive

def initialize(passenger_details)
@name = passenger_details["name"]
@age = passenger_details["age"]
end

def adult?
if @age >= 18
return true
else
return false
end
end

def drive
if adult? == true
return true
else
return false
end
end

def driver?
if drive == true
return true
else
return false
end
end
end
32 changes: 32 additions & 0 deletions lib/vehicle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class Vehicle
attr_reader :year, :make, :model, :passengers

def initialize(year, make, model)
@year = year
@make = make
@model = model
@speed = 0
@passengers = []
end

def speeding?
if @speed > 60
return true
else
return false
end
end

def speed(mph)
@speed += mph
end

def add_passenger(passenger)
@passengers << passenger
end

def num_adults
adults = @passengers.find_all { |passenger| passenger.adult? }
adults.count
end
end
67 changes: 67 additions & 0 deletions spec/park_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require 'pry'
require './lib/vehicle'
require './lib/passenger'
require './lib/park'

RSpec.describe do
before(:each)do
@park = Park.new({"name" => "Devil's Lake","admission price" => 15})
@vehicle = Vehicle.new("2001", "Honda", "Civic")
@charlie = Passenger.new({"name" => "Charlie", "age" => 18})
@taylor = Passenger.new({"name" => "Taylor", "age" => 12})
@jude = Passenger.new({"name" => "Jude", "age" => 20})
end
describe 'intialize' do
it 'can intialize'do
expect(@park).to be_instance_of(Park)
expect(@park.name).to eq("Devil's Lake")
expect(@park.admission_price).to eq(15)
end
end

describe 'park attributes' do
it 'can store vehicles in park' do
@park.add_vehicle(@vehicle)
expect(@park.vehicles_in_park).to be_an(Array)
end

it 'can store passengers in park' do
@park.add_passenger(@charlie)
@park.add_passenger(@taylor)
@park.add_passenger(@jude)
expect(@park.passengers_in_park).to be_an(Array)
end

it 'can charge admission price for adults' do
@park.add_passenger(@charlie)
@park.add_passenger(@taylor)
@park.add_passenger(@jude)
expect(@park.revenue).to be_an(Integer)
expect(@park.revenue).to eq(30)
end

it 'can track patrons' do
@park.add_passenger(@charlie)
@park.add_passenger(@taylor)
@park.add_passenger(@jude)
@park.patron_names
expect(@park.patron_names).to eq(["Charlie", "Jude", "Taylor"])
end

it 'can track minors' do
@park.add_passenger(@charlie)
@park.add_passenger(@taylor)
@park.add_passenger(@jude)
@park.minors
expect(@park.minors).to eq(["Taylor"])
end

it 'can track adults' do
@park.add_passenger(@charlie)
@park.add_passenger(@taylor)
@park.add_passenger(@jude)
@park.adults
expect(@park.adults).to eq(["Charlie", "Jude"])
end
end
end
40 changes: 40 additions & 0 deletions spec/passenger_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require './lib/passenger'
require 'pry'

RSpec.describe do
before(:each) do
@charlie = Passenger.new({"name" => "Charlie", "age" => 18})
@taylor = Passenger.new({"name" => "Taylor", "age" => 12})
end

describe '#intialize' do
it ' can initialize' do
expect(@charlie).to be_instance_of(Passenger)
expect(@taylor).to be_instance_of(Passenger)
end
end

describe 'passenger attributes' do
it 'can call their name'do
expect(@charlie.name).to eq("Charlie")
expect(@taylor.name).to eq("Taylor")
end

it 'can call their age' do
expect(@charlie.age).to eq(18)
expect(@taylor.age).to eq(12)
end

it 'can tell if they are an adult' do
expect(@charlie.adult?).to eq(true)
expect(@taylor.adult?).to eq(false)
end

it 'can allow adult drivers' do
expect(@taylor.driver?).to eq(false)
@charlie.drive
expect(@charlie.driver?).to eq(true)
end

end
end
52 changes: 52 additions & 0 deletions spec/vehicle_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require 'pry'
require './lib/passenger'
require './lib/vehicle'

RSpec.describe do
before(:each) do
@vehicle = Vehicle.new("2001", "Honda", "Civic")
@charlie = Passenger.new({"name" => "Charlie", "age" => 18})
@taylor = Passenger.new({"name" => "Taylor", "age" => 12})
@jude = Passenger.new({"name" => "Jude", "age" => 20})
end
describe '#initialize' do
it 'can initialize' do
expect(@vehicle).to be_instance_of(Vehicle)
end
end

describe 'vehicle attributes' do
it 'can tell the year' do
expect(@vehicle.year).to eq("2001")
end

it 'can tell the make' do
expect(@vehicle.make).to eq("Honda")
end

it 'can tell the model' do
expect(@vehicle.model).to eq("Civic")
end

it 'can tell if vehicle is speeding' do
@vehicle.speed(50)
expect(@vehicle.speeding?).to eq(false)
@vehicle.speed(70)
expect(@vehicle.speeding?).to eq(true)
end

it 'can add passengers' do
@vehicle.add_passenger(@charlie)
@vehicle.add_passenger(@taylor)
@vehicle.add_passenger(@jude)
expect(@vehicle.passengers).to be_an(Array)
end

it 'can count number of adults in vehicle' do
@vehicle.add_passenger(@charlie)
@vehicle.add_passenger(@taylor)
@vehicle.add_passenger(@jude)
expect(@vehicle.num_adults).to eq(2)
end
end
end