Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: Pls Fix my java code (using Linded List)

Reply
Thread Tools

Re: Pls Fix my java code (using Linded List)

 
 
stephen
Guest
Posts: n/a
 
      01-25-2006
Dear All!!,

I have a problem on my java program. pls help me as i can't find error.

below is my java coding.

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 ();
}

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 ();
}
}
}

class Node {

public Node next;
static int nodeCount;

Node () {

next = null;
nodeCount++;
}
}


that is program process

when u run the program.............


1.add
2.view
3.exit

enter ur number - 1

enter ur username - aung aung
enter ur ID - 122333
enter ur contact number - 313412415
enter ur genter - m

enter ur number - 2

user name user ID contact number genter
----------------------------------------------------------------------------------------
aungaung 12333 313412415 m

enter ur number - 1

enter ur username - aye
enter ur ID - 22222
enter ur contact number - 22222222
enter ur genter - f

enter ur number - 2

user name user ID contact number genter
----------------------------------------------------------------------------------------
aungaung 12333 313412415 m
aye 22222 222222222 f

enter ur number - 3

program end .........

that is all the process
no need DB and no need array
only simple java code
thx 4 helping me .

Help Me, Pls

 
Reply With Quote
 
 
 
 
Venky
Guest
Posts: n/a
 
      01-25-2006
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.

 
Reply With Quote
 
 
 
 
Jignesh
Guest
Posts: n/a
 
      01-27-2006
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++;
}



}

 
Reply With Quote
 
Jignesh
Guest
Posts: n/a
 
      01-27-2006
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++;
}



}

 
Reply With Quote
 
Jignesh
Guest
Posts: n/a
 
      01-27-2006
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++;
}



}

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
URGENT - Pls help...pls recommend - laptop purchase irfansmith@gmail.com Computer Information 2 08-15-2008 11:34 PM
Xah's Edu Corner: The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations Xah Lee Perl Misc 21 03-21-2006 07:02 AM
Xah's Edu Corner: The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations Xah Lee Python 23 03-21-2006 07:02 AM
Xah's Edu Corner: The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations Xah Lee Java 22 03-21-2006 07:02 AM
pls, help.. i need a number..pls olabanji timothy MCSE 7 09-10-2003 04:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57