Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-23-2008, 12:01 AM
Member
 
Join Date: Nov 2008
Posts: 3
Rep Power: 0
blevault is on a distinguished road
Default Capture elements from an List in a different package
Hi,
I am working on a program that has elements in an ArrayList in a ShoppingCart Class in a product package.

In Shopping Cart in the getItems method, I first created a list (required for assignment) in the getItems method List<Item> itemsList = new ArrayList(items);

I check this list for size and it matches my ArrayList items.

I also have my return return itemsList;

public List getItems()
{
List<Item> itemsList = new ArrayList(items);
//System.out.printf(" Total Price: %s\n", cPrice);
//clear();
return itemsList;

I need to to two things. First my Customer class in a different package I use a getCart method to access the getItems and then move the list as single element into a new list called bill.


I am unsure of how to code the getCart in my Customer class to get the list and move it to my Bill Class. Here is what I am currently trying.

public ShoppingCart getCart()
{
List<Bill> billList = new ArrayList();
billList = (List<Bill>) cart.getItems(); //(cart.getItems());
System.out.printf("\n billList Size: %d\n", billList.size());
return cart;

}

Any help would be appreciated.

Thanks

Last edited by blevault; 11-23-2008 at 12:41 AM.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-23-2008, 01:13 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 1,018
Rep Power: 3
Nicholas Jordan is on a distinguished road
Default
What package is Customer in? Just use
Code:
import (package).Customer;
in the file in which you wish to use Customer class, then do:
Code:
Customer customer = new Customer();//
in the Shopping Cart class, whatever methods you need in Shopping Cart, write them in Customer and they will show up on customer.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-23-2008, 01:42 AM
Member
 
Join Date: Nov 2008
Posts: 3
Rep Power: 0
blevault is on a distinguished road
Default Import for my class
Hi

I have my imports set and my package declarations are set. In my Customer Package I call. I tried this code as well as numerous other attempts, but I either cant compile or it retrurns 0 elements.

billList = (List<Bill>) cart.getItems(); //(cart.getItems());

Here is my customer class.

// Customer.java
// Customer class defines user customer with references to other objects.
package user;
// wk3.package user;

import java.util.ArrayList;
import java.util.List;
import product.*;
//import wk3.product.*;


public class Customer extends DefaultUser
{
private Address address= new Address();
private ArrayList<Bill> bills = new ArrayList<Bill>();
private ShoppingCart cart= new ShoppingCart();

public Customer()
{
}

public Customer(int id)
{
super(id);
}

public ShoppingCart getCart()
{
List<Bill> billList = new ArrayList();
billList = (List<Bill>) cart.getItems(); //(cart.getItems());
System.out.printf("\n billList Size: %d\n", billList.size());
return cart;

}

public void checkout()
{
getCart();

}
Is this a proper statement to have it return the elements of itemsList?

Thanks
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-23-2008, 03:18 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 3,190
Rep Power: 5
Fubarable is on a distinguished road
Default
as I see it, the getCart() method should return the cart, nothing less, nothing more. The cart that is returned is then used to generate the bill, but this is not done within the getCart method.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-23-2008, 03:53 AM
Member
 
Join Date: Nov 2008
Posts: 3
Rep Power: 0
blevault is on a distinguished road
Exclamation
Yes, you must be correct. It only has to return the cart. However, I am unsure of how to use this. How to use all these methods seems to be the biggest issue I have right now. What calls what, and then what do I need to code.

In my class I have the following.

attributes:
-address Address <create>
-bills ArrayList<Bill> <create>
-cart ShoppingCart <create>

+Customer()
+Customer(int id)
+checkOut() void
+getAddress() void
+getBills() List<Bill>
+findBillById(int id) Bill
+findBillByDate(Date date) Bill
+findCurrentBill() Bill
+getCart() ShoppingCart

attributes:
-TAX_RATE
-address Address
-date Date <create>
-items ArrayList<Item>
-subTotal float
-totalTax float
-totalCost float

+Bill (List<Item> items)
+Bill(int id, List<Item> items)
+getAddress Address
+setAddress Address
+getDate Date
+setDate Date
+getItems(ArrayList<Item>)
+subTotal float
+totalTax float
+totalCost float
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 11-27-2008, 09:14 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 1,018
Rep Power: 3
Nicholas Jordan is on a distinguished road
Lightbulb study OO
I coded till I wore out, study OO. Set down on the project and figure stuff like Customer has Bill and just do whatever OO tells you to do.
Code:
// A customer.
class Customer
{
    int id;
    boolean done;
    private List<Bill> lb;
    Customer(){lb = new List<Bill>();}
    Customer(int id){this();id = id}
    void checkOut(){done = true;}
    Address getAddress(){}
    List<Bill> getBills() {return }
    +findBillById(int id) Bill
    +findBillByDate(Date date) Bill
    +findCurrentBill() Bill
    +getCart() ShoppingCart
}
// Class Bill
class Bill
{
    //
    final BigDecimal TAX_RATE;
    static{TAX_RATE = new BigDecimal(123456.7890);}
    Date date;
    Integer id;
    Address address;
    Date <create>
    ArrayList<Item> Items;
    double subTotal;
    double totalTax;
    double totalCost;

    Bill (List<Item> items)
    {
        // This will need a cast or some further work.....
        Items = items;
        Bill(int id, List<Item> items)
        {
            id = new Integer(id);
            Items = items;//
        }
        Address getAddress(){return address;}
        void setAddress(String[] data){Address = new (data);} 
        Date getDate(){return date;}
        void setDate{ date = new Date(); }
        ArrayList<Item> getItems(){return Items;}
    }
}

class Address
{
    String street_number;
    String street_name;
    String citadel_name;
    String estacion_de_residence;
    String country_of_residence;
    // preliminary constructor .....
    Address(String[] data)
    {
        street_number = data[0];//
        street_name = data[1];//
        citadel_name = data[2];//
        estacion_de_residence = data[3];//
        country_of_residence = data[4];//
    }
}
class Item
{
    String name;
    String description;
    String vendor;
    Item(String name, String description, String vendor)
    {
        name = name;
        description = description;
        vendor = vendor;
    }
}
That's got to be the most unusual editor I have ever seen, can you post in our what editor are you using Thread and explain where + became Java code?
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to capture a widget image with a GC Java Tip SWT 0 07-02-2008 08:00 PM
Removing elements from a List JavaForums Java Blogs 0 06-21-2008 12:31 PM
Capture screenshots JavaForums Java Blogs 0 01-07-2008 04:50 PM
Elements package BlitzA New To Java 0 12-27-2007 11:58 PM
How to capture IP packets Hasan Networking 1 05-31-2007 05:44 PM


All times are GMT +2. The time now is 12:43 PM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org