public class Bank {
public static void nsUI(){
Bank objBank = new Bank();
objBank.LoadData();
}
public void UI(){
if(UserInput==7){
Exit();
}
}
public void Exit(){
System.out.printf("Have a Wonderful Day! %n");
IntSLList.printAll(); /////////This is where the problem is
// WriteData();
//System.exit(0);
}
public static void main(String[] args) {
nsUI();
}
}
**This is the Linked list file**
//************************ IntSLList.java **************************
// singly-linked list class to store integers
public class IntSLList {
protected IntSLLNode head, tail;
public static void createInst(){
new IntSLList().printAll();
}
public IntSLList() {
head = tail = null;
}
public boolean isEmpty() {
return head == null;
}
public void addToHead(String AN) {
head = new IntSLLNode(AN,head);
if (tail == null) // checks for empty list
tail = head;
}
public void addToTail(String AN, Double AB) {
if (!isEmpty()) {
tail.next = new IntSLLNode(AN,AB);
tail = tail.next;
}
else
head = tail = new IntSLLNode(AN,AB);
}
public String deleteFromHead() { // delete the head and return its info;
String AN = head.AccountNumber;
if (head == tail) // if only one node on the list;
head = tail = null;
else head = head.next;
return AN;
}
public String deleteFromTail() { // delete the tail and return its info;
String AN = tail.AccountNumber;
if (head == tail) // if only one node in the list;
head = tail = null;
else { // if more than one node in the list,
IntSLLNode tmp; // find the predecessor of tail;
for (tmp = head; tmp.next != tail; tmp = tmp.next);
tail = tmp; // the predecessor of tail becomes tail;
tail.next = null;
}
return AN;
}
public void printAll() {
for (IntSLLNode tmp = head; tmp != null; tmp = tmp.next)
System.out.print(tmp.AccountNumber + " " +tmp.AccountBalance+"");
}
public boolean isInList(String AN) {
IntSLLNode tmp;
for (tmp = head; tmp != null && tmp.AccountNumber != AN; tmp = tmp.next);
return tmp != null;
}
public void delete(String AN){ // delete the node with an element el;
if (!isEmpty())
if (head == tail && AN == head.AccountNumber) // if only one
head = tail = null; // node on the list;
else if (AN == head.AccountNumber) // if more than one node on the list;
head = head.next; // and el is in the head node;
else { // if more than one node in the list
IntSLLNode pred, tmp; // and el is in a non-head node;
for (pred = head, tmp = head.next;
tmp != null && tmp.AccountNumber != AN;
pred = pred.next, tmp = tmp.next);
if (tmp != null) { // if el was found;
pred.next = tmp.next;
if (tmp == tail) // if el is in the last node;
tail = pred;
}
}
}
}
Eclipse is yelling at me saying that I can't make a static reference to a non-static method, but how should I go about doing that... I read that I need to make an instance of the IntSLL class, and I tried that, but I still can't seem to get it to work... I think I'm doing it wrong.
PS, please don't grill me for the formatting of this post. Its the first time I've ever posted here, usually I can figure out my problems based on people having similar issues, and the awesome community that is here giving different ideas.
PPS, I know that I don't need the printAll method in the method of Exit(), I'm trying to figure out what I need to do to get this to work through my program step by step to implement the linked list rather than the linear search... Eventually the linear search will be replaced by the the implementation of the linked list.
Thanks everyone!