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? - //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?
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
4 1581
Override the toString method of your Customer class then just loop through all the customers and printing their toString values.
Hmm, so, i don't need to use the LinkedList() or ListNode() to help me print out the data?
Hmm, so, i don't need to use the LinkedList() or ListNode() to help me print out the data?
No, LinkedLists are not used for printing, they are just a collection for storing many objects.
No, LinkedLists are not used for printing, they are just a collection for storing many objects.
I see, thanx for all your help~
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Chris Ritchey |
last post by:
Hmmm I might scare people away from this one just by the title, or
draw people in with a chalange :)
I'm writting this program in c++, however I'm using char* instead of
the string class, I am...
|
by: prime80 |
last post by:
I'm building a project database to keep track of the various
engineering projects ongoing in our department. These projects will be
grouped by priority (=High, Medium, Low) and ranked within
the...
|
by: Kent |
last post by:
Hi!
I want to store data (of enemys in a game) as a linked list, each node will
look something like the following:
struct node
{
double x,y; // x and y position coordinates
struct enemy...
|
by: Booser |
last post by:
// Merge sort using circular linked list
// By Jason Hall <booser108@yahoo.com>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
//#define debug
|
by: Jonathan Bartlett |
last post by:
Just finished a new IBM DeveloperWorks article on linked lists, and
thought you all might be interested. It's not an introduction -- it
instead covers some of the more interesting aspects of...
|
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...
|
by: MJ |
last post by:
Hi
I have written a prog for reversing a linked list
I have used globle pointer
Can any one tell me how I can modify this prog so that I dont have to
use extra pointer Head1.
When I reverse a LL...
|
by: Little |
last post by:
Could someone tell me what I am doing wrong here about declaring
mutiple double linked lists. This is what the information is for the
project and the code wil be below that. Thank your soo much for...
|
by: Dongsheng Ruan |
last post by:
with a cell class like this:
#!/usr/bin/python
import sys
class Cell:
def __init__( self, data, next=None ):
self.data = data
|
by: Joerg Schoen |
last post by:
Hi folks!
Everyone knows how to sort arrays (e. g. quicksort, heapsort etc.)
For linked lists, mergesort is the typical choice.
While I was looking for a optimized implementation of mergesort...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |