Skip to document

CSC1016S 2017 Test3 MEMO

notes on unit 9 of core economics textbook for week 1 second semester
Course

Java programming (CSC1016S)

174 Documents
Students shared 174 documents in this course
Academic year: 2017/2018
Uploaded by:
Anonymous Student
This document has been uploaded by a student, just like you, who decided to remain anonymous.
University of Cape Town

Comments

Please sign in or register to post comments.

Related Studylists

Odetola Study List

Preview text

University of Cape Town ~~ Department of Computer Science

Computer Science 1016S ~~ 2017

Class Test 3

** Solutions **

Enter the following details AND shade in the corresponding blocks to the right with your Student Number.

Faculty (please tick one):

Science Engineering Commerce Humanities Other:

Student Number :

__________________________________

Name (optional) :

__________________________________

Marks : 40 Time : 40 minutes Instructions: a) Answer all questions. b) Write your answers in PEN in the spaces provided. c) Show all calculations where applicable.

A         0

B          1

C          2

D         3

E          4

F          5

G         6

H         7

I          8

J          9

K     

L      

M     

N     

O     

P      

Q     

R      

S      

T      

U     

V     

W     

X     

Y     

Z      

Question 1 2 3 4 5 6 7 8 Max 15 5 8 12 Marks 0                 1                 2                 3                 4                 5                 6                 7                 8                 9                 Marker

FOR

OFFICIAL

USE

ONLY:

Question 1 – Linked Lists [15]

(i) Explain what a linked list is and how it differs from an array. [2]










A linked list is a data structure that stores data in nodes/capsules/objects and linked together by link variables containing the memory address to the next node [1]. Unlike arrays, the size does not need to be specified upfront and the list can grow dynamically as items are added [1].

(ii) The head variable is not the same as the head node in the context of linked lists. Explain the differences. [2]

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

The head variable is not the node itself [1], but instead it stores the memory address of where the head node (or first node in the list) is located in memory [1].

(iii) Explain what an iterator is and discuss briefly some of the methods/functionality that an iterator will provide. [3]

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

By setting the head to null, nothing can access the nodes and the Java garbage collector recycles the memory [1]. CODE: head = null; [1]

(vii) With reference to line 3, the data variable is of typeT. Explain what this means and what type of data will be stored in this example. [2]

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

T is a generic data type [1] and will resolve to type String in this example [1].

Question 2 – Stacks and Queues [5]

(i) Describe the main difference between a stack and a queue. [2]






Stack: Last in first out (Items are removed in reverse order of which they were added) Queue: First in first out (Items added at the end and removed from the front)

(ii) Draw four drawings/diagrams to visualise what the stack will look like after each line has been executed. [3]

stack( "1" ); stack( "3" ); stack(); stack( "8" );

[1 mark for overall correctness] [1 mark for correct final state] [1 mark for removing 3]

(iv) Can the name of the methodactionPerformed(...) at //5 have a different name? Explain your answer. [1] ________________________________________________________________________ ________________________________________________________________________ ________________________________________________________________________ No, since it is the implementation of the method signature from the ActionListener interface. [1]

(v) Draw a diagram to show the GUI that will be displayed when this program runs. [3]

Frame with correct title etc. [0] Two buttons [0] Label with “hello :)” [0] Blank cell between buttons and label [0] Layout should have 1 row with 4 columns and blank cell between B2 and label. Should look similar to the image below [1]

Question 4 - SIPP [12]

(i) Social issues and professional practice have as component computer ethics. While computer ethics does not have a neat definition, it is clear what is, and is not, a topic of concern. Say of each of the following two cases whether it belongs to computer ethics specifically or not, and explain in one short sentence why. [4] A) Money laundering over a secure website. _________________________________________________________________________ _________________________________________________________________________ _________________________________________________________________________


A) no [0]; is just regular crime issue (not specific to computing, and was done before the Web) [1].

B) Selling of supermarket customers' loyalty card data to a health insurance company.





B) yes [0]; (digitised) data privacy issue, and this would not have been possible without ICT [1]

(ii) Explain in your own words what the Digital Divide refers to. [2]







denotes the gap/difference between people who do have [easy, cheap, fast] access to the internet with all the information on the Web, and those who do not. [2]

(iii) Which of the following statements describe teleology best? [2]

A. Actions are right insofar as they ensure fairness in society as a whole. B. Actions are essentially right or wrong, and some actions are never justified. C. Never impose wrong actions on others that you would not choose to do for yourself. D. Actions are judged morally right or wrong based upon their consequences.

Appendix A

1 public class LinkedList<T> { 2 private class Node<T> { 3 T data ; 4 Node<T> link ; 5 6 public Node(T dataItem, Node<T> linkValue) { 7 setData(dataItem); 8 link = linkValue; 9 } 10 11 public void setData(T dataItem) { 12 data = dataItem; 13 } 14 } //End of node inner class 15 16 Node<T> head ; 17 18 public LinkedList() { 19 head = null ; 20 } 21 //Adds an item to the start of the list 22 public void addToStart(T dataItem) { 23 // TODO for Question 1(e) 24 } 25 //Deletes all items in the list 26 public void clear() { 27 // TODO for Question 1(f) 28 } 29 30 public void outputList() { 31 Node position = head ; 32 while (position != null ) { 33 System. out .println(position. data ); 34 position = position. link ; 35 } 36 } 37 38 public static void main(String[] args) { 39 LinkedList<String> list = new LinkedList<>(); 40 list( "Banana" ); 41 list( "Peach" ); 42 list( "Apple" ); 43 list(); 44 } 45 }

Was this document helpful?

CSC1016S 2017 Test3 MEMO

Course: Java programming (CSC1016S)

174 Documents
Students shared 174 documents in this course
Was this document helpful?
University of Cape Town ~~ Department of Computer Science
Computer Science 1016S ~~ 2017
Class Test 3
** Solutions **
Enter the following details AND shade in the corresponding
blocks to the right with your Student Number.
Faculty (please tick one):
Science Engineering Commerce Humanities Other:
Student Number :
__________________________________
Name (optional) :
__________________________________
Marks : 40
Time : 40 minutes
Instructions:
a) Answer all questions.
b) Write your answers in PEN in the
spaces provided.
c) Show all calculations where
applicable.
A0
B1
C2
D3
E4
F5
G6
H7
I8
J9
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
Question 12345678
Max 15 5 8 12
Marks 0
1
2
3
4
5
6
7
8
9
Marker
FOR
OFFICIAL
USE
ONLY: