Question: Write a Java class definition for the Product class with the following features: Instance variables : productName for the Product name of type String. productPrice

Write a Java class definition for the Product class with the following features: Instance variables : productName for the Product name of type String. productPrice for the Products price of type double. Constructor: public Product (String pName, double pPrice): A constructor without parameters public Product (String pName, double pPrice): A constructor with parameters, it creates the Product object by setting the two fields to the passed values. Instance methods: public void setProductName (String productName): Used to set the name of product. public void setProductPrice(double productPrice): Used to set the price of product. public double getProuctName(): This method returns the name of the product. public double getProductPrice(): This method returns the price of the product. public String toString(): This method prints the products name and price to the screen Write a separate class ProductDemo with a main() method that creates a Product titled Monitor with Price $1200.00 and prints the products string representation to the standard output.

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!