Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

Objectives:

  • Use Javadocs to document a class and methods
  • Design and write a Java class
  • Use fields (instance variables)
  • Write multiple constructors
  • Write accessor methods
  • Write mutator methods
  • Use the this keyword
  • Use string concatenation
  • Round floating point numbers (using Math.round())
  • Use a Scanner object

Description

ProduceItem class

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). Also, include a getCostPerWeight() method that returns the cost divided by the weight. Do not write a public setCostPerWeight() method. That would allow code outside of the class to make the calculation inconsistent with the cost and weight fields.

 

ProduceItemDriver class

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

Examples (user input in bold face blue)

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)

Example 2

Please enter the description: carrots You entered carrots Please enter the cost: 0.89 You entered 0.89 Please enter the weight: 2.000001 You entered 2.000001 carrots: $0.89, 2.0 pounds ($0.44/pound)

Example 3

Please enter the description: fresh wasabi root You entered fresh wasabi root Please enter the cost: 10.95 You entered 10.95 Please enter the weight: 0.15 You entered 0.15 fresh wasabi root: $10.95, 0.2 pounds ($73.0/pound)

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education