Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package prgAssignment;
- public class GradClass
- {
- private GradNode head;
- public GradClass()
- {
- head = new GradNode(0);
- }
- public boolean isEmpty()
- {
- if (head==null)
- return true;
- else
- return false;
- }
- public void printList()
- {
- GradNode trav = head;
- while (trav!=null)
- {
- trav.displayNode();
- trav = trav.next;
- }
- }
- public void delete(Object newData)
- {
- GradNode previous,current;
- GradNode temp = new GradNode(newData);
- boolean found = false;
- current = head;
- previous = null;
- String key = (String) newData;
- while (!found&& current !=null)
- {
- String firstValue = (String) current.data;
- if ((key).compareTo(firstValue)==0)
- found = true;
- else {
- previous = current;
- current = current.next;
- }
- }
- temp.next = current;
- if (previous==null)
- head = temp;
- else
- previous.next = current.next;
- }
- public void insertInOrder(Object newData)
- {
- GradNode previous,current;
- GradNode temp = new GradNode(newData);
- boolean found = false;
- current = head;
- previous = null;
- String key = (String) newData;
- while(!found && current!=null)
- {
- String firstValue = (String) current.data;
- if ((key).compareTo(firstValue)<0)
- found = true;
- else
- {
- previous = current;
- current = current.next;
- }
- }
- temp.next = current;
- if (previous==null)
- head = temp;
- else
- previous.next = temp;
- }
- public Object getFirst()
- {
- return head.data;
- }
- public void add(Object newData)
- {
- GradNode temp = new GradNode(newData);
- if (head==null)
- head = temp;
- else {
- temp.next = head;
- head = temp;}
- }
- public boolean search(Object newData)
- {
- GradNode trav = head;
- boolean found = false;
- while (trav!=null&&found==false)
- {
- if(trav.data.equals(newData))
- found = true;
- trav = trav.next;
- }
- return found;
- }
- }
- package prgAssignment;
- public class GradNode
- {
- public Object data;
- public GradNode next;
- public GradNode(Object newData)
- {
- data = newData;
- next = null;
- }
- public void displayNode()
- {
- System.out.print(data + "->");
- }
- }
- package prgAssignment;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.Scanner;
- public class GradDemo
- {
- public static void main ( String [ ] args) throws IOException
- {
- GradClass cookies = new GradClass();
- Scanner scnr = new Scanner (System.in);
- GradClass Scharff = new GradClass();
- GradClass Chiou = new GradClass();
- while (!false)
- {
- System.out.println("Enter a name to Add Print Delete or Search");
- String a = scnr.next();
- String b = scnr.next();
- String emptyString = scnr.nextLine();
- if(a.equals("Add"))
- {
- System.out.print("What is this student's major");
- String major = scnr.next();
- if (major.equals("CS"))
- Scharff.add(b);
- else if (major.equals("IS"))
- Chiou.add(b);
- else
- System.out.println("That student is not in the Seidenberg School of Information Systems");
- }
- if(a.equals("Print"))
- {
- if (b.equals("Scharff"))
- Scharff.printList();
- else if (b.equals("Chiou"))
- Chiou.printList();
- else
- System.out.println("Does not exist");
- }
- if (a.equals("Search"))
- {
- if (Scharff.search(b))
- System.out.println("Student's advisor is Scharff");
- else if (Chiou.search(b))
- System.out.println("Student's advisor is Chiou");
- else
- System.out.println("Does not exist");
- }
- if (a.equals("Delete"))
- {
- if (Scharff.search(b))
- Scharff.delete(b);
- else if(Chiou.search(b))
- Chiou.delete(b);
- else
- System.out.println("Does not exist");
- }
- }
- }
- }
- Enter a name to Add Print Delete or Search
- Add Kevin
- What is this student's majorCS
- Enter a name to Add Print Delete or Search
- Add Devin
- What is this student's majorCS
- Enter a name to Add Print Delete or Search
- Add Devon
- What is this student's majorIS
- Enter a name to Add Print Delete or Search
- Add Aleya
- What is this student's majorCS
- Enter a name to Add Print Delete or Search
- Add Patrick
- What is this student's majorCS
- Enter a name to Add Print Delete or Search
- Add Zach
- What is this student's majorIS
- Enter a name to Add Print Delete or Search
- Add Scott
- What is this student's majorCS
- Enter a name to Add Print Delete or Search
- Add Kenny
- What is this student's majorIS
- Enter a name to Add Print Delete or Search
- Add Josh
- What is this student's majorIS
- Enter a name to Add Print Delete or Search
- Add Ty
- What is this student's majorCS
- Enter a name to Add Print Delete or Search
- Print Scharff
- Ty->
- Scott->
- Patrick->
- Aleya->
- Devin->
- Kevin->
- 0->
- Enter a name to Add Print Delete or Search
- Search
- Ty
- System.out.println("Student's advisor is Scharff");
- Enter a name to Add Print Delete or Search
- Delete Kevin
- Enter a name to Add Print Delete or Search
- Print Scharff
- Ty->
- Scott->
- Patrick->
- Aleya->
- Devin->
- 0->
- Enter a name to Add Print Delete or Search
- PART B---------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement