Write java code for class produce that meets the listed


Review of Classes, Objects, Arrays, and Enhance for Looping

Given: UML Diagram of class Produce

Test Harness code: ProcessProduce.java

These instructions

Tasks:

1. Write Java code for class Produce that meets the listed requirements

2. Complete code for the ProcessProduce.java test harness as instructed below

Requirements:

Class Produce

1. Code Java class Produce according to the UML provided and the instructions included here.

2. The class Produce will require two constructors

a. The default constructor (accepting no parameters) will instantiate a Produce object with the following values:

prodName = Unspecified

prodPrice = 0.0

prodInv = 0.0

b. The second constructor will accept a String object and two double type parameters and instantiate a Produce object based on those parameters:

c. Constructors will call the appropriate "set" methods to assign values to the instance variables. NOTE: Direct assignment of instance variable values effectively invalidates the constructor, i.e., the student will score a zero for that portion of the assignment.

3. "Set" methods will be written for all instance variables

a. Each "set" method will accept the appropriate data type value and assign it to the appropriate instance variable

b. "Set" methods will not return any value

c. "Set" methods will not contain any code other than that required to set a value for the given instance variable

4. "Get" methods will be written for all instance variables

a. Each "get" method will have a return type appropriate to the data type of the instance variable

b. "Get" methods do not accept any input parameters or values

c. "Get" methods will not contain any code other than that required to return the value of the given instance variable

5. Method toString

a. Will return a String object containing all object instance variable values and formatted as follows:

%f pounds of %s at a price of %f per pound/n

where the first "%f" represents the inventory in pounds, the "%s" represents the name of the produce type, and the second "%f" represents the price per pound for the produce type

b. The toString method will call other class methods to retrieve or derive the needed values. NOTE: Direct reference to instance variable values effectively invalidates the constructor, i.e., the student will score a zero for that portion of the assignment.

c. The toString method will use method format to format the returned String object

6. There must be no unneeded (not related to one of the requirements) code.

7. As always, all guidelines in the Basic Coding Standards will be followed. Please note that this specifically includes required code comments.

ProcessProduce Java Code

The basic code provided to you will allow you to test your Produce class. You will add code to complete the following functions:

1. Each instantiated Produce object will be stored in an array. To accomplish this, you will need to do the following:

a. Declare an Array structure, one-dimensional, to hold the instantiated objects.

b. Set the size of the array to contain 5 elements.

c. Add each new Produce object to the array as it is instantiated. (Hint: this can be accomplished in a single statement that instantiates the object and assigns the new object to a position in the array structure.)

d. You will instantiate 5 Produce objects and insert them into the array structure.

e. NOTE: It is not necessary to prompt a user for input - you may simply include the test data in the object instantiation statements

2. Once all Produce objects have been instantiated and inserted into the Array structure, use an enhanced for loop structure to display the to String results for each object to the screen.

3. There must be no unneeded (not related to one of the requirements) code.

4. As always, all guidelines in the Basic Coding Standards will be followed. Please note that this specifically includes required code comments.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Write java code for class produce that meets the listed
Reference No:- TGS01033334

Expected delivery within 24 Hours