Question: Question 1: (a) Develop a Java class that represents a product as follows: The product should have a description and a price and an ID

 Question 1: (a) Develop a Java class that represents a product

Question 1: (a) Develop a Java class that represents a product as follows: The product should have a description and a price and an ID Apply the principle of encapsulation by making the description and price private, and provide appropriate setter and getter methods for them. Make the ID public Define a default constructor, which generates a random number for the ID, and set the price to 10, and the description to "Unknown Define the toString method for the class to return an appropriate description of the product. (b) Based on the Product class in part (a), complete the following main program: Public class Test Product Public static void main(String[] args) { //1. Create two objects, item1 and item2, with the following values. Object name item1 item2 Description Book Pencil Price 54.50 I 20 1/2. Increment the price of item1 by 10. //3. Print the total prices of item1 and item2. //4. Change the description of item 1 to "Java Book" //6. Use toString method to print item2

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!