
February 9th, 2013, 02:33 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 4
Time spent in forums: 1 h 33 m 32 sec
Reputation Power: 0
|
|
|
Store class:
import java.util.ArrayList;
public class Store {
private String id;
private String name;
private String address;
private GPSLocation location;
private ArrayList<StoreItem> items;
/**
* Create a store with the given name and location
* @param name
* @param location
*/
public Store(String id, String name, String address, GPSLocation location){
this.id = id;
this.name = name;
this.address = address;
this.location = location;
items = new ArrayList<StoreItem>();
}
/**
* Add an item to this store
* @param item
* @param price
* @param quantity
*/
public void addItem(Item item, double price, int quantity){
items.add(new StoreItem(item, price, quantity));
}
/**
* Returns a list of items in the store
* @return
*/
public ArrayList<StoreItem> getInventory(){
//i'm just going to make sure no one can change my list.
return items;
}
/**
* Returns the StoreItem given the UPC. Returns null if not found
* @param UPC
* @return
*/
public StoreItem getItemByUPC(String UPC){
for(StoreItem item : items){
if(item.getItem().getUpc().equals(UPC)){
return item;
}
}
return null;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the id
*/
public String getId() {
return id;
}
/**
* @return the location
*/
public GPSLocation getLocation() {
return location;
}
/**
* @return the address
*/
public String getAddress() {
return address;
}
@Override
public String toString(){
String out = getId() + "\n";
out += getName() + "\n";
out += getLocation() + "\n";
for(StoreItem item : items){
out += "\t" + item + "\n";
}
return out;
}
}
|