Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started