Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 9th, 2013, 02:33 PM
bfmcgee bfmcgee is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 bfmcgee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 33 m 32 sec
Reputation Power: 0
Help with Java

Hello all. I need some help creating a new class in my java program. I need to create a class that does two things. The first is the plan for which stores to visit in what order and what to buy at each of those stores. This plan will be stored as an ArrayList of Store objects. The StoreItems in these Store objects will eventually contain the items to buy from that store. The second component of the shopping plan is a list of items we were unable to find in any store, which will be stored in an ArrayList of RecipeItem objects. Additionally, the shopping list will have a toString method.


I'm lost on how to go about creating this class. I will add the RecipeItem and Store classes in the comments.

Reply With Quote
  #2  
Old February 9th, 2013, 02:33 PM
bfmcgee bfmcgee is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 bfmcgee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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;
}
}

Reply With Quote
  #3  
Old February 9th, 2013, 02:34 PM
bfmcgee bfmcgee is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 bfmcgee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 33 m 32 sec
Reputation Power: 0
RecipeItem class:

/**
* An item in a recipe
*
*/
public class RecipeItem {

private Item item;
private int quantity;

public RecipeItem(Item item, int quantity) {
this.item = item;
this.quantity = quantity;
}

/**
* @return the item
*/
public Item getItem() {
return item;
}

/**
* @return the quantity
*/
public int getQuantity() {
return quantity;
}

@Override
public String toString(){
return getItem() + " Qty: " + getQuantity();
}
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Help with Java

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap