i have no insert method and still its adding node in linkedlist. code below have no error so you can run to see the problem better.
if u run this it will ask u to enter a command. i only have two commands exit and display. display command will print linklist note it will be empty bc no insert method. but it is adding empty string and int zero. which i dont want.
i think this is bc of empty constructor. but i dont know how to do it so it wont add any thing. any ideas?
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class aaa
{
/*** CREATE NODE ***/
private class node
{
private String name;
private int age;
private node next;
/*** Constructor ***/
public node()
{
name = "";
age = 0;
next = null;
}
public node(String n, int a)
{
name = n;
age = a;
next = null;
}/*** End of constructor ***/
}/*** End of Node class ***/
/*** Linked List Constructor ***/
private node head_node;
private node current_node;
public aaa()
{
head_node = new node();
current_node = new node();
}
/*** Insert Method ***/
public void insert(String name, int age)
{
}/*** End of Insert Method ***/
/*** Delete Method ***/
/*** Display Method ***/
public void display()
{
current_node = head_node;
System.out.println("name\tage");
while(current_node != null)
{
System.out.println(current_node.name+"\t"+current_node.age);
current_node = current_node.next;
}
}/*** End of Display Method/
/*** Main Method ***/
public static void main(String[] args) throws IOException
{
aaa m = new aaa();
String cmd = "";
int age = 0;
String name = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);
System.out.print("Enter a Command: ");
cmd = br.readLine();
while(!(cmd.equals("exit")))
{
if(cmd.equals("insert"))
{
}
else if(cmd.equals("display"))
{
m.display();
}
System.out.print("Enter a Command: ");
cmd = br.readLine();
}
}
}