frederick99

Java assignment

Sep 27th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. Create a generic abstract class called GenericList<I>:
  2. This class will contain only two data fields:
  3. Node<I> head (this is the head of the list).
  4.  
  5. int length (the length of the list and should be private)
  6. This class should include the following methods:
  7. print(): prints the items of the list, one value per line.
  8. add(I data): adds the value to the list. This is abstract since the implementation
  9. depends on what the data structure is.
  10. delete(): returns the first value of the list and deletes the node.
  11. This class should also define a generic inner class Node<T>: It will include two fields: T
  12. data and Node<T> next;
  13.  
  14. ***This class encapsulates a linked list. Defining a Node class and providing two
  15. methods that a queue and stack have in common while leaving adding a node to each
  16. implementation that inherits from it.***
  17.  
  18. Create two more classes GenericQueue<I> and GenericStack<I>. They both should
  19. inherit from GenericList<I>.
  20.  
  21. The constructors for each class will take one parameter. That parameter will be a value
  22. that will go in the first node of the list encapsulated by each instance of the class. Each
  23. constructor should initialize the linked list head, with the value passed in by the
  24. constructor. Each class should also implement the method add(I data), GenericQueue
  25. will add to the back of the list while GenericStack will add to the front. Each class must
  26. also keep track of the length of it’s list using the length data field defined in the abstract
  27. class.
  28.  
  29. GenericQueue will have the methods enqueue(I data) and dequeue() which will call
  30. the methods add(I data) and delete() respectively. Enqueue and dequeue merely call
  31. add(I data) and delete(). The reason for this is that a user would expect these calls to
  32. be implemented in each of those data structures. You will do the same with GenericStack.
  33.  
  34. GenericStack will have the methods push(I data) and pop() which will call the
  35. methods add(I data) and delete() respectively.
  36.  
  37. Once implemented, you should be able to create instances of both GenericQueue and
  38. GenericStack in main with most primitive wrapper classes. You should be able to add
  39. and delete nodes to each data structure instance as well as print out the entire list and
  40. check for the length of the list. You must follow this implementation: meaning you can
  41. not add any additional data fields or classes. You may add getters/setters as need be.
  42.  
  43. Implementing Iterator Design Pattern:
  44. You are to create an interface called CreateIterator. It will have one abstract method:
  45. Iterator createIterator(). You will want both GenericQueue and GenericStack classes
  46. to implement this interface.
  47. You must also create a class to contain logic for iterating through your data structure.
  48. Call this class GLIterator.
  49. It should implement the java interface Iterator (java.util.Iterator). You will have to
  50. implement two inherited methods: hasNext() and next().
  51. You are expected to fully comment your code and use good coding practices.
Add Comment
Please, Sign In to add comment