Suggested Solution

Task 1 Task 2 Task 3

Task 1

A car garage sells cars. Every time a customer buys a new car, a computer program creates a Car object in computer memory. Each object stores:

Design the Car class. Every time a Car object is constructed, the three pieces of data above are passed as parameters into the object and stored safely.

Write a computer program to instantiate 2 Car objects.

Write some logic to calculate and display the total cost of the two cars.

idea could we design a function called calculateTotal to determine this total cost for us?

Task 2

A computer game character has the following attributes:

Design the Character class.

Every time a Character object is constructed, the first three pieces of data above are passed as parameters into the object and stored safely eg Character c = new Character(6,3,"Red");.

The weakness property is determined by some logic written inside the Constructor method.

Write a computer program to instantiate a Character(s), and test if you code works as expected.

Task 3

Truck racing is back!

When a new Truck is constructed, its distance traveled is set to 0. A Truck also has a name.

Design the Truck class.

Write a computer program to instantiate 2 Trucks.

Create a game loop that will continue while both trucks have a distance of less than 100. Inside the loop, randomly increase each Truck's distance.

The first Truck to reach 100 is the winner and the name of the Truck is displayed.