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)
Step by stepSolved in 4 steps with 4 images
- javacoding please thank you!arrow_forwardWrite a Java class named PhoneRecord.java that performs the following functions: The class should contain the following data attributes and methods: private String name - The customer's name private String number - The customer's phone number public PhoneRecord(String personName, String phoneNumber) - Constructor get/set Methods - For each data attribute public String toString( ) - Special method to be used when printing a phoneRecord object Thank you so much for your help. Trying to write this class has really been stumping me.arrow_forwardPortfolio Instructions: You are working for a financial advisor who creates portfolios of financial securities for his clients. A portfolio is a conglomeration of various financial assets, such as stocks and bonds, that together create a balanced collection of investments. When the financial advisor makes a purchase of securities on behalf of a client, a single transaction can include multiple shares of stock or multiple bonds. It is your job to create an object-oriented application that will allow the financial advisor to maintain the portfolios for his/her clients. You will need to create several classes to maintain this information: Security, Stock, Bond, Portfolio, and Date. The characteristics of stocks and bonds in a portfolio are shown below: Stocks: Bonds: Purchase date (Date) Purchase date (Date) Purchase price (double)…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education