I have a file containing all the customer records. I had a program to read from the file and store using LinkedLists. Each Node is each customer record. Each customer record have AccID, Add, PhoneNum, etc.. All the accID, add are stored in an array. My question is how can I get all the names, ids all printed out?
I use NetBeans debugger mode and found that it is in this structure:
numRecord
item
[0]
acc_id //the correct id e.g. 123
name //Matt Damon
item
[1]
acc_id //e.g. 456
name // Ben Affleck
Code:
//ListNode.java
public class ListNode{
private Object item;
private ListNode next,head;
public ListNode(Object newItem)
{ item = newItem; next = null; }
public ListNode(Object newItem, ListNode newNext)
{ item = newItem; next = newNext; }
public void setItem(Object newItem)
{ item = newItem; }
public void setNext(ListNode newNext)
{ next = newNext; }
public Object getItem()
{ return item; }
public ListNode getNext()
{ return next; }}
//LinkedList.java
public class LinkedList{
protected ListNode head; //pointer to the first object
protected int numOfItems; //total number of objects
public LinkedList()
{ head = null; numOfItems = 0; }
public boolean isEmptyList(){
if(numOfItems==0) return true;
else return false; }
protected ListNode find(int index) {
ListNode cur = head;
if (index > numOfItems) return null;
for (int count=1; count<index; count++) cur = cur.getNext();
return cur;}
public boolean insert(int at, Object newItem)
{ ListNode pre, cur;
if (at < 1 || at > numOfItems+1) return false;
numOfItems++;
if (at == 1){
if (isEmptyList()) head = new ListNode(newItem);
else head = new ListNode(newItem, head);
return true;}
pre = find(at-1);
cur = pre.getNext();
pre.setNext(new ListNode(newItem, cur));
return true;}
public int size()
{ return numOfItems; }
//Customer.java
public class Customer{
protected int acc_id;
protected String name,address,birthdate,phone_no;
protected double balance, interest;
protected String type;
public Customer(){....} //default constructor
public Customer(int id,int name....){....}
//all the set and get methods
//Main Program
Customer[] record = new Customer[30];
LinkedList custRecords = new LinkedList();
ListNode numRecord = new ListNode(record);
while(readfile.hasNext()){ //readfile is using the Scanner class
//read all the data from file
//e.g. record[i].setID(readfile.nextInt());
custRecords.insert(i+1,record[i]);}
//put the printing here, but how?
numRecord
item
[0]
acc_id //the correct id e.g. 123
name //Matt Damon
item
[1]
acc_id //e.g. 456
name // Ben Affleck
Comment