java - The method addElement is undefined for the type LinkedList -
i working on assignment , i'm trying add element linkedlist. first block of code given , should not changed. second block written according uml given professor , located in class.
import java.io.*; import java.util.linkedlist; public class assignment10 { public static void main(string[] args) { char input1; string inputinfo = new string(); int operation2; string line = new string(); //create linked list used in method. linkedlist list1 = new linkedlist(); try { // print out menu printmenu(); // create bufferedreader object read input keyboard inputstreamreader isr = new inputstreamreader (system.in); bufferedreader stdin = new bufferedreader (isr); { system.out.print("what action perform?\n"); line = stdin.readline().trim(); //read line input1 = line.charat(0); input1 = character.touppercase(input1); if (line.length() == 1) // check if user entered 1 character { switch (input1) { case 'a': //add string system.out.print("please enter string add:\n"); string str1 = stdin.readline().trim(); system.out.print("please enter index add:\n"); inputinfo = stdin.readline().trim(); int addindex = integer.parseint(inputinfo); list1.addelement(addindex, str1); break; public void addelement(int index, object element) { if(index < 0) { indexoutofboundsexception ex = new indexoutofboundsexception(); throw ex; } linkedlistiterator iterator = new linkedlistiterator(); for(int = 0; < index; i++) { if(iterator.hasnext()) // check if iterator has next value before iterator.next(); // moving next element else { nosuchelementexception exception = new nosuchelementexception(); throw exception; } } iterator.add(element); } // end of addelement here eclipse telling me: exception in thread "main" java.lang.error: unresolved compilation problem: method addelement(int, string) undefined type linkedlist.
again, not supposed change first block of code there must wrong addelement method. ideas? sorry isn't compilable, more of conceptual question, think.
i think problem confused.
on 1 hand, appear implementing method called
addelementon appears custom list implementation. (you don't show entire class ...)on other hand, appear trying call nonexistent
addelementon standardjava.util.linkedlistclass.
one of these things wrong. either have misunderstood supposed do, or lecturer has given test harness class (assignment10) incorrect. (yes lecturers make mistakes. human.)
i suggest ask lecturer or tutor clarification. (and please polite , deferential. there nothing more annoying lecturer student "in face" errors, imaginary ones.)
Comments
Post a Comment