Presentation is loading. Please wait.

Presentation is loading. Please wait.

PC02 Consolidation Loading a witty quote…. PC02 Consolidation Loading a witty quote…

Similar presentations


Presentation on theme: "PC02 Consolidation Loading a witty quote…. PC02 Consolidation Loading a witty quote…"— Presentation transcript:

1

2 PC02 Consolidation Loading a witty quote…

3 This is the consolidation for this term
Introduction This is the consolidation for this term Has some of exercises on all the topics covered Start at any point you want Put all these in a single project called “Term03Consolidation” And then packages for each topic you do

4 Making a custom linked list Fixing errors Resources:
Index Graphics Making a custom linked list Fixing errors Resources: Click me Click me Click me

5 You will need to implement three methods:
Graphics For this exercise, you will need to finish a program, which can be found in resources You will need to implement three methods: paintComponent, which should draw a ball move, which should update the ball’s position and make it bounce of edges mouseClicked, which should teleport the ball to where you click See comments in BallPanel.java for more information

6 You program should implement a custom generic linked list
For this exercise, you will need to finish a program, which can be found in resources You program should implement a custom generic linked list You will need to implement three methods and a constructor

7 In case if you don’t remember, this is how lists work:
Linked list In case if you don’t remember, this is how lists work: When we add elements, we start from the root and keep going until we find the last element Then, we just make it point at the new element Pointer to the next element Pointer to the next element Element 1 (root) Element 2 Element 3

8 Open up CustomLinkedList.java
In the constructor, set root to null and size to zero In size() return the size of the list

9 In add() create a new Node
Linked list In add() create a new Node It should use Type for it’s generic type Call it “node” Pass element to its constructor Add an if statement which checks if root is null If it is, assign node to root, increment size by one and return form the function

10 Otherwise, initialise a new node
Linked list Otherwise, initialise a new node Call it current Sue root for its value Add a while loop that keeps going while current.getNext() is not null Inside the loop set current to current.getNext() After the loop, set current’s next node to node and add one to size

11 Removing elements is a bit trickier:
Linked list Removing elements is a bit trickier: To remove, we need to make the previous element point at the element after the one we’re deleting: Pointer to the next element Pointer to the next element Element 1 Element 2 (The element to remove) Element 3 Pointer to the next element Pointer to the next element Element 1 Element 2 (The element to remove) Element 3

12 The first couple of lines in remove will be very similar:
Linked list The first couple of lines in remove will be very similar: Declare a new node called node that uses element as a parameter Add an if statement that checks if root is null and, if it is, returns from the function Create a new Node called current and assign root to it

13 current. getNext(). getNext()
Linked list Add a while loop that keeps going while current.getNext() is not null Add an if statement that checks if current.getNext() is equal to node Make sure it uses .equals instead of “==”! If they’re equal, set current’s next node to current.getNext().getNext() Pointer to the next element Pointer to the next element current current. getNext() current. getNext(). getNext()

14 Make sure to update size and return form the function as well
Linked list Make sure to update size and return form the function as well Otherwise, assign current.getNext() to current Test the program!

15 Everyone’s favourite section is back!
Fixing errors Everyone’s favourite section is back! In eclipse, click on File -> Import -> General -> Existing Projects into Workspace Then, tick “Select archive file” and click on “Browse…”

16 See you next (academic) year!
THE END See you next (academic) year!


Download ppt "PC02 Consolidation Loading a witty quote…. PC02 Consolidation Loading a witty quote…"

Similar presentations


Ads by Google