Hi everybody! I'm currently working on an assignment for school. I'm creating a linked list (a line at the liqure store to be exact) and I'm a little stuck. Part of the code:
public void ekspederKunde() {
System.out.println("Velkommen til polet! Vennligst vis gyldig legitimasjon.\n");
if (fremst == null) { // is there anyone in line?
System.out.println("Det er ingen i køen!");
} // end if
else if (fremst != null) { // if there is anyone in the line chech age
if (alder >= alderMinst) { // if age is high enough
System.out.println("Takk for besøket! Velkommen igjen!");
} // end if
else if (alder < alderMinst) { // if customer is to young
System.out.println("DU ER IKKE GAMMEL NOK! Løp avgårde før vi varsler politiet!");
} // end else if
denne = fremst.neste; // Is this correct for deleting/removing the first in line? In english: current = first.next
totaltKunder--; // counter to reduce total number of customers in line
} // end if
System.out.println();
} // end metode for ekspedring av kunder
Now, this above here is a method I created to handle the first customer in line. The first if is checking if anyone i acctually in the line (fremst = first) and if there isn't anyone, it writes a message. My problem is that if I've had anyone in line, this check isn't working! It kinda keeps adding negative amounts of people in line and treating these as customers.
I think one of two things might be the problem. Either my delete function (see comment in code) isn't working, or the program can't reach the right "alder" in the else if checks. (alder = age, btw)
Now, I'm totally new to coding linked lists so I have no idea where my problem is. Any help would be greatly appreaciated since I have a deadline for delivering this in two days.
Just tell me if more of the code is needed.