Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to use an array as ADT

843829Oct 3 2002 — edited Oct 3 2002
I Just start learning java and my professor gave me very tough assignment and I am unable to understand where to start and what to do.

He asked me to create an array of type ITEM With WAREHOUSE object.

In this there are three objects "Warehouse", "Item" and "Main"

WAREHOUSE Object Contain following method:
+additem(n item) : void
+currentPostion() : double
+warehouse(n size): int

ITEM object contain following

-description = String = null
-cost double = 0
+item(in c : double, in p : double, in desc : Strings
+getcost() : double
+getRetailPrice : double

MAIN object contain

+main string [] args




The assignment details are as follows:

Purpose: To become familiar with arrays and implementing static Deliverables: containing:
� Main.java
� Mian.class file
� Warehouse.java
� Warehouse.class file
� Item.java
� Item.class file

Points: 10
For 5 Extra Credit points, create an Applet that does the same thing as that requested below, with the addition of producing a bar graph depicting the cost of goods vs. the retial price of goods. Add appropriate accessor methods to the Warehouse object in order that the applet can obtain the aggregate cost and aggregate retail price.
References:

�Using 5.16 as a base, implement the following class diagram

�5.16 � Write a class for a warehouse which hold radio, televisions and computers. Provide a constructor which starts a warehouse with no items. Include instance vriable to store the quantitiy of each item in the warehouse. Include methods to add to stock of each item and a method to display the content of the warhouse. Test in a main method creating two warehouses. Add items to each and display final contents of each warehouse.

�The Main.main method should create a random number of items, from 1 to 100, giving each item

a descrption name of "Item XXX", were XXX is the ordinal number between 1 and the random number.

cost (c) is a random double between 0.01 and 20.00

retail price (p) is a psudeo-random number between 0.01 and 20.00, but must be >= cost

�The Warehouse.addItem will add the item to the items array, where Warehouse.nextItem is the index position of the next available items position. Do not trap for ArrayIndexOutOfBounds just yet.

�Warehouse.currentPosition returns a value of the current financial position of the Warehouse, such that
postion = (sum retailPrice of each item) less sum(cost of each item)

� The Items constructor accepts parameters of
o c = cost
o p = retailPrice
o desc = description

� Item.getCost and Item.getRetailPrice are accessor methods for the associated private instance variables
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 31 2002
Added on Oct 3 2002
1 comment
94 views