java - Linked List steps -
i have project , don't know steps pierced
write java program store employee information in linked list, program should implement following functions:
- function
task - insert new employee
add new employee linked list , store employee's information ( id, name, address, department, salary) - update employee information
modify existing employee's information (change address , salary only). should ask employee id update his/her information - remove employee
remove employee using employee id linked list
the program should display list of functions, , ask user enter number of function he/she wants do, perform function required in previous table.
this did
import java.util.scanner; import java.util.linkedlist; import java.util.collections; import java.util.listiterator; public class linkedlistemployee { //------------start of employee class-------- private class employee { private string empnumber; private string name; private string department; private int emptest; private double salary; public employee() { empnumber = null; emptest= 0; name = null; department = null; salary = 0.0; } } //------------end of employee class-------- public static void main(string args[]) { linkedlist<employee> emptest = new linkedlist<employee>(); system.out.println("\nmenu\n1.add employee\n2.update"); scanner in = new scanner(system.in); int choice = in.nextint(); if (choice == 2) system.out.println("enter employee’s name"); string nm = in.nextline(); update(nm, emptest); } public static void update(string namepara, linkedlist<employee> emptest) { listiterator<employee> litr = emptest.listiterator(); employee tempemp; scanner in = new scanner(system.in); while (litr.hasnext()) { tempemp=litr.next(); if (tempemp.name.equals(namepara)) { system.out.println("enter new address"); string add = in.nextline(); system.out.println("enter new salary"); string sal = in.nextline(); //tempemp.empaddress = add; tempemp.salary = double.parsedouble(sal); break; } } } }
it work ?? or there more steps go !! referring question ?
please me know steps
based on comment in response error getting ("listiterator litr = emptest.listiterator(); cannot find symbol - class listlterator"):
the type listiterator
unknown, looking listiterator
, change
listiterator<integer> litr = emptest.listiterator();
to
listiterator<integer> litr = emptest.listiterator();
edit next error after then: "listiterator litr = emptest.listiterator(); cannot find symbol - variable emptest":
that list visible within scope of main method since it's declared in there. 1 possibility pass list along method call, change
public static void update(string name) {
to
public static void update(string name, linkedlist<employee> emptest) {
and pass missing list update method main method:
update(nm, emptest); //instead of update(nm);
alternatively, can widen scope of list , declare entire class, mentioned in comments @dude, should handled care, heightens retained state of object (or class in case) in question.
aside: types capitalized in java (employee should employee), whereas variables , methods start lower case (update() should update()). take @ this article, please.
Comments
Post a Comment