Declare the class Bike and define the following fields of this class (with the access modifier private): wheels (no of wheels) , brand , year, price, color and quantity. Create a constructor of this class consisting of the previously mentioned fields. Create methods to return each of the fields and methods to set values for each of the fields. Additionally, create the sell() method (simulating bike sales) which will change the value of the quantity field when called. The last method to create is the toString() method that returns an object of type String and prints the names of all fields of a given object and values. Create another class with the main() method in it. Create an object of the Bike class by using the constructor. Call the toString() method and print the details. Call the sell() method. Print all fields (using the previously declared getter methods of the object field).
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Declare the class Bike and define the following fields of this class (with the access modifier private): wheels (no of wheels) , brand , year, price, color and quantity.
Create a constructor of this class consisting of the previously mentioned fields. Create methods to return each of the fields and methods to set values for each of the fields. Additionally, create the sell() method (simulating bike sales) which will change the value of the quantity field when called.
The last method to create is the toString() method that returns an object of type String and prints the names of all fields of a given object and values.
Create another class with the main() method in it. Create an object of the Bike class by using the constructor. Call the toString() method and print the details.
Call the sell() method. Print all fields (using the previously declared getter methods of the object field).
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 4 images