Answer to Question #17517 in Java | JSP | JSF for cord

Question #17517
Create a class named Product that contains private instance variables to hold the product's name, price, value, and quantity in stock. Create getters and setters that allow you to access and modify the name, price, value, and quantity of the product. Create a method named getProfit() to tell you the profit you would make if you sold one. The profit is the price less the value. Override the toString() method to return a string that contains the name of the product. Validation of the incoming data in the setters is not required.
1
Expert's answer
2012-10-30T08:20:56-0400
public class Product {
privateString name;
privatedouble price;
privatedouble value;
privateint quantity;

publicString getName() {
returnname;
}

publicvoid setName(String name) {
this.name = name;
}

publicdouble getValue() {
returnvalue;
}

publicvoid setValue(double value) {
this.value= value;
}

publicint getQuantity() {
returnquantity;
}

publicvoid setQuantity(int quantity) {
this.quantity= quantity;
}

publicdouble getPrice() {
returnprice;
}

publicvoid setPrice(double price) {
this.price= price;
}

publicdouble getProfit() {
returnthis.value - this.price;
}

@Override
publicString toString() {
return"Product name: " + name;
}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS