Menu

[Solved]63 Objects Contain Objects Real World Example Car Object Contains Steeringwheel Object 4 T Q37232953

6.3 Objects can contain other objects in the real world. Forexample, A Car object contains a SteeringWheel object, 4 Tireobjects, an Engine object, etc. Each of these objects could betheir own class, and the Car object would contain fields for theseobjects, and maybe an array for the 4 tires. For this assignment weare just going to deal with a Car and it’s tires.

1. Create a class called Tire with the following fields: brand,size (inches), and tire pressure (psi: pressure per square inch,usually around 32 to 35 psi)

2. Create a Car class that has the following fields: model,speed (current speed in mph), fuel (current fuel in gallons), andan array of 4 Tire objects.

3. For both classes, create constructors, getter/settervariables, and any other methods you think you may need.

4. Create a class called Driver with the main method. In themain method, create a Car object, and assign that car 4 tireobjects.

5. Add a method for Tire called isFlat() that returns true ifthe tire pressure is less than 20 psi.

6. Add a method Car called crash() that will randomly pop tires(the number of tires should be random, and also the tires poppedshould be random)

7. Add another method for Car that checks all for tires for aflat tire, and prints out which of the 4 tires are flat.

Expert Answer


Answer to 6.3 Objects can contain other objects in the real world. For example, A Car object contains a SteeringWheel object, 4 Ti… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *