I'm trying to create my own little collection of code that I can basically copy and paste into programs as I need them, but it seems to be causing some problems.

After importing a LinkedList class and a Node class into Netbeans and then changing the constructors a little bit, LinkedList can't seem to find the modified Node constructors. I think it's still trying to find the old constructors, before I modified them.

Here are the two classes. I'm new to using packages; we weren't really taught how to use them, in class. Maybe that's the problem.

The error I get is
"cannot find symbol
symbol : constructor Node(char,int)
location: class vigenerecypher.Node
Node newNode = new Node(data, asciiValue);" on line 24.

Any help would be appreciated.

package vigenerecypher;

public class Node
{
    private Node prev;
    private Node next;
    private char data;
    private int asciiValue;

    public Node()
    {
	prev = null;
	next = null;
	asciiValue = -1;
    }

    public Node(char data, int asciiValue)
    {
	this.data = data;
	this.asciiValue = asciiValue;
	next = null;
	prev = null;
    }
    
    public Node(Node node)
    {
	prev = node.prev;
	next = node.next;
	data = node.data;
	asciiValue = node.asciiValue;
    }

    public Node(char data, int asciiValue, Node prev, Node next)
    {
	this.data = data;
	this.asciiValue = asciiValue;
	this.prev = prev;
	this.next = next;
    }

    public Node getPrevious()
    {
	return prev;
    }

    public Node getNext()
    {
	return next;
    }

    public char getData()
    {
	return data;
    }

    public int getAsciiValue()
    {
	return asciiValue;
    }

    public void setPrev(Node prev)
    {
	this.prev = prev;
    }

    public void setNext(Node next)
    {
	this.next = next;
    }

    public void setData(char data)
    {
	this.data = data;
    }

    public void setAsciiValue(int asciiValue)
    {
	this.asciiValue = asciiValue;
    }

}
package vigenerecypher;

public class LinkedList
{
    Node head = new Node();
    Node tail = new Node();
    Node current = new Node();
    int length;

    public LinkedList()
    {
	head.setNext(tail);
	tail.setPrev(head);
	current = head;
	length = 0;
    }

    public void addNode(char data, int asciiValue)
    {
	Node newNode = new Node
	newNode.setPrev(tail.getPrevious());
	newNode.setNext(tail);
	newNode.getPrevious().setNext(newNode);
	tail.setPrev(newNode);
	length++;
    }

    public void insertAt(char data, int asciiValue, int position)
    {
	Node temp = new Node(head.getNext());
	for(int x = 0; x < position; x++)
	    temp = temp.getNext();
	
	if(temp.getAsciiValue == -1)
	{
	    temp.setData(data);
	    temp.setAsciiValue = asciiValue;
	    temp.setNext(tail);
	    tail.setPrev(temp);
	}
	else
	{
	    temp.setData(data);
	    temp.setAsciiValue(asciiValue);
	    temp.setNext(temp.getNext().getPrevious());
	    temp.getNext().setPrev(temp);
	}
	
	temp.getPrevious().setNext(temp);
	
	length++;
    }
    
    public int deleteNode(int dataIn)
    {
	int probes = 0;
	current = head.getNext();
	while(current.getData()!= dataIn)
	{
	    current = current.getNext();
	    probes++;
	}
	
	probes++;
	current.getNext().setPrev(current.getPrevious());
	current.getPrevious().setNext(current.getNext());
	current = head;
	length--;
	return probes;
    }
}

Line 20 of LinkedList should read:

Node newNode = new Node(data, asciiValue);

I apologize for the error.

Line 20 of LinkedList should read:

Node newNode = new Node(data, asciiValue);

I apologize for the error.

you may start with correcting this as well:

if(temp.getAsciiValue == -1)
{
temp.setData(data);
temp.setAsciiValue = asciiValue;
temp.setNext(tail);
tail.setPrev(temp);
}

to

if ( temp.getAsciiValue() == -1)
{
temp.setData(data);
temp.setAsciiValue(asciiValue);
temp.setNext(tail);
tail.setPrev(temp);
}

didn't get any errors on not finding the constructor, though

you may start with correcting this as well:

if(temp.getAsciiValue == -1)
{
temp.setData(data);
temp.setAsciiValue = asciiValue;
temp.setNext(tail);
tail.setPrev(temp);
}

to

if ( temp.getAsciiValue() == -1)
{
temp.setData(data);
temp.setAsciiValue(asciiValue);
temp.setNext(tail);
tail.setPrev(temp);
}

didn't get any errors on not finding the constructor, though

Yep, obvious mistake there. Thanks.

Still getting the error:
"java:24: cannot find symbol
symbol : constructor Node(char,int)
location: class vigenerecypher.Node
Node newNode = new Node(data, asciiValue);"

Can anyone help with this?

In what class are you getting this error?
I don't see a main method in these two classes, and I don't get an error compiling them

In what class are you getting this error?
I don't see a main method in these two classes, and I don't get an error compiling them

I'm getting the error in the LinkedList class. I don't think the Main method would be causing any problems, but here it is. It's obviously not complete yet.

package vigenerecypher;
import java.util.Scanner;

public class Main
{
    static Scanner scan;
    static String[] arg;
    static String input, plaintext, password, encryptedMessage;
    
    public static void main(String[] args)
    {

	System.out.println("ENCRYPT or DECRYPT?");
	readInput();
	validateInput();

    }

    public static void readInput()
    {
	input = scan.nextLine();
    }

    public static void validateInput()
    {
	if(input.equals("ENCRYPT"))
	{
	    encryptMessage();
	}
	else
	{
	    if(input.equals("DECRYPT"))
	    {
		decryptMessage();
	    }
	    else
	    {
		System.out.println("Incorrect command.  Try again.");
		readInput();
		validateInput();
	    }
	}
    }

    public static void encryptMessage()
    {
	System.out.print("Plaintext message: ");
	readInput();
	plaintext = input;
	System.out.print("\nPassword: ");
	readInput();
	password = input;
	encryptedMessage = createEncryptedMessage(plaintext, password);
	System.out.println("\n\nThe encrypted message is: " + encryptedMessage + "\n");
	System.out.println("Press 'ENTER' to return to the main screen...");
	scan.nextLine();
	clear();
    }

    public static void decryptMessage()
    {

    }

    public static String createEncryptedMessage(String plaintext, String password)
    {
	return "";
    }

    public static void clear()
    {
	for(int x = 0; x < 60; x++)
	    System.out.println();
	main(arg);
    }
}

I've tested this in NetBeans (so I changed the scanner in JOptionPane commands, but that's the only thing I changed) and it ran without problems.
are you sure you compiled the last versions of your classes?

I've tested this in NetBeans (so I changed the scanner in JOptionPane commands, but that's the only thing I changed) and it ran without problems.
are you sure you compiled the last versions of your classes?

I'm using Netbeans, too. Yes, the code I've posted (with the exception of that one error) is up to date. What's this about changing the scanner in JOptionPane commands?

The code-completion tool in Netbeans is picking up a couple different versions of a Node constructor, but just not the right ones. Is there a standard Node class in Java? Because, I was under the impression that there wasn't.

What's this about changing the scanner in JOptionPane commands?

because personally, I don't like to use scanner unless I'm running from a DOS-prompt :), but no matter that, that shouldn't change anything. anyway, it works over here, so don't understand why it doesn't with you :/

*sigh* I guess it's an IDE problem. Maybe I'll try a different one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.