Question: For this Java project, you get to design and write a ProduceItem class that stores a description, cost and weight as fields. Include both a

For this Java project, you get to design and write a ProduceItem class that stores a description, cost and weight as fields. Include both a constructor without any parameters and one with parameters for the description (String), cost (double) and weight (double) (in that order). For the constructor without parameters, set the description to an empty string, the cost to 0.0 and the weight to 0.0. Include appropriate accessor and mutator methods (and label them with comments including the terms "accessor" or "mutator"). So that the test cases compile, name the accessor methods:

  • getDescription()
  • getCost()
  • getWeight()

Additionally, name the mutator methods:

  • setDescription()
  • setCost()
  • setWeight()

Include, appropriately, the this keyword in your code. Do not use it unless it's necessary. This may mean you need to create a situation where it is required. Additionally, include a method named toString() that returns a String formatted as in the examples below (including rounding cost and cost per pound to two decimal places and weight to one decimal place).

ProduceItemDriver class

Write a ProduceItemDriver class that requests input from the user and populates a ProduceItem object and calls that object's toString() method.

Example 1

Please enter the description: bananas You entered bananas Please enter the cost: 2.0711 You entered 2.07 Please enter the weight: 4.56789 You entered 4.56789 bananas: $2.07, 4.6 pounds ($0.45/pound)

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!