Theory Test 3A. University of Cape Town ~ Department of Computer Science. Computer Science 1016S ~ For Official Use

Similar documents
Chapter 13 Lab Advanced GUI Applications

Chapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus

University of Cape Town ~ Department of Computer Science. Computer Science 1016S / 1011H ~ November Exam

import javax.swing.*; import java.awt.*; import java.awt.event.*;

University of Cape Town Department of Computer Science Computer Science CSC1017F

Queens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide

University of Cape Town ~ Department of Computer Science. Computer Science 1016S / 1011H ~ January Exam

University of Cape Town ~ Department of Computer Science. Computer Science 1011H/1016S ~ January Exam

A Simple Text Editor Application

RAIK 183H Examination 2 Solution. November 10, 2014

Building Graphical User Interfaces. GUI Principles

1.1 GUI. JFrame. import java.awt.*; import javax.swing.*; public class XXX extends JFrame { public XXX() { // XXX. init() main() public static

Attempt FOUR questions Marking Scheme Time: 120 mins

CS 180 Final Exam Review 12/(11, 12)/08

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

JLayeredPane. Depth Constants in JLayeredPane

RobotPlanning.java Page 1

Window Interfaces Using Swing Objects

Building Graphical User Interfaces. Overview

JAVA NOTES GRAPHICAL USER INTERFACES

Window Interfaces Using Swing Objects

Overview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling

CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2015

More Swing. CS180 Recitation 12/(04,05)/08

Layouts and Components Exam

RAIK 183H Examination 2 Solution. November 11, 2013

CSCI 201L Written Exam #1 Fall % of course grade

Calculator Class. /** * Create a new calculator and show it. */ public Calculator() { engine = new CalcEngine(); gui = new UserInterface(engine); }

FirstSwingFrame.java Page 1 of 1

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

1.00/1.001 Introduction to Computers and Engineering Problem Solving. Quiz 2: April 16, 2004

Programming Language Concepts: Lecture 8

CS 216 Exam 1 Fall SOLUTION

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

Write a program to implement stack or any other data structure in Java ASSIGNMENT NO 15

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Part 3: Graphical User Interface (GUI) & Java Applets

Original GUIs. IntroGUI 1

COMP Assignment #10 (Due: Monday, March 11:30pm)

CSE 8B Intro to CS: Java

CSCI 201L Written Exam #1 - SOLUTION Fall % of course grade

1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall (total 7 pages)

MIT AITI Swing Event Model Lecture 17

Java Help Files. by Peter Lavin. May 22, 2004

Lecture 28. Exceptions and Inner Classes. Goals. We are going to talk in more detail about two advanced Java features:

Java Project P6 Event Handling

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

encompass a group of features for building Graphical User Interfaces (GUI).

GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali

CSIS 10A Assignment 7 SOLUTIONS

Topic 6: Inner Classes

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 2: April 16, 2004

1.00/1.001 Introduction to Computers and Engineering Problem Solving Final Examination - December 15, 2003

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ June Exam

H212 Introduction to Software Systems Honors

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

Name CPTR246 Spring '17 (100 total points) Exam 3

Lecture 3: Java Graphics & Events

/* Write a Program implementing GUI based Calculator using Swing */

1.00/ Introduction to Computers and Engineering Problem Solving. Quiz 2 / November 10, 2005

GUI Forms and Events, Part II

7. Program Frameworks

Queen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb

We are on the GUI fast track path

1.00/1.001 Introduction to Computers and Engineering Problem Solving Final Examination - December 15, 2003

Programming graphics

CMP-326 Exam 2 Spring 2018 Solutions Question 1. Version 1. Version 2

State Application Using MVC

JAVA NOTES GRAPHICAL USER INTERFACES

Linked Lists. Linked List Nodes. Walls and Mirrors Chapter 5 10/25/12. A linked list is a collection of Nodes: item next -3.

Prototyping a Swing Interface with the Netbeans IDE GUI Editor

Lecture 16. Lecture

University of Cape Town ~ Department of Computer Science. Computer Science 1016S / 1011H ~ January Exam

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

AP CS Unit 11: Graphics and Events

Midterm Test II Object Oriented Programming in Java Computer Science, University of Windsor Fall 2014 Time 2 hours. Answer all questions

COURSE DESCRIPTION. John Lewis and William Loftus; Java: Software Solutions; Addison Wesley

Introduction to the JAVA UI classes Advanced HCI IAT351

Day before tests of Java Final test. IDM institution of Bandarawela. Project for department of education

University of Cape Town Department of Computer Science. Computer Science CSC117F Solutions

1. Stack Implementation Using 1D Array

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Object-Oriented Programming: Revision. Revision / Graphics / Subversion. Ewan Klein. Inf1 :: 2008/09

Swing - JTextField. Adding a text field to the main window (with tooltips and all)

Today. cisc3120-fall2012-parsons-lectiii.3 2

Midterm assessment - MAKEUP Fall 2010

ECE 242 Fall 13 Exam I Profs. Wolf and Tessier

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

APPENDIX. public void cekroot() { System.out.println("nilai root : "+root.data); }

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Final Examination Semester 2 / Year 2010

CS/ENGRD2110: Prelim 2 SOLUTION

JFrame & JLabel. By Iqtidar Ali

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)

Transcription:

Please fill in your Student Number and, optionally, Name. For Official Use Student Number : Mark : Name : Marker : University of Cape Town ~ Department of Computer Science Computer Science 1016S ~ 2007 Theory Test 3A Question Mark Marker 1 2 3 4 Total Marks : 30 Time : 40 minutes Instructions: a) Answer all questions. b) Write your answers in the space provided.

c) Show all calculations where applicable. Question 1: [5 marks] a) What is the advantage of a doubly linked list? [1 mark] b) Provide a diagram to show how a doubly linked list is structured. [2 marks] c) Give the Java code that would implement a suitable node for a doubly linked list. [2 marks]

Question 2: [5 marks] a) What is a stack? Provide a diagram and describe how a stack works [2 marks] b) Given the stack implementation below (as a linked data structure). Write a Java method pop() that returns the value from the top of the stack. Your method should remove the item that has been popped off the stack. [3 marks] public class Stack private class Node private int item; private Node link; public Node( ) item = null; link = null;

public Node(int newitem ) item = newitem; link = top; //End of Node inner class private Node top; public stack( ) top = null; /** Adds a node at the start of the stack with the specified data. The added node will be the first node in the stack. */ public void push(int item) top = new Node(item, top); /** Pops the top element of the stack. Returns 1 if the list is empty. */ public int pop( ) /** Returns the number of nodes in the list. */ public int size( )... public boolean isempty( ) return (top == null);

public void clearstack( ) top = null; Question 3: [5 marks] a) Convert 572 8 from octal to the following Show all of your working : Binary: [2 marks] Hexadecimal: [1 mark] Decimal [1 mark] b) Illustrate the IEEE 754 format for single precision floating point numbers [1 mark]

Question 4: [5 marks] a) What is a binary tree? Explain your answer with a diagram. [1 mark] b) Provide the algorithm for an inorder walk around a binary tree that prints out the value at each node. [2 marks]

c) Apply your algorithm to this tree; show your output as string. [2 marks] root p o t c m u e Output:

Question 5: [5 marks] Consider the following program. 1 import javax.swing.*; 2 import java.awt.*; 3 import java.awt.event.*; 4 5 public class GuiDemo extends JFrame implements ActionListener 6 7 private JPanel redpanel; 8 private JPanel bluepanel; 9 10 public static void main(string[] args) 11 12 GuiDemo gui = new GuiDemo( ); 13 gui.setvisible(true); 14 15 16 public GuiDemo( ) 17 18 super("menu Demonstration"); 19 setsize(300, 200); 20 setdefaultcloseoperation(jframe.do_nothing_on_close); 21 setlayout(new GridLayout(2,1)); 22 23 redpanel = new JPanel( ); 24 add(redpanel); 25 26 bluepanel = new JPanel( ); 27 add(bluepanel); 28 29 JMenu colormenu = new JMenu("Colours"); 30 31 JMenuItem redchoice = new JMenuItem("Red"); 32 redchoice.addactionlistener(this); 33 colormenu.add(redchoice); 34 35 JMenuItem bluechoice = new JMenuItem("Blue"); 36 bluechoice.addactionlistener(this); 37 colormenu.add(bluechoice); 38 39 JMenuItem exitchoice = new JMenuItem("Exit"); 40 exitchoice.addactionlistener(this); 41 colormenu.add(exitchoice); 42 43 JMenuBar bar = new JMenuBar( ); 44 bar.add(colormenu); 45 setjmenubar(bar); 46 47 48 public void actionperformed(actionevent e) 49 50 String command = e.getactioncommand( ); 51 52 if (command.equals("red")) 53 redpanel.setbackground(color.red); 54 else if (command.equals("blue")) 55 bluepanel.setbackground(color.blue); 56 else if (command.equals("exit")) 57 System.exit(0); 58 59 60

a) Illustrate the GUI produced by the above program when the program is run. [2 marks] b) Describe clearly the content of the menu using a diagram. [2 marks] c) What is the effect of activating the menu item Blue? Illustrate you answer with a diagram. [2 marks]

d) Explain the code at lines 16 21. What does it do and why is it used? [2 marks] e) Describe the purpose and actions of the code in line 48-59 [2 marks]

Question 6: [5 marks] a) Draw up a truth table to represent A. B (A and B) for all values of A and of B. [2 marks] b) Show that [3 marks]