Define an interface as follows: Interface Bicycle { // wheel revolutions per minute void changeCadence(int newValue); //will change value of candence to new value void changeGear (int newValue); changes gear of car void speedUp(int increment); //increments speed of car by adding new Value to existing speed void applyBrakes
Define an interface as follows:
Interface Bicycle {
// wheel revolutions per minute
void changeCadence(int newValue); //will change value of candence to new value
void changeGear (int newValue); changes gear of car
void speedUp(int increment); //increments speed of car by adding new Value to existing speed
void applyBrakes(int decrement); }//decease car speed by subtracting value from speed.
To implement this interface, the name of your class would change (to a particular brand of bicycle, for example, such as ACMEBicycle, KEYOBicycle), and you'd use the implements keyword in the class declaration:
class ACMEBicycle implements Bicycle{
int cadence = 0;
int speed = 0;
int gear = 1;
//methods of interface
}
These clases will implements the abstract method of interface and provide definitions according to them. Now in main class you will ask user what kind of bicycle he/she wants create object of that class, then asks user for options
1. Change cadence
2. Change gear
3. Speed UP
4. Apply brakes
Call appropriate method and print values at the end.
Programming language : Java
Trending now
This is a popular solution!
Step by step
Solved in 2 steps