user3304737
user3304737

Reputation: 1

Java NotePad++ to NetBeans

We were given 3 problems but our professor wants us to convert it and work it on NetBeans.

I encountered a lot of errors that did not came out from my NotePad++.

Can you please help me with this? Later on I will proceed to add another question that I could not answer to my self.

A little Guide will also help, thanks in advance :)

Code:

package datastructures;
    public class StackArray {
        private static class Node {

            public Node() {
            }
        }
        private Node top;

        public StackArray()
        {
            top = null;
        }

        public boolean isEmpty()
        {
            return top == null;
        }

        public boolean isFull()
        {
            return false;
        }

        public boolean push(String item)
        {
            Node newNode = new Node();
            newNode.info = item;

            if(isEmpty())
            {
                top = newNode;
            }
            else
            {
                newNode.next = top;
                top = newNode;
            }
            return true;
        }

        public String peek()
        {
            if(!isEmpty())
                return top.info;
            else
                return null;
        }

        public boolean pop()
        {
            String itemPeek = peek();
            if(itemPeek != null)
            {
                top = top.next;
                return true;
            }
            else
                return false;
        }

        @Override
        public String toString()
        {
            String output = "";

            if(!isEmpty())
            {
                Node temp = top;
                while(temp != null)
                {
                    output+="["+temp.info+"]\n";
                    temp = temp.next;
                }
            }

            return output;
        }
    }

The Errors I got were:

.info .next

it also shows when run

*No Class Found

Upvotes: 0

Views: 126

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347214

Basically, Node has no properties, so newNode.info, newNode.next etc are all undefined properties.

You need to supply these as instance variables within your Node class.

Upvotes: 3

Related Questions