473,378 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Linking 2 Linked Lists together

I have a Customer.java and a Transaction.java Transaction is when the user wants to deposit money. Customer.java includes the particulars of the user such as Name, AccountID, Balance etc. I have a LinkedList for Customer and a LinkedList for Transaction. How can i link the 2 together?

Expand|Select|Wrap|Line Numbers
  1. #
  2. //ListNode.java
  3. public class ListNode{
  4.     private Object item;
  5.     private ListNode next,head;
  6.     public ListNode(Object newItem)
  7.     {    item = newItem;    next = null;     }
  8.     public ListNode(Object newItem, ListNode newNext)
  9.     {    item = newItem;    next = newNext;    }
  10.     public void setItem(Object newItem)
  11.     {    item = newItem;    }
  12.     public void setNext(ListNode newNext)
  13.     {    next = newNext;    }
  14.     public Object getItem()
  15.     {     return item;    }
  16.     public ListNode getNext()
  17.     {    return next;    }}
  18.  
  19. //LinkedList.java
  20. public class LinkedList{
  21.     protected ListNode head; //pointer to the first object
  22.     protected int numOfItems; //total number of objects
  23.     public LinkedList()
  24.     {    head = null;     numOfItems = 0; }
  25.     public boolean isEmptyList(){
  26.         if(numOfItems==0)  return true;
  27.         else    return false;    }
  28.     protected ListNode find(int index) {   
  29.          ListNode   cur = head;
  30.          if (index > numOfItems) return null;
  31.          for (int count=1; count<index; count++)     cur = cur.getNext();
  32.          return cur;}
  33.     public boolean insert(int at, Object newItem)
  34.     {    ListNode   pre, cur;
  35.          if (at < 1 || at > numOfItems+1) return false;
  36.             numOfItems++;
  37.          if (at == 1){
  38.             if (isEmptyList()) head = new ListNode(newItem);
  39.             else head = new ListNode(newItem, head);
  40.             return true;}
  41.         pre = find(at-1);
  42.     cur = pre.getNext();
  43.     pre.setNext(new ListNode(newItem, cur));
  44.     return true;}
  45.     public int size()
  46.     {    return numOfItems;    }
  47.  
  48. //Customer.java
  49. public class Customer{
  50.     protected int acc_id;
  51.     protected String name,address,birthdate,phone_no;
  52.     protected double balance, interest;
  53.     protected String type;
  54.     public Customer(){....} //default constructor
  55.     public Customer(int id,int name....){....}
  56.     //all the set and get methods 
  57.  
  58. //Transaction
  59. public class Transaction{
  60.     protected int acc_id;
  61.     protected String transDate,transTime;
  62.     protected double amount;
  63.     protected String type;
  64.     protected int place;
  65. public Transaction(){
  66.     acc_id=0;
  67.     transDate=null;
  68.     transTime=null;
  69.     type=null;
  70.     place=0;}
  71. public Transaction(int id,String d.....){
  72.     acc_id=id;
  73.     transDate = d;
  74.     amount = amt; 
  75.     type=typ;
  76.     place=p;}
  77. //all the set and get methods
  78.  
  79. //Main Program
  80.  Customer[] records = new Customer[30];
  81. LinkedList custRecords = new LinkedList();
  82. ListNode numRecord = new ListNode(records);
  83. //read from file and store into Customer array
  84. //call insertTramsaction()
  85. public static void insertTransaction(String filename, LinkedList list_record,Customer[] record){
  86.         int i=0,j=0;
  87.     Transaction[] trans = new Transaction[30];
  88.  LinkedList transRecords = new LinkedList();
  89. //store into trans array...
  90.  for(i=0;i<trans.length;i++)
  91.      transRecords.insert(i+1,trans[i]);
  92. for(i=0;i<numRecords;i++){    
  93.      for(j=0;j<numTrans;j++){
  94.          if(trans[j].getID()==record[i].getID()){
  95.                        //how to link to Customer LinkedList?
  96.         }
  97.     }
  98. }
  99. }//end program
I need to link Transaction LinkedList to Customer LinkedList, because each user have their own transaction records. So, i have to linked Transaction linked list to Customer linked list according to the user's account ID.
Sep 20 '07 #1
0 1157

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Robert Morgan | last post by:
Hi, is it possible to link databases within mysql? I have a access database that I need to import into mysql this db consists of 4 other dbs linked together sharing a common switchboard. Can I link...
15
by: Rob Ratcliff | last post by:
I'm compiling the latest version of a CORBA ORB called MICO on a Cray X1. It makes heavy use of templates and namespaces. Up until the link step, the C++ source code compiled flawlessly. But, when...
7
by: Steven T. Hatton | last post by:
Is there anything that gives a good description of how source code is converted into a translation unit, then object code, and then linked. I'm particularly interested in understanding why putting...
3
by: Stephen Gray | last post by:
Hi, What I'm trying to do is produce a number of XML documents that can be linked together. For example say I had one document called "valuations.xml" which is a lists all of the...
3
by: s_subbarayan | last post by:
Dear all, 1)In one of our implementation for an application we are supposed to collate two linked lists.The actual problem is like this: There are two singularly linked lists, the final output...
1
by: Peetah_junkmail | last post by:
Hi, I'm not sure this is completely a C related question since it's more about linking problems, so don't hesitate to redirect me to a more appropriate NG. I have a set of useful functions...
1
by: Little | last post by:
Could someone help me figure out how to put my project together. I can't get my mind wrapped around the creation of the 4 double Linked Lists. Thank your for your insight. 1. Create 4 double...
4
by: nishantb | last post by:
I had posted simillar question some time back. i want to link some libraries statically on NT. currently, product execute command simillar to following. link /STACK:0x20000 /libpath:D:/lib...
2
by: Jim Johnson | last post by:
C++ linking works by using Linker to combine object files into single exe file. Does each .cpp file compile to a single .obj file? If the .cpp code called functions in some library (.lib) does...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.