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
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