Hi mate...This is Andy here.... I need help in JAVA...I know nothing abt JAVA...& also very poor in programming.....
The following is question for my assignment.Can you plzz help me out...
Problem Situation
You will write a small application which might be used by a shopkeeper to hold and maintain a list of items sold by the shop and allow some simple summary information to be obtained from the collection of items. The problem focuses on a container class of user-defined objects. The main features being assessed include your ability to handle several Java classes working together, the dynamic adding of new objects to a collection and searching the collection for particular objects.
*********************************************************
The Item Class
Item objects represent information about different items sold by the shop. Each object contains simple attributes and just the 'standard' methods.
Define the Item class in a file called 'Item.java' and include the following attributes as instance variables:
The name of the item, a String (for example 'Lite White Milk')
The quantity in stock, an integer
The current price of the item, a double.
The methods of class Item should include:
A constructor which accepts just the name of the item.
A constructor which accepts the name, the quantity and the price.
Getter methods for the name, the quantity and the price.
Setter methods for the name and the price but not for the quantity. The quantity will be changed only when some of the items are sold or some new ones are ordered.
A method called sell which accepts an integer and reduces the quantity of the Item by that amount. This method should not allow the quantity to fall below zero. This method simulates selling some of a Items.
A method called order which accepts an integer and increases the quantity by that amount. This method simulates more of the Item being stocked.
A method which returns the 'value' of an Item. This value is calculated by multiplying the quantity by the price.
A 'toString()' method which returns a String containing a description of the current state of the item.
It is recommended that once you have written the Item class you compile it and test it using BlueJ, by creating objects and calling their methods.
*******************************************************
The StockTake Container Class
A StockTake class is a container class which can manage a collection of Item objects.
The StockTake class should define the following attributes:
An array of Item objects
An integer to hold the maximum size of the array
An integer to keep track of how many Item objects are actually stored in the array at any time.
The StockTake class should define the following methods:
A constructor which requires the maximum number of Items which might be managed. This will be an integer. The StockTake constructor will check that the parameter is positive and if so use it as the length of an array of Item objects. If the argument is non-positive the constructor will allocate and create an array of 50 Items. The maximum array size and the current number of Items will also need to be initialized.
A method which accepts as a parameter an object of class Item. This method will attempt to store a reference to this Item object into the next available cell in the array if there is room and return true as a confirmation. If the array is full this method will return false. This method will be used by client code when ever a new Item is to be added to the collection.
A method which accepts a String argument representing the name of an Item. The method will search through the array of Items and return the first one found which has a name matching the argument. If no match is possible the method should return a null reference. This method will allow client code to search for Items.
A method which returns the current value of the entire collection of Items. This value is simply the sum of all the values of the individual Items in the array.
When you have written and compiled the StockTake class test it by creating a StockTake object and invoking the methods to create a small collection of Items.
Also add methods that:
Traverse the array of Items and collects the names (only) of any items which have zero quantity. These names (each a string) should be copied into an array of Strings and that array should be returned by the method. This method allows client codes to fetch a list of names of all Items which are out-of-stock.
Delete a named item from the collection
Sort the collection in descending order of value
Client Code and User-Interface
The aim of this class is to provide a user-interface for a modest application which uses a StockTake container class. The user-interface should be written as a 'console' application using the normal screen and keyboard to interact with a user via a simple text-based menu.
The menu must allow the following tasks to be performed:
Add a new Item to the StockTake collection
Display the full details of all Items in stock
Display the full details of an Item after specifying its name
Sell a specified quantity of an Item after first specifying its name
Purchase a specified quantity of an Item after first specifying its name
Display the total value of the entire stock of Items
Display a list of the names of all the Items which need reordering
Delete an item from the collection after specifying its name
The contents of the collection to be sorted
I need to use two utility classes (KeyboardReader.java & Script.java) provided by our faculty. I have also worked out on the code step by step whick I will send to you in my next posting...... I need to know how to make all the the five classes to get running (Item, StockTake & Console along with KeyboradReader & Script). KeyboardReader.java is used to accept an input from the user & I think Script.java too does the same(I think both have run together).
Thanking u.....Expecting a positive reply ASAP
Regards
Andy