A Car IS-A Vehicle
A Truck is a Vehicle
A Dragster is a Vehicle
A Tractor is a Vehicle
Every Vehicle has:
As well as these attributes, a Vehicle also has the following behaviour:
A Dragster IS-A Vehicle. It has all of the same behaviour and attributes as a Vehicle.
However, it also has a raceDistance attribute. This stores the distance that the dragster has covered in a race, starting at 0.
It also has crash() behaviour. This method randomly returns true if a dragster crashes, false otherwise.
When a Dragster honks, it honks like any Vehicle does, but after that it says "Growl!!!" like any true Dragster should!
A game is being developed.
You are coding the game logic and, other software designers are designing prototypes of the graphics.
public static void main(String[] args){
Dragster[] dragsters = new Dragster[2];
dragsters[0] = new Dragster("DG-101", 7500, 220);
dragsters[1] = new Dragster("DG-403", 11000, 240);
int raceDistance = 150;
race(dragsters, raceDistance);
}
public static void race(dragsters[] draggies, int distance){
//your game code
}
Create a game where the 2 dragsters race. The first dragster to reach the race distance is the winner.
During the race, if a dragster crashes it honks and its toString method is called.
Instead of simply having a honk() method to handle honking, let's create a Honk object.
A Dragster HAS-A Honk object.
A Honk object has a honkWord eg "Honk!" and a volume eg 10
Everytime the Honk object honks, its volume decreases by 1.
Using your own ideas, include a Honk object as a property of a Dragster.
While the race is continuiing, Dragsters honk when they crash!
But what happens when a Dragster's honk volume reaches 0?!?!
behavioursyntax method inherit instantiate constructor prototype attributeconcurrency