A Driver USES-A Car. This is an example of a Dependency relationship between a TaxiDriver and a Car.
The Driver class is .
The Car class is .
Take a moment to analyse the two classes.
Can you find examples of:
Create a project environment in your IDE and create the Driver, Car and Main classes.
In the Main class, can you figure out how to make a Driver drive a Car for 20kms.
A Driver drives a Car 10 times. Each journey is a random distance.
At the end of each journey, the fare is stored in a 10-element integer array, fareData, in the Main class.
Then, a function, searchFare, is called. This function uses the algorithm to search for a given fare.
It returns true if the given fare is found in the array and false otherwise. Here is an example of a Main program:
Driver jack = new Driver("Jack");
Car sporty1 = new Car();
int[] fareData = new int[10];
for(i =0; i<10; i++){
//code to make Driver drive the car not shown.
fareData[i] = sporty1.getFare();
sporty1.reset(); //reset distance and fare before next journey
}
boolean result = searchFare(fareData, 100);
if(!result){
System.out.println("Fare not found!");
}else{
System.out.println("Fare found!");
}
Implement the searchFare helper function in the Main class.
You may need to design another helper function to sort searchFare into ascending order of value before searching!
If you are an IBDP student you will need to be familiar with 2 popular search algorithms:
Submit your solution as instructed.
object
property
method
create an object/instance of a class
instantiate an object
encapsulate
access
mutate
abstraction
signature
methodsyntax overriding overloading instantiate instance super parameterattribute