Question
For this project, you get to design and write a ProduceItem class that stores a description, cost and weight as fields. Include both a constructor
For this 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
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