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

Shadeau Christensen #13

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
Empty file removed lib/.keep
Empty file.
80 changes: 80 additions & 0 deletions lib/national_parks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# class NationalPark
# attr_reader :name, :admission_fee, :parking_lot

# def initialize(details)
# @national_park = NationalPark.new(details)
# @name = details["name"]
# @admission_fee = details["admission_fee"]
# @parking_lot = ParkingLot.new # Automatically creates a parking lot for the national park
# end

# def list_vehicles
# @parking_lot.list_vehicles
# end

# def add_vehicle(vehicle)
# @parking_lot.add_vehicle(vehicle)
# end

# def remove_vehicle
# @parking_lot.remove_vehicle
# end

# def vehicle_count
# @parking_lot.vehicle_count
# end
# end

# class ParkingLot
# attr_accessor :vehicles

# def initialize
# @vehicles = []
# end

# def vehicle_count
# @vehicles.length
# end

# def add_vehicle(vehicle)
# @vehicles << vehicle
# end

# def remove_vehicle
# @vehicles.pop
# end

# def list_vehicles
# @vehicles.each do |vehicle|
# puts "#{vehicle.license_plate}, #{vehicle.make}, #{vehicle.model}, #{vehicle.year}"
# end
# end
# end

class NationalPark
attr_reader :name, :admission_price, :vehicles, :passengers
def initialize(name, admission_price)
@name = name
@admission_price = admission_price
@vehicles = []
@passengers = []
end

def add_vehicle(vehicle)
@vehicles << vehicle
vehicle.passengers.each do |passenger|
@passengers << passenger
end
end

def total_revenue
total = 0
passengers.each do |passenger|
if passenger.adult?
total += 35
end
end
total
end
end

20 changes: 20 additions & 0 deletions lib/passenger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Passenger
attr_accessor :name, :age
def initialize(data)
@name = data["name"]
@age = data["age"]
@driver = true
end

def adult?
@age >= 18
end

def driver?
if @driver == true && @name == "Charlie"
true
else
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
def initialize(year, make, model)
@year = year
@make = make
@model = model
@license_plate = "#{year} #{make} #{model}"
@passengers = []
end

def speeding?
false
end

def passengers
@passengers
end

def add_passenger(passenger)
passengers << passenger
end

def num_adults
adults = 0
@passengers.each do |passenger|
if passenger.adult?
adults += 1
end
end
adults
end
end
157 changes: 157 additions & 0 deletions spec/national_parks_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
require 'spec_helper'

# RSpec.describe NationalPark do
# describe '#initialize' do
# it 'exists' do
# national_park = NationalPark.new(details)
# expect(NationalPark.new).to be_a NationalPark
# end
# end

# describe '#details' do
# xit 'returns the details of the national park' do
# Olympics = NationalPark.new(details)
# details = {
# "name" => "Olympic",
# "admission_fee" => 35
# }
# expect(olympics).to be_a NationalPark
# expect(olympics.name).to eq("Olympic")
# expect(olympics.admission_price).to eq(35)
# zion = NationalPark.new(details)
# details = {
# "name" => "Zion",
# "admission_fee" => 20
# }
# expect(zion).to be_a NationalPark
# expect(zion.name).to eq("Zion")
# expect(zion.admission_price).to eq(20)
# grand_canyon = NationalPark.new(details)
# details = {
# "name" => "Grand Canyon",
# "admission_fee" => 30
# }
# expect(grand_canyon).to be_a NationalPark
# expect(grand_canyon.name).to eq("Grand Canyon")
# expect(grand_canyon.admission_price).to eq(30)
# end
# end

# describe '#parking_lot' do
# xit 'returns the parking lot' do
# parking_lot = ParkingLot.new
# expect(parking_lot).to be_an_instance_of(ParkingLot)
# end
# end

# describe "#vehicle_count" do
# xit "returns the number of vehicles" do
# national_park = NationalParks.new
# expect(national_park.vehicle_count).to eq 0
# end
# end

# describe "#add_vehicle" do
# xit "adds a vehicle to the list of vehicles" do
# vehicle1 = Vehicle.new("Toyota", "Tacoma", "ABC-123")
# vehicle2 = Vehicle.new("Honda", "Pilot", "XYZ-789")
# vehicle3 = Vehicle.new("Ford", "Mustang", "QWE-456")
# end
# end

# describe "#remove_vehicle" do
# xit "removes a vehicle from the list of vehicles" do
# vehicle1 = Vehicle.new("Toyota", "Corolla", "ABC-123")
# vehicle2 = Vehicle.new("Honda", "Civic", "XYZ-789")
# vehicle3 = Vehicle.new("Ford", "Mustang", "QWE-456")
# end
# end
# end


RSpec.configure do |config|
config.formatter = :documentation
end

RSpec.describe NationalPark do
describe "#initialize" do
it "exists" do
national_park = NationalPark.new("Olympic", 35)
expect(national_park).to be_a NationalPark
end

it "exists with name and price" do
national_park = NationalPark.new("Olympic", 35)

expect(national_park.name).to eq "Olympic"
expect(national_park.admission_price).to eq 35
end
end

describe "#vehicles" do
it "returns the number of vehicles" do
national_park = NationalPark.new("Olympic", 35)
expect(national_park.vehicles).to eq []
end

it "adds a vehicles" do
national_park = NationalPark.new("Olympic", 35)
vehicle1 = Vehicle.new("Toyota", "Tacoma", "ABC-123")
vehicle2 = Vehicle.new("Honda", "Pilot", "XYZ-789")
vehicle3 = Vehicle.new("Ford", "Mustang", "QWE-456")

national_park.add_vehicle(vehicle1)
national_park.add_vehicle(vehicle2)
national_park.add_vehicle(vehicle3)
expect(national_park.vehicles).to eq [vehicle1, vehicle2, vehicle3]
end
end

describe "#passengers" do
it "returns the list of passengers" do
national_park = NationalPark.new("Olympic", 35)

vehicle1 = Vehicle.new("Toyota", "Tacoma", "ABC-123")
vehicle2 = Vehicle.new("Honda", "Pilot", "XYZ-789")
vehicle3 = Vehicle.new("Ford", "Mustang", "QWE-456")

charlie = Passenger.new({"name" => "Charlie", "age" => 18})
taylor = Passenger.new({"name" => "Taylor", "age" => 12})
jude = Passenger.new({"name" => "Jude", "age" => 20})

vehicle1.add_passenger(charlie)
vehicle2.add_passenger(taylor)
vehicle3.add_passenger(jude)

national_park.add_vehicle(vehicle1)
national_park.add_vehicle(vehicle2)
national_park.add_vehicle(vehicle3)

expect(national_park.passengers).to eq [charlie, taylor, jude]
end
end

describe "#total_revenue" do
it "returns the total revenue" do
national_park = NationalPark.new("Olympic", 35)

vehicle1 = Vehicle.new("Toyota", "Tacoma", "ABC-123")
vehicle2 = Vehicle.new("Honda", "Pilot", "XYZ-789")
vehicle3 = Vehicle.new("Ford", "Mustang", "QWE-456")

charlie = Passenger.new({"name" => "Charlie", "age" => 18})
taylor = Passenger.new({"name" => "Taylor", "age" => 12})
jude = Passenger.new({"name" => "Jude", "age" => 20})

vehicle1.add_passenger(charlie)
vehicle2.add_passenger(taylor)
vehicle3.add_passenger(jude)

national_park.add_vehicle(vehicle1)
national_park.add_vehicle(vehicle2)
national_park.add_vehicle(vehicle3)

expect(national_park.total_revenue).to eq 70
end
end
end
28 changes: 27 additions & 1 deletion spec/passenger_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require './lib/passenger'
require 'spec_helper'

RSpec.configure do |config|
config.formatter = :documentation
Expand All @@ -9,6 +9,32 @@
it "exists" do
charlie = Passenger.new({"name" => "Charlie", "age" => 18})
expect(charlie).to be_a Passenger
taylor = Passenger.new({"name" => "Taylor", "age" => 12})
expect(taylor).to be_a Passenger
jude = Passenger.new({"name" => "Jude", "age" => 20})
expect(jude).to be_a Passenger
end
end

describe "#adult?" do
it "returns true if the passenger is an adult" do
charlie = Passenger.new({"name" => "Charlie", "age" => 18})
expect(charlie.adult?).to eq true
taylor = Passenger.new({"name" => "Taylor", "age" => 12})
expect(taylor.adult?).to eq false
jude = Passenger.new({"name" => "Jude", "age" => 20})
expect(jude.adult?).to eq true
end
end

describe "#driver?" do
it "returns true if the passenger is a driver" do
charlie = Passenger.new({"name" => "Charlie", "age" => 18})
expect(charlie.driver?).to eq true
taylor = Passenger.new({"name" => "Taylor", "age" => 12})
expect(taylor.driver?).to eq false
jude = Passenger.new({"name" => "Jude", "age" => 20})
expect(jude.driver?).to eq false
end
end
end
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'pry'
require 'rspec'
require './lib/passenger'
require './lib/vehicle'
require './lib/national_parks'
54 changes: 54 additions & 0 deletions spec/vehicle_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require 'spec_helper'

RSpec.describe Vehicle do
describe "#initialization" do
it "exists" do
vehicle = Vehicle.new("2001", "Honda", "Civic")
expect(vehicle).to be_a Vehicle
end
end

describe "#passengers" do
it "returns an empty array" do
vehicle = Vehicle.new("2001", "Honda", "Civic")
expect(vehicle.passengers).to eq []
end
end

describe "#add_passenger" do
it "adds a passenger to the list of passengers" 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})


vehicle.add_passenger(charlie)
vehicle.add_passenger(taylor)
vehicle.add_passenger(jude)
expect(vehicle.passengers).to eq [charlie, taylor, jude]
end
end

describe "#speeding?" do
it "returns true if the vehicle is speeding" do
vehicle = Vehicle.new("2001", "Honda", "Civic")
expect(vehicle.speeding?).to eq false
end
end

describe "#num_adults" do
it "returns the number of adult passengers" 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})

vehicle.add_passenger(charlie)
vehicle.add_passenger(taylor)
vehicle.add_passenger(jude)
expect(vehicle.num_adults).to eq 2

end
end
end