Question: Question 1 : Define the Product Class and Attributes Define a Product class with the following private attributes: productName ( String ) productID ( int
Question : Define the Product Class and Attributes
Define a Product class with the following private attributes:
productName String
productID int
price double
Question : 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 and price as use the main in a different class named productDemo
Question : 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 : 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 and print the updated information.
Question : 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
