You need some variables to store username, id... where are you
declaring them?? I guess you need to declare them as memeber variables
in Node class and in the Node constructor you need to read the values
for these variables.
And override toString() function in Node which will print these values,
so that you can print Node object.
Jignesh - 27 Jan 2006 06:27 GMT
Hello Stephan,
i have modified yr code and made same program that u want...
source code:
import java.io.*;
public class Demo {
static Node objLL;
static BufferedReader br = new BufferedReader (new
InputStreamReader ( System.in));
public static void main (String args[]) throws IOException {
int choice = 0;
do {
System.out.println ("\nDemo:");
System.out.println ("-----\n");
System.out.println ("Press (1) to ADD.");
System.out.println ("Press (2) to VIEW.");
System.out.println ("Press (3) to EXIT.");
System.out.print ("Choice: ");
choice = Integer.parseInt (br.readLine ());
if (choice == 1)
add ();
else if (choice == 2)
view ();
} while (choice != 3);
}
static void add () {
if (objLL == null)
objLL = new Node ();
else {
Node temp = objLL;
while (temp != null)
temp = temp.next;
temp = new Node ();
}
try{
System.out.print ("Enter Username:");
objLL.v1.add((String)br.readLine ());
System.out.print ("Enter Id:");
objLL.v2.add((String)br.readLine ());
System.out.print ("Enter Contact Number:");
objLL.v3.add((String)br.readLine ());
System.out.print ("Enter genter:");
objLL.v4.add((String)br.readLine ());
}catch(Exception e)
{
e.printStackTrace();
}
System.out.println ("\nNode added.");
}
static void view () {
if (objLL == null)
System.out.println ("\nNo nodes to display.");
else {
System.out.println ();
int loopCount = 0;
for (loopCount = 1; loopCount <=
objLL.nodeCount; loopCount++)
System.out.println (loopCount);
System.out.println("user name user ID contact
number genter");
System.out.println("-----------------------------------------------------------------");
for(int i=0;i<objLL.v1.size();i++)
{
System.out.println((String)objLL.v1.get(i) + "\t\t\t"
+(String)objLL.v2.get(i)+"\t\t\t"+(String)objLL.v3.get(i)+"\t\t\t"+(String)objLL.v4.get(i));
}
System.out.println ();
}
}
}
class Node {
public Node next;
static int nodeCount;
java.util.Vector v1 = new java.util.Vector();
java.util.Vector v2 = new java.util.Vector();
java.util.Vector v3 = new java.util.Vector();
java.util.Vector v4 = new java.util.Vector();
Node () {
next = null;
nodeCount++;
}
}
Jignesh - 27 Jan 2006 06:28 GMT
Hello Stephan,
i have modified yr code and made same program that u want...
source code:
import java.io.*;
public class Demo {
static Node objLL;
static BufferedReader br = new BufferedReader (new
InputStreamReader ( System.in));
public static void main (String args[]) throws IOException {
int choice = 0;
do {
System.out.println ("\nDemo:");
System.out.println ("-----\n");
System.out.println ("Press (1) to ADD.");
System.out.println ("Press (2) to VIEW.");
System.out.println ("Press (3) to EXIT.");
System.out.print ("Choice: ");
choice = Integer.parseInt (br.readLine ());
if (choice == 1)
add ();
else if (choice == 2)
view ();
} while (choice != 3);
}
static void add () {
if (objLL == null)
objLL = new Node ();
else {
Node temp = objLL;
while (temp != null)
temp = temp.next;
temp = new Node ();
}
try{
System.out.print ("Enter Username:");
objLL.v1.add((String)br.readLine ());
System.out.print ("Enter Id:");
objLL.v2.add((String)br.readLine ());
System.out.print ("Enter Contact Number:");
objLL.v3.add((String)br.readLine ());
System.out.print ("Enter genter:");
objLL.v4.add((String)br.readLine ());
}catch(Exception e)
{
e.printStackTrace();
}
System.out.println ("\nNode added.");
}
static void view () {
if (objLL == null)
System.out.println ("\nNo nodes to display.");
else {
System.out.println ();
int loopCount = 0;
for (loopCount = 1; loopCount <=
objLL.nodeCount; loopCount++)
System.out.println (loopCount);
System.out.println("user name user ID contact
number genter");
System.out.println("-----------------------------------------------------------------");
for(int i=0;i<objLL.v1.size();i++)
{
System.out.println((String)objLL.v1.get(i) + "\t\t\t"
+(String)objLL.v2.get(i)+"\t\t\t"+(String)objLL.v3.get(i)+"\t\t\t"+(String)objLL.v4.get(i));
}
System.out.println ();
}
}
}
class Node {
public Node next;
static int nodeCount;
java.util.Vector v1 = new java.util.Vector();
java.util.Vector v2 = new java.util.Vector();
java.util.Vector v3 = new java.util.Vector();
java.util.Vector v4 = new java.util.Vector();
Node () {
next = null;
nodeCount++;
}
}
Jignesh - 27 Jan 2006 06:29 GMT
Hello Stephan,
i have modified yr code and made same program that u want...
source code:
import java.io.*;
public class Demo {
static Node objLL;
static BufferedReader br = new BufferedReader (new
InputStreamReader ( System.in));
public static void main (String args[]) throws IOException {
int choice = 0;
do {
System.out.println ("\nDemo:");
System.out.println ("-----\n");
System.out.println ("Press (1) to ADD.");
System.out.println ("Press (2) to VIEW.");
System.out.println ("Press (3) to EXIT.");
System.out.print ("Choice: ");
choice = Integer.parseInt (br.readLine ());
if (choice == 1)
add ();
else if (choice == 2)
view ();
} while (choice != 3);
}
static void add () {
if (objLL == null)
objLL = new Node ();
else {
Node temp = objLL;
while (temp != null)
temp = temp.next;
temp = new Node ();
}
try{
System.out.print ("Enter Username:");
objLL.v1.add((String)br.readLine ());
System.out.print ("Enter Id:");
objLL.v2.add((String)br.readLine ());
System.out.print ("Enter Contact Number:");
objLL.v3.add((String)br.readLine ());
System.out.print ("Enter genter:");
objLL.v4.add((String)br.readLine ());
}catch(Exception e)
{
e.printStackTrace();
}
System.out.println ("\nNode added.");
}
static void view () {
if (objLL == null)
System.out.println ("\nNo nodes to display.");
else {
System.out.println ();
int loopCount = 0;
for (loopCount = 1; loopCount <=
objLL.nodeCount; loopCount++)
System.out.println (loopCount);
System.out.println("user name user ID contact
number genter");
System.out.println("-----------------------------------------------------------------");
for(int i=0;i<objLL.v1.size();i++)
{
System.out.println((String)objLL.v1.get(i) + "\t\t\t"
+(String)objLL.v2.get(i)+"\t\t\t"+(String)objLL.v3.get(i)+"\t\t\t"+(String)objLL.v4.get(i));
}
System.out.println ();
}
}
}
class Node {
public Node next;
static int nodeCount;
java.util.Vector v1 = new java.util.Vector();
java.util.Vector v2 = new java.util.Vector();
java.util.Vector v3 = new java.util.Vector();
java.util.Vector v4 = new java.util.Vector();
Node () {
next = null;
nodeCount++;
}
}