Question: Question 1 : Define the Product Class and Attributes Define a Product class with the following private attributes: productName ( String ) productID ( int

Question 1: Define the Product Class and Attributes
Define a Product class with the following private attributes:
productName (String)
productID (int)
price (double)
Question 2: Add a Constructor
Add a constructor to the Product class that initializes productName, productID, and price.
Create an instance of Product in the main method with productName as "Laptop", productID as 101, and price as 999.99.( use the main in a different class named productDemo)
Question 3: Add displayInfo Method
Add a public method displayInfo in the Product class that returns a string containing the product's information in the format: "Product: [productName], ID: [productID], Price: $[price]". In the main method, print the details of myProduct by calling displayInfo.
Question 4: Adding Getters and Setters
Add getter and setter methods for the price and productName attributes in the Product class. In the main method, update price to 1099.99 and print the updated information.
Question 5: Adding more instances
Create at least three Product objects, modify the productName and price using setters, and call the method displayInfo for each instance.

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 Programming Questions!