Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.91 KB | None | 0 0
  1. package app;
  2.  
  3. import java.util.*;
  4. import java.io.*;
  5.  
  6. public class dataStruct
  7. {
  8. int count = 0;
  9.  
  10. private int ClassLength;
  11. private int StuLength;
  12. private int Techlength;
  13.  
  14. LabTech head;
  15. LabTech tail;
  16. LabTech current;
  17. LabTech trail;
  18.  
  19. StudentWorker stuHead;
  20. StudentWorker stuTail;
  21. StudentWorker stuCurrent;
  22. StudentWorker stuTrail;
  23.  
  24. Class chead;
  25. Class ctail;
  26. Class cCurrent;
  27. Class cTrail;
  28.  
  29. boolean found;
  30.  
  31. int num = 0;
  32. int data = 0;
  33. String Data = " ";
  34.  
  35. Scanner in = new Scanner(System.in);
  36.  
  37. public dataStruct ()
  38. {
  39. StuLength = 0;
  40. ClassLength = 0;
  41. Techlength = 0;
  42.  
  43. head = null;
  44. tail = null;
  45. current = null;
  46. trail = null;
  47.  
  48. stuHead = null;
  49. stuTail = null;
  50. stuCurrent = null;
  51. stuTrail = null;
  52.  
  53. chead = null;
  54. ctail = null;
  55. cCurrent = null;
  56. cTrail = null;
  57.  
  58. found = false;
  59.  
  60. }
  61.  
  62. public void initializeTechList()
  63. {//intializes list
  64. head = null;
  65. Techlength = 0;
  66. }
  67.  
  68. public void initializeClassList()
  69. {//intializes list
  70. chead = null;
  71. ClassLength = 0;
  72. }
  73.  
  74. public void initializeStudentList()
  75. {//intializes list
  76. stuHead = null;
  77. StuLength = 0;
  78. }
  79.  
  80.  
  81. public boolean isClassEmpty()
  82. {//checks to see if the list is empty
  83. return (chead == null);
  84. }
  85.  
  86. public boolean isTechEmpty()
  87. {//checks to see if the list is empty
  88. return (head == null);
  89. }
  90.  
  91. public boolean isStuEmpty()
  92. {//checks to see if the list is empty
  93. return (head == null);
  94. }
  95.  
  96.  
  97. public void addClass(String n, String c, String lect, String d, String t, String l)
  98. {//adds node
  99. try
  100. {//attepts to find and open the file
  101. PrintWriter out = new PrintWriter("Final_project.dat");
  102. String start = "startclass";
  103. String end = "endclass";
  104. Class cl = new Class();
  105. //out.println stores data unto the file
  106.  
  107. cl.link = chead;
  108. out.println(start);
  109. cl.setName(n);
  110. out.println(n);
  111. cl.code = c;
  112. out.println(c);
  113. cl.setLecturer(lect);
  114. out.println(lect);
  115. cl.setday(d);
  116. out.println(d);
  117. cl.setTime(t);
  118. out.println(t);
  119. cl.setLab(l);
  120. out.println(l);
  121. out.println(end);
  122.  
  123. if (ctail == null)
  124. {
  125. ctail = cl;
  126. ClassLength++;
  127. }
  128. out.close();
  129. }
  130.  
  131. catch (FileNotFoundException e)
  132. {
  133. //if the file cannot be opened the error is handled...
  134. System.err.println("file not found...");
  135. }
  136.  
  137.  
  138. }
  139.  
  140. public void addLabTech(String lf, String ll,int lId, String llab, String lday, String lt,String lq)
  141. {//adds node
  142.  
  143. try
  144. {//attepts to find and open the file
  145. PrintWriter out = new PrintWriter("Final_project.dat");
  146. String start = "startlabtech";
  147. String end = "endlabtech";
  148. LabTech tech = new LabTech();
  149. //out.println stores data unto the file
  150. tech.link = head;
  151. out.println(start);
  152. tech.setf(lf);
  153. out.println(lf);
  154. tech.setl(ll);
  155. out.println(ll);
  156. tech.setId(lId);
  157. out.println(lId);
  158. tech.setlab(llab);
  159. out.println(llab);
  160. tech.setday(lday);
  161. out.println(lday);
  162. tech.settime(lt);
  163. out.println(lt);
  164. tech.setqual(lq);
  165. out.println(lq);
  166. out.println(end);
  167.  
  168. if (tail == null)
  169. {
  170. tail = tech;
  171. Techlength++;
  172. }
  173. out.close();
  174. }
  175. catch (FileNotFoundException e)
  176. {
  177. //if the file cannot be opened the error is handled...
  178. System.err.println("file not found...");
  179. }
  180.  
  181. }
  182.  
  183. public void addStudent(String sfn, String sln, int sId, String sl, String sd, String st, String m)
  184. {//adds node
  185. try
  186. {//attepts to find and open the file
  187. PrintWriter out = new PrintWriter("Final_project.dat");
  188. String start = "startstudent";
  189. String end = "endstudent";
  190. StudentWorker stu = new StudentWorker();
  191. //out.println stores data unto the file
  192. stu.link = stuHead;
  193. out.println(start);
  194. stu.setFname(sfn);
  195. out.println(sfn);
  196. stu.setLname(sln);
  197. out.println(sln);
  198. stu.stuID = sId;
  199. out.println(sId);
  200. stu.setLab(sl);
  201. out.println(sl);
  202. stu.setday(sd);
  203. out.println(sd);
  204. stu.setTime(st);
  205. out.println(st);
  206. stu.setmajor(m);
  207. out.println(m);
  208. out.println(end);
  209. if (stuTail == null)
  210. {
  211. stuTail = stu;
  212. StuLength++;
  213. }
  214. out.close();
  215. }
  216. catch (FileNotFoundException e)
  217. {
  218. //if the file cannot be opened the error is handled...
  219. System.err.println("file not found...");
  220. }
  221.  
  222. }
  223.  
  224.  
  225. public void deleteCLass(String Data)
  226. {//deletes Class from list
  227. Class cCurrent, cTrail;
  228. if (isClassEmpty())
  229. {//checks to see if list is empty
  230. System.err.println("CANNOT DELETE FROM AN EMPTY LIST!!!!");
  231. }
  232. else
  233. {
  234. if (chead.code.equalsIgnoreCase(Data))
  235. {//if the list isnt empty it checks to see if the node to be deleted is the head of the list
  236. chead = chead.link;
  237. System.out.println("\nSuccesfully deleted...");
  238. ClassLength--;
  239.  
  240. if (chead == null)
  241. {
  242. ctail = null;
  243. System.out.println("\nSuccesfully deleted...");
  244. ClassLength--;
  245. }
  246. else
  247. {//if the node is somewhere in the list it will find it and delete it
  248. cTrail = chead;
  249. cCurrent = chead.link;
  250. while (cCurrent != null && !found)
  251. {
  252. if (cCurrent.code.equalsIgnoreCase(Data))
  253. {
  254. found = true;
  255. System.out.println("\nSuccesfully deleted...");
  256. ClassLength--;
  257. }
  258. else
  259. {
  260. cTrail = cCurrent;
  261. cCurrent = cCurrent.link;
  262. }
  263. if (found)
  264. {
  265. cTrail.link =cCurrent.link;
  266. System.out.println("\nSuccesfully deleted...");
  267. ClassLength--;
  268. if (ctail == cCurrent)
  269. {
  270. ctail = cTrail;
  271. }
  272. else
  273. {
  274. System.err.println("\nSorry...the Item to be deleted isnt in the list....");
  275. }
  276. }
  277. }
  278. }
  279. }
  280. }
  281. }
  282.  
  283. public void deleteLab(int data)
  284. {//deletes Lab tech from list
  285. LabTech current, trail;
  286. if (isTechEmpty())
  287. {//if list isnt empty it will delete
  288. System.err.println("CANNOT DELETE FROM AN EMPTY LIST!!!!");
  289. }
  290. else
  291. {
  292. if (head.staffID == data)
  293. {//if the node to be deleted is the head of the list it will assign the head to the next in the list
  294. head = head.link;
  295. System.out.println("\nSuccesfully deleted...");
  296. Techlength--;
  297.  
  298. if (isTechEmpty())
  299. {
  300. tail = null;
  301. System.out.println("\nSuccesfully deleted...");
  302. Techlength--;
  303. }
  304. else
  305. {//if the node is somewhere in the list it will find it and delete it
  306. trail = head;
  307. current = head.link;
  308. while (current != null && !found)
  309. {
  310. if (current.staffID == data)
  311. {
  312. found = true;
  313. System.out.println("\nSuccesfully deleted...");
  314. Techlength--;
  315. }
  316. else
  317. {
  318. trail = current;
  319. current = current.link;
  320. }
  321. if (found)
  322. {
  323. trail.link =current.link;
  324. System.out.println("\nSuccesfully deleted...");
  325. Techlength--;
  326. if (tail == current)
  327. {
  328. tail = trail;
  329. }
  330. }
  331. else
  332. {
  333. System.err.println("\nSorry...The item to be deleted isnt in the list....");
  334. }
  335.  
  336. }
  337. }
  338. }
  339. }
  340. }
  341.  
  342. public void deleteStudent(int data)
  343. {//deletes student from lits
  344. StudentWorker stuCurrent, stuTrail;
  345.  
  346. if (isStuEmpty())
  347. {//if list isnt empty it will delete
  348. System.err.println("CANNOT DELETE FROM AN EMPTY LIST!!!!");
  349. }
  350. else
  351. {
  352. if (stuHead.stuID == data)
  353. {//if the node to be deleted is the head of the list it will assign the head to the next in the list
  354. stuHead = stuHead.link;
  355. System.out.println("\nSuccesfully deleted...");
  356. StuLength--;
  357.  
  358. if (isStuEmpty())
  359. {
  360. stuTail = null;
  361. System.out.println("\nSuccesfully deleted...");
  362. StuLength--;
  363. }
  364. else
  365. {//if the node is somewhere in the list it will find it and delete it
  366. stuTrail = stuHead;
  367. stuCurrent = stuHead.link;
  368. while (stuCurrent != null && !found)
  369. {
  370. if (stuHead.stuID == data)
  371. {
  372. found = true;
  373. System.out.println("\nSuccesfully deleted...");
  374. StuLength--;
  375. }
  376. else
  377. {
  378. stuTrail = stuCurrent;
  379. stuCurrent = stuCurrent.link;
  380. }
  381. if (found)
  382. {
  383. stuTrail.link =stuCurrent.link;
  384. System.out.println("\nSuccesfully deleted...");
  385. StuLength--;
  386. if (stuTail == stuCurrent)
  387. {
  388. stuTail = stuTrail;
  389. }
  390. else
  391. {
  392. System.err.println("\nSorry...the item to be deleted isnt in the list....");
  393. }
  394. }
  395.  
  396. }
  397. }
  398. }
  399. }
  400. }
  401.  
  402. public boolean searchClassList(String Data)
  403. {//searches Class by class Code
  404. try
  405. {
  406. Scanner inFile = new Scanner( new FileReader("Final_project.dat") );
  407. String info = " ";
  408. if (isClassEmpty())
  409. {
  410. System.err.println("\nThis list is empty...");
  411. }
  412. else
  413. {
  414. info = inFile.nextLine();
  415. if (inFile.hasNext())
  416. {
  417. if (info == Data)
  418. {
  419. found = true;
  420. System.out.println("\nClass Code Found : " + Data);
  421. }
  422. cCurrent = chead;
  423. while (cCurrent != null && !found)
  424. {
  425. if (cCurrent.code.equalsIgnoreCase(Data))
  426. {
  427. found = true;
  428. }
  429. else
  430. {
  431. cCurrent = cCurrent.link;
  432. if (found == true)
  433. {
  434. System.out.println("\nClass Code Found : " + Data);
  435. }
  436. else
  437. {
  438. System.err.println("\n" + Data + " not found...");
  439. }
  440. }
  441. }
  442. }
  443. else
  444. {
  445. System.err.println("\nEmpty file....");
  446. }
  447. }
  448. inFile.close();
  449. return found;
  450. }
  451. catch (FileNotFoundException e)
  452. {
  453. System.err.println("\nFile not found...");
  454. }
  455. return found;
  456. }
  457.  
  458. public boolean searchStudentList(int data)
  459. {//searches student by ID number
  460. try
  461. {
  462. Scanner inFile = new Scanner (new FileReader("Final_project.dat"));
  463. int ids = 0;
  464. if (isStuEmpty())
  465. {
  466. System.err.println("\nThis list is empty...");
  467. }
  468. else
  469. {
  470. ids = inFile.nextInt();
  471. if (inFile.hasNext())
  472. {
  473. if (ids == data)
  474. {
  475. found = true;
  476. System.out.println("\nStudent ID Found : " + data);
  477. }
  478. stuCurrent = stuHead;
  479. while (stuCurrent != null && !found)
  480. {
  481. if (stuCurrent.stuID == data)
  482. {
  483. found = true;
  484. }
  485. else
  486. {
  487. stuCurrent = stuCurrent.link;
  488. if (found == true)
  489. {
  490. System.out.println("\nStudent ID Found : " + data);
  491. }
  492. else
  493. {
  494. System.err.println("\n" + data + " not found...");
  495. }
  496. }
  497. }
  498. }
  499. }
  500. inFile.close();
  501. }
  502. catch (FileNotFoundException e)
  503. {
  504. System.err.println("\nFile not found....");
  505. }
  506.  
  507.  
  508. return found;
  509. }
  510.  
  511. public boolean searchTechList(int data)
  512. {//searches Lab tech by Staff ID number
  513. try
  514. {
  515. Scanner inFile = new Scanner (new FileReader("Final_project.dat"));
  516. int ids = 0;
  517. if (isTechEmpty())
  518. {
  519. System.err.println("\nThis list is empty...");
  520. }
  521. else
  522. {
  523. ids = inFile.nextInt();
  524. if (inFile.hasNext())
  525. {
  526. if (ids == data)
  527. {
  528. found = true;
  529. System.out.println("\nStudent ID Found : " + data);
  530. }
  531. current = head;
  532. while (current != null && !found)
  533. {
  534. if (current.staffID == data)
  535. {
  536. found = true;
  537. }
  538. else
  539. {
  540. current = current.link;
  541. if (found == true)
  542. {
  543. System.out.println("\nLab Tech ID Found : " + data);
  544. }
  545. else
  546. {
  547. System.err.println("\n" + data + " not found...");
  548. }
  549. }
  550. }
  551. }
  552. }
  553. inFile.close();
  554. }
  555. catch (FileNotFoundException e)
  556. {
  557. System.err.println("\nfile not found......");
  558. }
  559. return found;
  560. }
  561.  
  562. public void print()
  563. {
  564. System.out.println("\nClass List....");
  565. if (isClassEmpty())
  566. {
  567. System.err.println("\n*---CLASS LIST EMPTY---*");
  568. }
  569. else
  570. {
  571. cCurrent = chead;
  572. while (cCurrent!= null)
  573. {
  574. System.out.println("\n Class Code: " + cCurrent.code
  575. + "\nClass name: " + cCurrent.getName()
  576. + "\nClass Lecturer: " +cCurrent.getLecturer()
  577. + "\nClass Day(s): " +cCurrent.getDay()
  578. + "\nClass Time: " +cCurrent.getTime()
  579. +"\nClass Lab: " +cCurrent.getLab());
  580. cCurrent =cCurrent.link;
  581. }
  582. System.out.println("\nCLass List Length = " + ClassLength);
  583. }
  584.  
  585.  
  586. System.out.println("\n\nStudent List...");
  587. if (isStuEmpty())
  588. {
  589. System.err.println("\n*---STUDENT LIST EMPTY---*");
  590. }
  591. else
  592. {
  593. stuCurrent = stuHead;
  594. while (stuCurrent != null)
  595. {
  596.  
  597. System.out.println("\nStudent Name :" + stuCurrent.getFname() + " " + stuCurrent.getLname()
  598. + "\nStudent ID: " + stuCurrent.getID()
  599. + "\nStudent Major: " +stuCurrent.getM()
  600. + "\nAssingned Lab: " +stuCurrent.getLab()
  601. + "\nDay(s): " +stuCurrent.getday()
  602. + "\nTime: " +stuCurrent.getTime());
  603. stuCurrent = stuCurrent.link;
  604. }
  605. System.out.println("\nStudent Worker List Length = " + StuLength);
  606. }
  607.  
  608.  
  609. System.out.println("\n\nLab Techn List....");
  610. if (isTechEmpty())
  611. {
  612. System.err.println("\n*---LAB TECH LIST EMPTY---*");
  613. }
  614. else
  615. {
  616. current = head;
  617. while (current != null)
  618. {
  619. System.out.println("\nTechnician Name :" + current.getfname() + " " + current.getlname()
  620. + "\nStaff ID: " + current.getId()
  621. + "\nTechnician's Qualifications: " +current.getQualif()
  622. + "\nAssingned Lab: " +current.getlab()
  623. + "\nDay(s): " +current.getday()
  624. + "\nTime: " +current.gettime());
  625. current = current.link;
  626. }
  627. System.out.println("\n Lab Tech List Length = " + Techlength);
  628. }
  629. }
  630.  
  631. public void labSchedules()
  632. {
  633. try
  634. {
  635. Scanner infile = new Scanner ( new FileReader("Final_project.dat"));
  636. String Data = " ";
  637. int info = 0;
  638. if (!infile.hasNext())
  639. {
  640. System.err.println("\nEmpty file...");
  641. }
  642. else// reads file and inputs data into linked list
  643. {
  644. Data = infile.nextLine(); // reads data from the file
  645. do //starts do while loop in file to read the entire file
  646. {
  647. if (Data == "startclass")
  648. { // if any data in the file contains startclass the program enters a do - while loop
  649.  
  650. while (infile.hasNextLine() && Data != "endclass")// starts while loop to read the file until "endclass" is found
  651. {
  652. if (Data == cCurrent.getCode())
  653. {
  654. cCurrent.setCode(Data);
  655. }
  656. if (Data == cCurrent.getName())
  657. {
  658. cCurrent.setName(Data);
  659. }
  660. if (Data == cCurrent.getLecturer())
  661. {
  662. cCurrent.setLecturer(Data);
  663. }
  664. if (Data == cCurrent.getTime())
  665. {
  666. cCurrent.setTime(Data);
  667. }
  668. if (Data == cCurrent.getDay())
  669. {
  670. cCurrent.setday(Data);
  671. }
  672. if (Data == cCurrent.getLab())
  673. {
  674. cCurrent.setLab(Data);
  675. }
  676. }
  677. }
  678. else if (Data == "startstudent")
  679. {
  680. while (infile.hasNextLine() && Data != "endstudent")// starts while loop to read the file until "endstudent" is found
  681. {
  682. info = infile.nextInt();//reads intergers from the file
  683. if (info == stuCurrent.getID())
  684. {
  685. stuCurrent.setID(info);
  686. }
  687. if (Data == stuCurrent.getFname())
  688. {
  689. stuCurrent.setFname(Data);
  690. }
  691. if (Data == stuCurrent.getLname())
  692. {
  693. stuCurrent.setLname(Data);
  694. }
  695. if (Data == stuCurrent.getM())
  696. {
  697. stuCurrent.setmajor(Data);
  698. }
  699. if (Data == stuCurrent.getTime())
  700. {
  701. stuCurrent.setTime(Data);
  702. }
  703. if (Data == stuCurrent.getday())
  704. {
  705. stuCurrent.setday(Data);
  706. }
  707. if (Data == stuCurrent.getLab())
  708. {
  709. stuCurrent.setLab(Data);
  710. }
  711. }
  712. }
  713. else if (Data == "startlabtech")
  714. {
  715. while (infile.hasNextLine() && Data != "endlabtech")// starts while loop to read the file until "endlabtech" is found
  716. {
  717. info = infile.nextInt();//reads intergers from the file
  718. if (info == current.getId())
  719. {
  720. current.setId(info);
  721. }
  722. if (Data == current.getfname())
  723. {
  724. current.setf(Data);
  725. }
  726. if (Data == current.getlname())
  727. {
  728. current.setl(Data);
  729. }
  730. if (Data == current.getQualif())
  731. {
  732. current.setqual(Data);
  733. }
  734. if (Data == current.gettime())
  735. {
  736. current.settime(Data);
  737. }
  738. if (Data == current.getday())
  739. {
  740. current.setday(Data);
  741. }
  742. if (Data == current.getlab())
  743. {
  744. current.setlab(Data);
  745. }
  746. }
  747. }
  748. }
  749. while (infile.hasNext());
  750.  
  751.  
  752. if (isClassEmpty() || isStuEmpty() || isTechEmpty())
  753. {
  754. System.err.println("\nERROR!! "
  755. + "\nIn order to view the Lab Schedule for Computer Room (CR) You MUST add ALL 3 fields as an entry:"
  756. +"\n\t1.A Lab Tech \n\t2. Student worker \n\t3. Class");
  757. }
  758. else
  759. {
  760. System.out.println("\n------------------------------COMPUTER ROOM (CR)-------------------------------------");
  761. while (cCurrent.getLab() == "CR" || current.getlab() == "CR" || stuCurrent.getLab() == "CR")
  762. {
  763. if (cCurrent.getDay() == "Monday & Wendnesday" || current.getday() == "Monday" || stuCurrent.getday() == "Monday" || current.getday() == "Everyday" || stuCurrent.getday() == "Everday")
  764. {
  765. System.out.println("\nMonday Class: " + cCurrent.code + "-" + cCurrent.getLecturer()
  766. + "\n\tLab Tech: " + current.getfname() + " " +current.getlname()
  767. + "\n\t\tStudent Worker: " +stuCurrent. getFname()+ " " +stuCurrent.getLname());
  768. System.out.println("\n\t\t\t\t Time: " + cCurrent.getTime());
  769. }
  770. else if (cCurrent.getDay() == "Tuesday & Thursday" || current.getday() == "Tuesday" || stuCurrent.getday() == "Tuesday" || current.getday() == "Everyday" || stuCurrent.getday() == "Everday")
  771. {
  772. System.out.println("\nTuesday Class: " + cCurrent.code + "-" + cCurrent.getLecturer()
  773. + "\n\tLab Tech: " + current.getfname() + " " +current.getlname()
  774. + "\n\t\tStudent Worker: " +stuCurrent. getFname()+ " " +stuCurrent.getLname());
  775. System.out.println("\n\t\t\t\t Time: " + cCurrent.getTime());
  776. }
  777. else if (cCurrent.getDay() == "Monday & Wednesday" || current.getday() == "Wednesday" || stuCurrent.getday() == "Wednesday" || current.getday() == "Everyday" || stuCurrent.getday() == "Everday")
  778. {
  779. System.out.println("\nWednesday Class: " + cCurrent.code + "-" + cCurrent.getLecturer()
  780. + "\n\tLab Tech: " + current.getfname() + " " +current.getlname()
  781. + "\n\t\tStudent Worker: " +stuCurrent. getFname()+ " " +stuCurrent.getLname());
  782. System.out.println("\n\t\t\t\t Time: " + cCurrent.getTime());
  783. }
  784. else if (cCurrent.getDay() == "Tuesday & Thursday" || current.getday() == "Thursday" || stuCurrent.getday() == "Thursday" || current.getday() == "Everyday" || stuCurrent.getday() == "Everday")
  785. {
  786. System.out.println("\nThursday Class: " + cCurrent.code + "-" + cCurrent.getLecturer()
  787. + "\n\tLab Tech: " + current.getfname() + " " +current.getlname()
  788. + "\n\t\tStudent Worker: " +stuCurrent. getFname()+ " " +stuCurrent.getLname());
  789. System.out.println("\n\t\t\t\t Time: " + cCurrent.getTime());
  790. }
  791. else
  792. {
  793. System.out.println("\n-------------------------------------LABS CLOSED-----------------------------------------");
  794. }
  795. }
  796. }
  797. }
  798. infile.close();
  799. }
  800. catch (FileNotFoundException e)
  801. {
  802. System.err.println("\nUnable to open file");
  803. }
  804.  
  805.  
  806. }
  807.  
  808. public void updateClass(String Data, String n, String c, String lect, String d, String t, String l)
  809. {//update lab adds data then deletes the selected node from the list.
  810. Class cCurrent, ctrail;
  811.  
  812. if (isClassEmpty())
  813. {//checks to see if the list is empty
  814. System.err.println("\nCannot Update an Empty list....");
  815. }
  816. else
  817. {
  818. if (chead.code.equalsIgnoreCase(Data))
  819. {//if the list isnt empty, it chects to see if the entered data is equal to head
  820. addClass(n, c, lect, d, t, l);
  821. chead = chead.link;
  822. System.out.println("Succesfully Updated...");
  823. }
  824. else
  825. {// if the data is in the list but isnt the 1st node in the list, it goes through the list to look fot the data
  826. addClass(n, c, lect, d, t, l);
  827. ctrail = chead;
  828. cCurrent = chead.link;
  829. while (cCurrent != null && !found)
  830. {
  831. if (cCurrent.code.equalsIgnoreCase(Data))
  832. {
  833. found = true;
  834. System.out.println("\nSuccesFully Updated...");
  835. ClassLength--;
  836. }
  837. else
  838. {
  839. ctrail = cCurrent;
  840. cCurrent = cCurrent.link;
  841. }
  842.  
  843. if (found)
  844. {
  845. ctrail.link = cCurrent.link;
  846. ClassLength--;
  847.  
  848. if (ctail == cCurrent)
  849. {
  850. ctail = ctrail;
  851. }
  852. }
  853. }
  854. }
  855.  
  856. }
  857. }
  858.  
  859. public void updateStudent(int data, String sfn, String sln, int sId, String sl, String sd, String st, String m)
  860. {//update lab adds data then deletes the selected node from the list.
  861. StudentWorker stuCurrent, stuTrail;
  862.  
  863. if (isStuEmpty())
  864. {//checks to see if the list is empty
  865. System.err.println("\nCannot Update an Empty list....");
  866. }
  867. else
  868. {
  869. if (stuHead.stuID == data)
  870. {//if the list isnt empty, it chects to see if the entered data is equal to head
  871. addStudent(sfn, sln, sId, sl, sd, st, m);
  872. stuHead = stuHead.link;
  873. System.out.println("Succesfully Updated...");
  874. }
  875. else
  876. {// if the data is in the list but isnt the 1st node in the list, it goes through the list to look fot the data
  877. addStudent(sfn, sln, sId, sl, sd, st, m);
  878. stuTrail = stuHead;
  879. stuCurrent = stuHead.link;
  880. while (cCurrent != null && !found)
  881. {
  882. if (stuCurrent.stuID == data)
  883. {
  884. found = true;
  885. System.out.println("\nSuccesFully Updated...");
  886. StuLength--;
  887. }
  888. else
  889. {
  890. stuTrail = stuCurrent;
  891. stuCurrent = stuCurrent.link;
  892. }
  893.  
  894. if (found)
  895. {
  896. stuTrail.link = stuCurrent.link;
  897. StuLength--;
  898.  
  899. if (stuTail == stuCurrent)
  900. {
  901. stuTail = stuTrail;
  902. }
  903. }
  904. }
  905. }
  906.  
  907. }
  908.  
  909. }
  910.  
  911. public void updateLab(int data, String lf, String ll,int lId, String llab, String lday, String lt,String lq)
  912. {//update lab adds data then deletes the selected node from the list.
  913. LabTech current, trail;
  914. if (isTechEmpty())
  915. {//checks to see if the list is empty
  916. System.err.println("\nCannot Update an Empty list....");
  917. }
  918. else
  919. {
  920. if (head.staffID == data)
  921. {//if the list isnt empty, it chects to see if the entered data is equal to head
  922. addLabTech(lf, ll, lId, llab, lday, lt, lq);
  923. head = head.link;
  924. System.out.println("Succesfully Updated...");
  925. Techlength--;
  926. }
  927. else
  928. {// if the data is in the list but isnt the 1st node in the list, it goes through the list to look fot the data
  929. addLabTech(lf, ll, lId, llab, lday, lt, lq);
  930. trail = head;
  931. current = head.link;
  932. while (current != null && !found)
  933. {
  934. if (current.staffID == data)
  935. {
  936. found = true;
  937. System.out.println("\nSuccesFully Updated...");
  938. Techlength--;
  939. }
  940. else
  941. {
  942. trail = current;
  943. current = current.link;
  944. }
  945.  
  946. if (found)
  947. {
  948. trail.link = current.link;
  949. Techlength--;
  950.  
  951. if (tail == current)
  952. {
  953. tail = trail;
  954. }
  955. }
  956. }
  957. }
  958.  
  959. }
  960. }
  961. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement