Please help me with my programming.
Hi guys im just need alittle help.
Ive been given this assignment for uni but I dont quite understand how to do it.
This is the project outline and anyone who reads it and helps me (even just explaining how to do it alittle) would have all my thanks.
The purpose of this project is to simulate a simple supermarket. We will first describe the project briefly and then give the details of the classes that you will need to write. Our supermarket has the following features:
All the items in the supermarket (called the inventory) are kept in a file in your current folder. We will supply you a fragment of a java class that will help you to read this file from the disk. The file has a very simple format. Each line contains the name of the item and how many pieces of the item exists in the inventory. For example,
Each customer (or shopper) randomly buys a few items from the inventory, however, each customer always buys 50 pieces of the item she chooses (e.g., 50 potato, 50 cheese etc.). A customer may also leave the store without buying anything.
Customers also have another role. If a customer wants to buy an item (50 pieces) and currently there are less than 50 pieces of that item in stock, the customer makes the total available pieces of that item equal to 100 (she adds the remaining pieces). This of course is unrealistic, but we make this simplifying assumption. You can assume that the customer requests a staff of the super market to add those remaining pieces. If this happens, we say that the customer "re-stocks" the item. A customer does not buy the item that she re-stocks. However, she can buy that item if that item comes up next time when she generates a random number.
A report of a customer's activities (buying items, re-stocking items etc.) is printed using the System.out.println statement (BlueJ pops up a separate window whenever you use the System.out.println statement). A customer can buy the same item repeatedly and also may leave without buying anything (it all depends on the generated random numbers).
Details of the classes
You will need five classes to implement the project. While it is possible to write the project in many different ways, you have to follow these guidelines strictly. The guidelines have been designed deliberately so that you have to pass references (of objects) among objects that are instances of different classes. These classes are discussed below: (Note: I have changed the names of the classes by changing the first letter of each name to upper-case from lower-case (on October 9). However, you can keep the old names if you have done significant amount of coding already with the old names.)
Item.java: An item is stored by creating an instance of this class. Each item has a name and a quantity (as discussed above). You have to write the constructor(s), and appropriate setter and getter methods.
LoadInventory.java: You can use this class to read the inventory file and store the lines of the inventory file in an array. Each entry of the array will store a complete line, e.g., soap 70. You have to later extract the name of the item and the quantity from this line. <="" a="">Here is an outline of this class.
CartItem.java: This is where a shopper puts an individual item. It has two attributes, itemInCart (the item, note that we only need the name, but this specification is deliberate and you have to store an item) and quantity how many copies of the item the shopper is buying (e.g., 50 soaps, 50 potatoes etc.). Even though the shopper always buys 50 copies of an item, you still have to store 50.
You have to decide whether you need constructor(s), getter and setter methods depending on the requirements of the project.
ShoppingCart.java: This is the complete shopping cart of the shopper. In other words, the shopper deposits the items she purchases in an instance of this class. This class has two attributes, a reference to an array of cartItems called basket and a reference to an array of items available in the super market. The constructor takes the reference of an array of items as a parameter and initializes this attribute. The constructor also can construct the basket.
The shopper completes her shopping in this class. The policy for buying an item is the following. Suppose there are k items in the inventory, she generates a random number between 0 and k to choose an item and then buys 50 pieces of that item. She also has the responsibility to re-stock an item if there are less than 50 pieces of that item.
SuperMarket.java: This is the engine of our program, most of the controls are here. This class has the following attributes:
supplier: This is an instance of the LoadInventory class. You have to access the inventory through this reference.
supplierInventory: This is an array of String that will hold the inventory, i.e., each entry in the array will hold a complete line of the inventory (e.g., milk 60). You have to separate the name and the quantity of an item (see below).
itemsInAisle: This is an array of Items. You will store here the items and the respective quantities that you separate from the entries in supplierInventory.
inventoryFile: This is a string that stores the name of the inventory file. We will use the name inventory.file for the inventory file.
numOfItemsInventory: This variable stores the number of items in the inventory.
You have to write appropriate getter and setter methods for this class.
The constructor will create a new LoadInventory object by passing the name of the inventory file to the constructor of the LoadInventory class and get back a reference of the LoadInventory object. This reference then can be used to get the inventory list from the LoadInventory object (by calling a getter method in the LoadInventory object). You can also get back the number of items in the inventory using the same reference.
You have to write other appropriate getter and setter methods that you may find necessary.
You will also need an important method called superMarketEngine (or main if you are writing the project outside BlueJ) that will drive our Super Market. This method has the following tasks (you can of course break these tasks into smaller methods if you want):
Separate the names and quantities of the items from each line of the inventory file and create a list of items (Hint: Use a StringTokenizer object created for each line. You should lookup the Java API to see how to use a StringTokenizer object.)
We will assume there are 10 shoppers in our system. These 10 shoppers will shop in a for loop (one iteration of the loop for each shopper). For each shopper, you have to do the following:
Make a shopping trolley for the shopper by creating an instance of the ShoppingCart class (also get back the reference of the shopping trolley). Remember that the constructor of the ShoppingCart class takes the list of items available in the super market.
Randomly generate an integer between 0 and 5. This will be the number of items that the shopper will purchase.
Now call an appropriate method of the ShoppingCart object by passing this random number. You should get back the reference of the shopping basket that the shopper uses inside the ShoppingCart object. This shopping basket is an array of CartItem objects (that the shopper has either placed in the shopping basket or re-stocked).
Finally print out the contents of the basket from the array in the previous step.
Though we have mentioned only one method called superMarketEngine, you may write more than one method that collectively perform these tasks.
However, you must have a method called superMarketEngine that does not take any parameters. We will create an instance of the SuperMarket class and execute this method (if you are writing your project in BlueJ) and your program should work as specified in this document. The main method (if you are writing the project outside BlueJ) should not take any parameters as well.
Re: Please help me with my programming.
I recommend reading the getting help link in my signature as well as the following page: http://www.javaprogrammingforums.com...e-posting.html
Re: Please help me with my programming.
When reading the whole task request it may seem a bit hard to understand, but watch the guidelines, and you could do at least the simple tasks (create the classes, the getters/setter etc). Then, come-back here for the more advanced ones. There is no point for us, and you if we solve your homework completely. There will be more assignments like this, what will you do then? Think about that.
Re: Please help me with my programming.
Try writing an Algorithm on the specification. Write a step by step what you would need to do next, next, next etc.
That way you will be able to easily navigate your way through google for each step such as "create a class" , "Create a method", "Read Data from file", "Save data" etc...