Common Computer Science References
At the end of this lesson, you will be able to:
understand inheritance and how to use it correctly
review "Encapsulation" & "Constructors"
read "Using OOP", Chapter 9, Computer Based Problem Solving
read "Inheritance"
null
read over and do Lesson 4 (answers from yesterday)
use the "Vehicle" class from before
create 3 new classes that inherit from "Vehicle Class"
Vehicle (from before!)
Truck
Bike
here are some properties and methods:
Vehicle
properties:
Color: string
Speed: number (getter only)
Maximum speed:number (getter only)
(remove the other properties you had!)
methods:
Accelerate(accelerationPower: number, accelerationTime: number): void
same logic as before
Brake(breakPower: number, breakTime: number): void
same logic as before
Truck
properties:
licensePlateNumber: string
doors: int = 2
methods:
Provide_Air(airPressure: number)Â
this.speed = this.speed - airPressure / 2
Bike
properties:
cadence: number
gear: number
methods:
acceelerate (appliedPower: number, newGear: number)
this.cadense = this.cadense + appliedPower
this.speed = this.speed + (this.cadense * this.gear)
it completely overrides the existing method!
ringBell()
return "Ding ding!\n"
us the provided index.ts to create your 3 classes
using inheritance
do the above in a second language
Test Case