Answer to Question #259165 in Java | JSP | JSF for thando

Question #259165

Write a class called Item. The Item class represents all that is common between



various multimedia items. It should have the following attributes (fields):



a) a String name to store the name of the item.



b) a String comment to store a comment about the item.



c) a double value to store how much the item cost.



It should have appropriate constructors and at least the following methods



a) getters and setters for the attributes.



b) a public String toString() method that returns a String representation of the



Item.



c) a method void depreciate() that decreases the value of the item by 5%.

1
Expert's answer
2021-10-30T19:36:31-0400
public class Item {
  private String name;
  private String comment;
  private double itemCost;
  public Item(String name, String comment, double itemCost) {
    this.name = name;
    this.comment = comment;
    this.itemCost = itemCost;
  }
  public void depreciate() {
    setItemCost(0.95 * getItemCost()); // 100% - 5% = 95%
  }
  public void setName(String name) {
    this.name = name;
  }
  public String getName() {
    return this.name;
  }
  public void setComment(String comment) {
    this.comment = comment;
  }
  public String getComment() {
    return this.comment;
  }
  public void setItemCost(double itemCost) {
    this.itemCost = itemCost;
  }
  public String getItemCost() {
    return this.itemCost;
  }
  @Override
  public String toString() {
    return "{name: " + name + ", comment: " + comment + ", item cost: " + itemCost + "}";
  }
}

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
New on Blog
APPROVED BY CLIENTS