Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package app;
- import java.util.*;
- import java.io.*;
- public class dataStruct
- {
- int count = 0;
- private int ClassLength;
- private int StuLength;
- private int Techlength;
- LabTech head;
- LabTech tail;
- LabTech current;
- LabTech trail;
- StudentWorker stuHead;
- StudentWorker stuTail;
- StudentWorker stuCurrent;
- StudentWorker stuTrail;
- Class chead;
- Class ctail;
- Class cCurrent;
- Class cTrail;
- boolean found;
- int num = 0;
- int data = 0;
- String Data = " ";
- Scanner in = new Scanner(System.in);
- public dataStruct ()
- {
- StuLength = 0;
- ClassLength = 0;
- Techlength = 0;
- head = null;
- tail = null;
- current = null;
- trail = null;
- stuHead = null;
- stuTail = null;
- stuCurrent = null;
- stuTrail = null;
- chead = null;
- ctail = null;
- cCurrent = null;
- cTrail = null;
- found = false;
- }
- public void initializeTechList()
- {//intializes list
- head = null;
- Techlength = 0;
- }
- public void initializeClassList()
- {//intializes list
- chead = null;
- ClassLength = 0;
- }
- public void initializeStudentList()
- {//intializes list
- stuHead = null;
- StuLength = 0;
- }
- public boolean isClassEmpty()
- {//checks to see if the list is empty
- return (chead == null);
- }
- public boolean isTechEmpty()
- {//checks to see if the list is empty
- return (head == null);
- }
- public boolean isStuEmpty()
- {//checks to see if the list is empty
- return (head == null);
- }
- public void addClass(String n, String c, String lect, String d, String t, String l)
- {//adds node
- try
- {//attepts to find and open the file
- PrintWriter out = new PrintWriter("Final_project.dat");
- String start = "startclass";
- String end = "endclass";
- Class cl = new Class();
- //out.println stores data unto the file
- cl.link = chead;
- out.println(start);
- cl.setName(n);
- out.println(n);
- cl.code = c;
- out.println(c);
- cl.setLecturer(lect);
- out.println(lect);
- cl.setday(d);
- out.println(d);
- cl.setTime(t);
- out.println(t);
- cl.setLab(l);
- out.println(l);
- out.println(end);
- if (ctail == null)
- {
- ctail = cl;
- ClassLength++;
- }
- out.close();
- }
- catch (FileNotFoundException e)
- {
- //if the file cannot be opened the error is handled...
- System.err.println("file not found...");
- }
- }
- public void addLabTech(String lf, String ll,int lId, String llab, String lday, String lt,String lq)
- {//adds node
- try
- {//attepts to find and open the file
- PrintWriter out = new PrintWriter("Final_project.dat");
- String start = "startlabtech";
- String end = "endlabtech";
- LabTech tech = new LabTech();
- //out.println stores data unto the file
- tech.link = head;
- out.println(start);
- tech.setf(lf);
- out.println(lf);
- tech.setl(ll);
- out.println(ll);
- tech.setId(lId);
- out.println(lId);
- tech.setlab(llab);
- out.println(llab);
- tech.setday(lday);
- out.println(lday);
- tech.settime(lt);
- out.println(lt);
- tech.setqual(lq);
- out.println(lq);
- out.println(end);
- if (tail == null)
- {
- tail = tech;
- Techlength++;
- }
- out.close();
- }
- catch (FileNotFoundException e)
- {
- //if the file cannot be opened the error is handled...
- System.err.println("file not found...");
- }
- }
- public void addStudent(String sfn, String sln, int sId, String sl, String sd, String st, String m)
- {//adds node
- try
- {//attepts to find and open the file
- PrintWriter out = new PrintWriter("Final_project.dat");
- String start = "startstudent";
- String end = "endstudent";
- StudentWorker stu = new StudentWorker();
- //out.println stores data unto the file
- stu.link = stuHead;
- out.println(start);
- stu.setFname(sfn);
- out.println(sfn);
- stu.setLname(sln);
- out.println(sln);
- stu.stuID = sId;
- out.println(sId);
- stu.setLab(sl);
- out.println(sl);
- stu.setday(sd);
- out.println(sd);
- stu.setTime(st);
- out.println(st);
- stu.setmajor(m);
- out.println(m);
- out.println(end);
- if (stuTail == null)
- {
- stuTail = stu;
- StuLength++;
- }
- out.close();
- }
- catch (FileNotFoundException e)
- {
- //if the file cannot be opened the error is handled...
- System.err.println("file not found...");
- }
- }
- public void deleteCLass(String Data)
- {//deletes Class from list
- Class cCurrent, cTrail;
- if (isClassEmpty())
- {//checks to see if list is empty
- System.err.println("CANNOT DELETE FROM AN EMPTY LIST!!!!");
- }
- else
- {
- if (chead.code.equalsIgnoreCase(Data))
- {//if the list isnt empty it checks to see if the node to be deleted is the head of the list
- chead = chead.link;
- System.out.println("\nSuccesfully deleted...");
- ClassLength--;
- if (chead == null)
- {
- ctail = null;
- System.out.println("\nSuccesfully deleted...");
- ClassLength--;
- }
- else
- {//if the node is somewhere in the list it will find it and delete it
- cTrail = chead;
- cCurrent = chead.link;
- while (cCurrent != null && !found)
- {
- if (cCurrent.code.equalsIgnoreCase(Data))
- {
- found = true;
- System.out.println("\nSuccesfully deleted...");
- ClassLength--;
- }
- else
- {
- cTrail = cCurrent;
- cCurrent = cCurrent.link;
- }
- if (found)
- {
- cTrail.link =cCurrent.link;
- System.out.println("\nSuccesfully deleted...");
- ClassLength--;
- if (ctail == cCurrent)
- {
- ctail = cTrail;
- }
- else
- {
- System.err.println("\nSorry...the Item to be deleted isnt in the list....");
- }
- }
- }
- }
- }
- }
- }
- public void deleteLab(int data)
- {//deletes Lab tech from list
- LabTech current, trail;
- if (isTechEmpty())
- {//if list isnt empty it will delete
- System.err.println("CANNOT DELETE FROM AN EMPTY LIST!!!!");
- }
- else
- {
- if (head.staffID == data)
- {//if the node to be deleted is the head of the list it will assign the head to the next in the list
- head = head.link;
- System.out.println("\nSuccesfully deleted...");
- Techlength--;
- if (isTechEmpty())
- {
- tail = null;
- System.out.println("\nSuccesfully deleted...");
- Techlength--;
- }
- else
- {//if the node is somewhere in the list it will find it and delete it
- trail = head;
- current = head.link;
- while (current != null && !found)
- {
- if (current.staffID == data)
- {
- found = true;
- System.out.println("\nSuccesfully deleted...");
- Techlength--;
- }
- else
- {
- trail = current;
- current = current.link;
- }
- if (found)
- {
- trail.link =current.link;
- System.out.println("\nSuccesfully deleted...");
- Techlength--;
- if (tail == current)
- {
- tail = trail;
- }
- }
- else
- {
- System.err.println("\nSorry...The item to be deleted isnt in the list....");
- }
- }
- }
- }
- }
- }
- public void deleteStudent(int data)
- {//deletes student from lits
- StudentWorker stuCurrent, stuTrail;
- if (isStuEmpty())
- {//if list isnt empty it will delete
- System.err.println("CANNOT DELETE FROM AN EMPTY LIST!!!!");
- }
- else
- {
- if (stuHead.stuID == data)
- {//if the node to be deleted is the head of the list it will assign the head to the next in the list
- stuHead = stuHead.link;
- System.out.println("\nSuccesfully deleted...");
- StuLength--;
- if (isStuEmpty())
- {
- stuTail = null;
- System.out.println("\nSuccesfully deleted...");
- StuLength--;
- }
- else
- {//if the node is somewhere in the list it will find it and delete it
- stuTrail = stuHead;
- stuCurrent = stuHead.link;
- while (stuCurrent != null && !found)
- {
- if (stuHead.stuID == data)
- {
- found = true;
- System.out.println("\nSuccesfully deleted...");
- StuLength--;
- }
- else
- {
- stuTrail = stuCurrent;
- stuCurrent = stuCurrent.link;
- }
- if (found)
- {
- stuTrail.link =stuCurrent.link;
- System.out.println("\nSuccesfully deleted...");
- StuLength--;
- if (stuTail == stuCurrent)
- {
- stuTail = stuTrail;
- }
- else
- {
- System.err.println("\nSorry...the item to be deleted isnt in the list....");
- }
- }
- }
- }
- }
- }
- }
- public boolean searchClassList(String Data)
- {//searches Class by class Code
- try
- {
- Scanner inFile = new Scanner( new FileReader("Final_project.dat") );
- String info = " ";
- if (isClassEmpty())
- {
- System.err.println("\nThis list is empty...");
- }
- else
- {
- info = inFile.nextLine();
- if (inFile.hasNext())
- {
- if (info == Data)
- {
- found = true;
- System.out.println("\nClass Code Found : " + Data);
- }
- cCurrent = chead;
- while (cCurrent != null && !found)
- {
- if (cCurrent.code.equalsIgnoreCase(Data))
- {
- found = true;
- }
- else
- {
- cCurrent = cCurrent.link;
- if (found == true)
- {
- System.out.println("\nClass Code Found : " + Data);
- }
- else
- {
- System.err.println("\n" + Data + " not found...");
- }
- }
- }
- }
- else
- {
- System.err.println("\nEmpty file....");
- }
- }
- inFile.close();
- return found;
- }
- catch (FileNotFoundException e)
- {
- System.err.println("\nFile not found...");
- }
- return found;
- }
- public boolean searchStudentList(int data)
- {//searches student by ID number
- try
- {
- Scanner inFile = new Scanner (new FileReader("Final_project.dat"));
- int ids = 0;
- if (isStuEmpty())
- {
- System.err.println("\nThis list is empty...");
- }
- else
- {
- ids = inFile.nextInt();
- if (inFile.hasNext())
- {
- if (ids == data)
- {
- found = true;
- System.out.println("\nStudent ID Found : " + data);
- }
- stuCurrent = stuHead;
- while (stuCurrent != null && !found)
- {
- if (stuCurrent.stuID == data)
- {
- found = true;
- }
- else
- {
- stuCurrent = stuCurrent.link;
- if (found == true)
- {
- System.out.println("\nStudent ID Found : " + data);
- }
- else
- {
- System.err.println("\n" + data + " not found...");
- }
- }
- }
- }
- }
- inFile.close();
- }
- catch (FileNotFoundException e)
- {
- System.err.println("\nFile not found....");
- }
- return found;
- }
- public boolean searchTechList(int data)
- {//searches Lab tech by Staff ID number
- try
- {
- Scanner inFile = new Scanner (new FileReader("Final_project.dat"));
- int ids = 0;
- if (isTechEmpty())
- {
- System.err.println("\nThis list is empty...");
- }
- else
- {
- ids = inFile.nextInt();
- if (inFile.hasNext())
- {
- if (ids == data)
- {
- found = true;
- System.out.println("\nStudent ID Found : " + data);
- }
- current = head;
- while (current != null && !found)
- {
- if (current.staffID == data)
- {
- found = true;
- }
- else
- {
- current = current.link;
- if (found == true)
- {
- System.out.println("\nLab Tech ID Found : " + data);
- }
- else
- {
- System.err.println("\n" + data + " not found...");
- }
- }
- }
- }
- }
- inFile.close();
- }
- catch (FileNotFoundException e)
- {
- System.err.println("\nfile not found......");
- }
- return found;
- }
- public void print()
- {
- System.out.println("\nClass List....");
- if (isClassEmpty())
- {
- System.err.println("\n*---CLASS LIST EMPTY---*");
- }
- else
- {
- cCurrent = chead;
- while (cCurrent!= null)
- {
- System.out.println("\n Class Code: " + cCurrent.code
- + "\nClass name: " + cCurrent.getName()
- + "\nClass Lecturer: " +cCurrent.getLecturer()
- + "\nClass Day(s): " +cCurrent.getDay()
- + "\nClass Time: " +cCurrent.getTime()
- +"\nClass Lab: " +cCurrent.getLab());
- cCurrent =cCurrent.link;
- }
- System.out.println("\nCLass List Length = " + ClassLength);
- }
- System.out.println("\n\nStudent List...");
- if (isStuEmpty())
- {
- System.err.println("\n*---STUDENT LIST EMPTY---*");
- }
- else
- {
- stuCurrent = stuHead;
- while (stuCurrent != null)
- {
- System.out.println("\nStudent Name :" + stuCurrent.getFname() + " " + stuCurrent.getLname()
- + "\nStudent ID: " + stuCurrent.getID()
- + "\nStudent Major: " +stuCurrent.getM()
- + "\nAssingned Lab: " +stuCurrent.getLab()
- + "\nDay(s): " +stuCurrent.getday()
- + "\nTime: " +stuCurrent.getTime());
- stuCurrent = stuCurrent.link;
- }
- System.out.println("\nStudent Worker List Length = " + StuLength);
- }
- System.out.println("\n\nLab Techn List....");
- if (isTechEmpty())
- {
- System.err.println("\n*---LAB TECH LIST EMPTY---*");
- }
- else
- {
- current = head;
- while (current != null)
- {
- System.out.println("\nTechnician Name :" + current.getfname() + " " + current.getlname()
- + "\nStaff ID: " + current.getId()
- + "\nTechnician's Qualifications: " +current.getQualif()
- + "\nAssingned Lab: " +current.getlab()
- + "\nDay(s): " +current.getday()
- + "\nTime: " +current.gettime());
- current = current.link;
- }
- System.out.println("\n Lab Tech List Length = " + Techlength);
- }
- }
- public void labSchedules()
- {
- try
- {
- Scanner infile = new Scanner ( new FileReader("Final_project.dat"));
- String Data = " ";
- int info = 0;
- if (!infile.hasNext())
- {
- System.err.println("\nEmpty file...");
- }
- else// reads file and inputs data into linked list
- {
- Data = infile.nextLine(); // reads data from the file
- do //starts do while loop in file to read the entire file
- {
- if (Data == "startclass")
- { // if any data in the file contains startclass the program enters a do - while loop
- while (infile.hasNextLine() && Data != "endclass")// starts while loop to read the file until "endclass" is found
- {
- if (Data == cCurrent.getCode())
- {
- cCurrent.setCode(Data);
- }
- if (Data == cCurrent.getName())
- {
- cCurrent.setName(Data);
- }
- if (Data == cCurrent.getLecturer())
- {
- cCurrent.setLecturer(Data);
- }
- if (Data == cCurrent.getTime())
- {
- cCurrent.setTime(Data);
- }
- if (Data == cCurrent.getDay())
- {
- cCurrent.setday(Data);
- }
- if (Data == cCurrent.getLab())
- {
- cCurrent.setLab(Data);
- }
- }
- }
- else if (Data == "startstudent")
- {
- while (infile.hasNextLine() && Data != "endstudent")// starts while loop to read the file until "endstudent" is found
- {
- info = infile.nextInt();//reads intergers from the file
- if (info == stuCurrent.getID())
- {
- stuCurrent.setID(info);
- }
- if (Data == stuCurrent.getFname())
- {
- stuCurrent.setFname(Data);
- }
- if (Data == stuCurrent.getLname())
- {
- stuCurrent.setLname(Data);
- }
- if (Data == stuCurrent.getM())
- {
- stuCurrent.setmajor(Data);
- }
- if (Data == stuCurrent.getTime())
- {
- stuCurrent.setTime(Data);
- }
- if (Data == stuCurrent.getday())
- {
- stuCurrent.setday(Data);
- }
- if (Data == stuCurrent.getLab())
- {
- stuCurrent.setLab(Data);
- }
- }
- }
- else if (Data == "startlabtech")
- {
- while (infile.hasNextLine() && Data != "endlabtech")// starts while loop to read the file until "endlabtech" is found
- {
- info = infile.nextInt();//reads intergers from the file
- if (info == current.getId())
- {
- current.setId(info);
- }
- if (Data == current.getfname())
- {
- current.setf(Data);
- }
- if (Data == current.getlname())
- {
- current.setl(Data);
- }
- if (Data == current.getQualif())
- {
- current.setqual(Data);
- }
- if (Data == current.gettime())
- {
- current.settime(Data);
- }
- if (Data == current.getday())
- {
- current.setday(Data);
- }
- if (Data == current.getlab())
- {
- current.setlab(Data);
- }
- }
- }
- }
- while (infile.hasNext());
- if (isClassEmpty() || isStuEmpty() || isTechEmpty())
- {
- System.err.println("\nERROR!! "
- + "\nIn order to view the Lab Schedule for Computer Room (CR) You MUST add ALL 3 fields as an entry:"
- +"\n\t1.A Lab Tech \n\t2. Student worker \n\t3. Class");
- }
- else
- {
- System.out.println("\n------------------------------COMPUTER ROOM (CR)-------------------------------------");
- while (cCurrent.getLab() == "CR" || current.getlab() == "CR" || stuCurrent.getLab() == "CR")
- {
- if (cCurrent.getDay() == "Monday & Wendnesday" || current.getday() == "Monday" || stuCurrent.getday() == "Monday" || current.getday() == "Everyday" || stuCurrent.getday() == "Everday")
- {
- System.out.println("\nMonday Class: " + cCurrent.code + "-" + cCurrent.getLecturer()
- + "\n\tLab Tech: " + current.getfname() + " " +current.getlname()
- + "\n\t\tStudent Worker: " +stuCurrent. getFname()+ " " +stuCurrent.getLname());
- System.out.println("\n\t\t\t\t Time: " + cCurrent.getTime());
- }
- else if (cCurrent.getDay() == "Tuesday & Thursday" || current.getday() == "Tuesday" || stuCurrent.getday() == "Tuesday" || current.getday() == "Everyday" || stuCurrent.getday() == "Everday")
- {
- System.out.println("\nTuesday Class: " + cCurrent.code + "-" + cCurrent.getLecturer()
- + "\n\tLab Tech: " + current.getfname() + " " +current.getlname()
- + "\n\t\tStudent Worker: " +stuCurrent. getFname()+ " " +stuCurrent.getLname());
- System.out.println("\n\t\t\t\t Time: " + cCurrent.getTime());
- }
- else if (cCurrent.getDay() == "Monday & Wednesday" || current.getday() == "Wednesday" || stuCurrent.getday() == "Wednesday" || current.getday() == "Everyday" || stuCurrent.getday() == "Everday")
- {
- System.out.println("\nWednesday Class: " + cCurrent.code + "-" + cCurrent.getLecturer()
- + "\n\tLab Tech: " + current.getfname() + " " +current.getlname()
- + "\n\t\tStudent Worker: " +stuCurrent. getFname()+ " " +stuCurrent.getLname());
- System.out.println("\n\t\t\t\t Time: " + cCurrent.getTime());
- }
- else if (cCurrent.getDay() == "Tuesday & Thursday" || current.getday() == "Thursday" || stuCurrent.getday() == "Thursday" || current.getday() == "Everyday" || stuCurrent.getday() == "Everday")
- {
- System.out.println("\nThursday Class: " + cCurrent.code + "-" + cCurrent.getLecturer()
- + "\n\tLab Tech: " + current.getfname() + " " +current.getlname()
- + "\n\t\tStudent Worker: " +stuCurrent. getFname()+ " " +stuCurrent.getLname());
- System.out.println("\n\t\t\t\t Time: " + cCurrent.getTime());
- }
- else
- {
- System.out.println("\n-------------------------------------LABS CLOSED-----------------------------------------");
- }
- }
- }
- }
- infile.close();
- }
- catch (FileNotFoundException e)
- {
- System.err.println("\nUnable to open file");
- }
- }
- public void updateClass(String Data, String n, String c, String lect, String d, String t, String l)
- {//update lab adds data then deletes the selected node from the list.
- Class cCurrent, ctrail;
- if (isClassEmpty())
- {//checks to see if the list is empty
- System.err.println("\nCannot Update an Empty list....");
- }
- else
- {
- if (chead.code.equalsIgnoreCase(Data))
- {//if the list isnt empty, it chects to see if the entered data is equal to head
- addClass(n, c, lect, d, t, l);
- chead = chead.link;
- System.out.println("Succesfully Updated...");
- }
- else
- {// 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
- addClass(n, c, lect, d, t, l);
- ctrail = chead;
- cCurrent = chead.link;
- while (cCurrent != null && !found)
- {
- if (cCurrent.code.equalsIgnoreCase(Data))
- {
- found = true;
- System.out.println("\nSuccesFully Updated...");
- ClassLength--;
- }
- else
- {
- ctrail = cCurrent;
- cCurrent = cCurrent.link;
- }
- if (found)
- {
- ctrail.link = cCurrent.link;
- ClassLength--;
- if (ctail == cCurrent)
- {
- ctail = ctrail;
- }
- }
- }
- }
- }
- }
- public void updateStudent(int data, String sfn, String sln, int sId, String sl, String sd, String st, String m)
- {//update lab adds data then deletes the selected node from the list.
- StudentWorker stuCurrent, stuTrail;
- if (isStuEmpty())
- {//checks to see if the list is empty
- System.err.println("\nCannot Update an Empty list....");
- }
- else
- {
- if (stuHead.stuID == data)
- {//if the list isnt empty, it chects to see if the entered data is equal to head
- addStudent(sfn, sln, sId, sl, sd, st, m);
- stuHead = stuHead.link;
- System.out.println("Succesfully Updated...");
- }
- else
- {// 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
- addStudent(sfn, sln, sId, sl, sd, st, m);
- stuTrail = stuHead;
- stuCurrent = stuHead.link;
- while (cCurrent != null && !found)
- {
- if (stuCurrent.stuID == data)
- {
- found = true;
- System.out.println("\nSuccesFully Updated...");
- StuLength--;
- }
- else
- {
- stuTrail = stuCurrent;
- stuCurrent = stuCurrent.link;
- }
- if (found)
- {
- stuTrail.link = stuCurrent.link;
- StuLength--;
- if (stuTail == stuCurrent)
- {
- stuTail = stuTrail;
- }
- }
- }
- }
- }
- }
- public void updateLab(int data, String lf, String ll,int lId, String llab, String lday, String lt,String lq)
- {//update lab adds data then deletes the selected node from the list.
- LabTech current, trail;
- if (isTechEmpty())
- {//checks to see if the list is empty
- System.err.println("\nCannot Update an Empty list....");
- }
- else
- {
- if (head.staffID == data)
- {//if the list isnt empty, it chects to see if the entered data is equal to head
- addLabTech(lf, ll, lId, llab, lday, lt, lq);
- head = head.link;
- System.out.println("Succesfully Updated...");
- Techlength--;
- }
- else
- {// 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
- addLabTech(lf, ll, lId, llab, lday, lt, lq);
- trail = head;
- current = head.link;
- while (current != null && !found)
- {
- if (current.staffID == data)
- {
- found = true;
- System.out.println("\nSuccesFully Updated...");
- Techlength--;
- }
- else
- {
- trail = current;
- current = current.link;
- }
- if (found)
- {
- trail.link = current.link;
- Techlength--;
- if (tail == current)
- {
- tail = trail;
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement