Question: In object-oriented programming, the concept of encapsulation hides the implementation details of a class and forces the user to use an interface to access data.

In object-oriented programming, the concept of encapsulation hides the implementation details of a class and forces the user to use an interface to access data. This helps to make the code more maintainable.

(a) Define a Java class named Vehicle with at least THREE (3) instance variables with private access modifiers. One of these instance variables will be the price and the category. Define THREE (3) getter and TWO (2) setter instance methods to access or modify any of the objects instance variables. One of the setter methods is used to set the value of the price instance variable. If the price value given is above 100000, the category will be assigned as Luxury, else it will be assigned as Standard by default. (15 marks)

(b) Define another Java class with the main() method to demonstrate the access and manipulation of the object Vehicle above. Demonstrate the use of all the getter and setter methods defined in the Vehicle class. Show the results of the Vehicle default category when the initial price is 100000 or less, and the updated category when the price is set to above 100000. (10 marks)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!