You are welcome to add methods to any class that you may find useful. You must a
ID: 3704309 • Letter: Y
Question
You are welcome to add methods to any class that you may find useful. You must add comments to all your classes, using the javadoc style commenting. You may add other classes if you consider them necessary. The first class, Product, models a basic Product object for record keeping of the product's data on a daily basis.
Product.java details: One Constructor Constructor #1. It will take all the parameters as listed: int dNum String name double price int quantity Instance variables for the Product class int idNum String name double price int quantity Methods that must be part of the Product class (you may and probably will add other methods): Method public int getID() public void setlD(int sID) public String getName) public void setName(String sName) public double getPrice() public void setPrice(double newPrice) public int getQuantitx) public void setQuantity(int newQuantitv) Updates the quantity in inventory public String toStrina() Functionality Returns the Product's ID number. Updates the Product's ID number. Returns the Product's name. Updates the Product's name. Returns the Product's price. Updates the Product's price. Returns the quantity in inventory Returns a printable version of the Product ObjectExplanation / Answer
public class Product { private int id; private String name; private double price; private int quantity; public Product(int id, String name, double price, int quantity) { this.id = id; this.name = name; this.price = price; this.quantity = quantity; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public int getQuantity() { return quantity; } public void setQuantity(int quantity) { this.quantity = quantity; } @Override public String toString() { return "Product{" + "id=" + id + ", name='" + name + ''' + ", price=" + price + ", quantity=" + quantity + '}'; } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.