I am new to Java and need to know how to correct this function call parameter passing compiling error. Any ideas?
List.java compiles and here is the code.
//----------------------------------------------------------------------------
// List.java
//----------------------------------------------------------------------------
class List
{
private class Node
{ int col;
double val;
Node next, prev;
Node (int c, double v) { col = c; val = v; next = prev = null; }
public String toString() {
return String.format (" (%2d, %5.2f)", col, val);
}
public boolean equals(Node E) { return (this.val == E.val); }
}
private Node front, back, current;
private int row, length;
List(int r) { front = back = current = null; row = r; length = 0; }
void insertAfterLast(Node N)
{ Node node = new Node(N.col, N.val);
if ( this.length == 0 )
{ this.front = this.back = node;
}else {
node.prev = this.back;
this.back.next = node;
this.back = node;
this.current = node;
}
this.length++;
}
public String toString()
{ String str = "";
for(Node N = front; N != null; N = N.next)
{ if ( N == front ) { str = String.format ("%3d:", row); }
str += N.toString() + (N.next==null?"\n":"");
}
return str;
}
}
ListTest.Java does not compile. Here are the error and code.
-bash-3.00$ javac ListTest.java
ListTest.java:20: non-static variable this cannot be referenced from a static context
Entry Ea = new Entry(0, 0.0);
^
ListTest.java:24: insertAfterLast(List.Node) in List cannot be applied to (ListTest.Entry)
A.insertAfterLast(Ea);
^
ListTest.java:26: insertAfterLast(List.Node) in List cannot be applied to (ListTest.Entry)
B.insertAfterLast(Ea);
^
ListTest.java:28: insertAfterLast(List.Node) in List cannot be applied to (ListTest.Entry)
B.insertAfterLast(Ea);
^
4 errors
//----------------------------------------------------------------------------
// ListTest.java - A test client for the List ADT
//----------------------------------------------------------------------------
class ListTest
{
private class Entry
{ int col;
double val;
Entry next, prev;
// Entry Constructor
Entry (int c, double v) { col = c; val = v; next = prev = null; }
}
public static void main(String[] args)
{ int i;
List A = new List(1);
List B = new List(2);
Entry Ea = new Entry(0, 0.0);
for(i=1; i<=4; i++){
Ea.col = i;
Ea.val = Double.parseDouble(Integer.toString(i));
A.insertAfterLast(Ea);
Ea.val = Double.parseDouble(Integer.toString(10-2*i));
B.insertAfterLast(Ea);
Ea.val = Double.parseDouble(Integer.toString(9-2*i));
B.insertAfterLast(Ea);
}
System.out.println(" ");
System.out.println("Print Lists A and B which have been initialized");
System.out.println("A = " + A);
System.out.println("B = " + B);
}
}
!--removed tag-->
Enter your message below
Sign in or Join us (it's free).