THE UNIVERSITY OF AUCKLAND

Size: px
Start display at page:

Download "THE UNIVERSITY OF AUCKLAND"

Transcription

1 CompSci 101 with answers THE UNIVERSITY OF AUCKLAND FIRST SEMESTER, 2012 Campus: City COMPUTER SCIENCE Principles of Programming (Time Allowed: TWO hours) NOTE: You must answer all questions in this test. No calculators are permitted Answer in the spaces provided in this booklet. There is space at the back for answers that overflow the allotted space. Surname Forenames Student ID Login (UPI) Q1 Q4 Q7 Q10 Q2 (/12) Q5 (/15) Q8 (/6) Q11 (/6) Q3 (/10) Q6 (/4) Q9 (/10) Q12 (/7) (/8) (/6) (/6) TOTAL (/10) (/100)

2 Question/Answer Sheet CompSci 101 with answers Question 1 (12 marks) a) Complete the output produced when the following code is executed. int x = * 6 / 2-1; int y = 2 % * 2-2 / 2; System.out.println("x = " + x); System.out.println("y = " + y); x = 15 y = 3 (2 marks) b) The following section of code does not compile. Identify the error by circling the error and writing out the corrected single line of code. The output of the corrected code is "Woman". int gender = 1; if ( gender = 1) { System.out.println("Woman"); else { System.out.println("Man"); if ( gender == 1) { (2 marks) c) The following section of code does not execute as it should. Identify the problem and correct the code. The output of the corrected code should be "6" (i.e. the sum of 0, 1, 2 and 3). int z = 0; int sum = 0; while ( z <= 3 ) { sum = sum + z; z++; System.out.println(sum); (2 marks)

3 Question/Answer Sheet CompSci 101 with answers d) Rewrite the following code with correct indentation. String s = "*"; if ( y == 8 ) { if ( x == 5 ) { s = "@@@"; else { s = "###"; s = s + "S"; System.out.println("s: " + s); String s = "*"; if ( y == 8 ) { if ( x == 5 ) { s = "@@@"; else { s = "###"; s = s + "S"; System.out.println("s: " + s); (3 marks) e) Using the code from part d) above, complete the output if x has the value 5, and y has the value 8. (2 marks) f) Using the code from part d) above, complete the output if x has the value 5, and y has the value 7. s: * (1 mark)

4 Question/Answer Sheet CompSci 101 with answers Question 2 (10 marks) a) Complete the getaverage() method which takes two int parameters, x and y, and returns the average of the two parameter values. The return type of the method is a double. For example, the following code: System.out.println("Average of 2 and 3 is " + getaverage(2,3)); System.out.println("Average of 4 and 3 is " + getaverage(4,3)); System.out.println("Average of 4 and 6 is " + getaverage(4,6)); produces the output: Average of 2 and 3 is 2.5 Average of 4 and 3 is 3.5 Average of 4 and 6 is 5.0 private double getaverage(int x, int y) { return (x + y ) / 2.0; b) Complete the printrowofstars() method which is passed an int parameter, n. The method prints n number of stars. For example, the code: printrowofstars(4); (3 marks) produces the following output: **** private void printrowofstars(int n) { for (int i = 0; i < n; i++) { System.out.print("*"); (3 marks)

5 Question/Answer Sheet CompSci 101 with answers c) Complete the printsquareofstars() method which is passed an int parameter, size. The method displays a square of stars. The number of rows is given by the parameter, size, and there are size number of stars in each row. Your answer MUST call the printrowofstars() method defined in part b) above. For example, the following code: printsquareofstars(3); produces the following output: *** *** *** private void printsquareofstars(int size) { for (int i = 0; i < size; i++) { printrowofstars (size); System.out.println(); (4 marks)

6 Question/Answer Sheet CompSci 101 with answers Question 3 (8 marks) a) Given the following method: private void method1(int x, int y, int[] z) { x++; y = 10; if ( z.length >= 1 ) { z[0] = 100; complete the output produced when the following code is executed. int a = 1; int[] b = { 1, 2, 3 ; int[] c = { 1, 2, 3 ; method1(a, b[0], c); System.out.println("a = " + a); System.out.println("b[0] = " + b[0]); System.out.println("c[0] = " + c[0]); a = 1 b[0] = 1 c[0] = 100 (3 marks)

7 Question/Answer Sheet CompSci 101 with answers b) Given the following method: private void method2(point p, Point q, Point r) { p.x = 100; q = new Point(200, 300); r = new Point(300, 400); complete the output produced when the following code is executed. Point d = new Point(1, 2); Point e = new Point(3, 4); Point[] f = { new Point(1, 2), new Point(3, 4) ; method2(d, e, f[0]); System.out.println("d.x = " + d.x); System.out.println("e.x = " + e.x); System.out.println("f[0].x = " + f[0].x); d.x = 100 e.x = 3 f[0].x = 1 c) Given the following method: private void method3(point[] x, Point[] y) { if ( x.length >= 1) { x[0].x = 100; (3 marks) y = new Point[1]; y[0] = new Point(200, 300); complete the output produced when the following code is executed. Point[] g = { new Point(1, 2), new Point(3, 4) ; Point[] h = { new Point(1, 2), new Point(3, 4) ; method3(g, h); System.out.println("g[0].x = " + g[0].x); System.out.println("h[0].x = " + h[0].x); g[0].x = 100 h[0].x = 1 (2 marks)

8 Question/Answer Sheet CompSci 101 with answers Question 4 (15 marks) The class SaleItem represents an item on sale in a shop and is partially defined as follows: public class SaleItem { private String code; private String description; private int price;... a) Complete the following constructor method of the class, which allows the creation of new SaleItem objects. public SaleItem (String code, String desc, int price) { this.code = code; description = desc; this.price = price; (3 marks) b) Complete the following accessor (get) method of the class, which returns the value of the instance variable price. public int getprice() { return price; (3 marks) c) Complete the following mutator (set) method of the class, which sets the value of the instance variable description. public void setdescription(string desc) { description = desc; (3 marks)

9 Question/Answer Sheet CompSci 101 with answers d) Complete the following equals method of the class, which compares the values of two SaleItem objects based on the description and price. public boolean equals(saleitem other) { return description.equals(other. description) && price == other.price; (3 marks) e) Complete the following tostring method of the class, which returns a String representation of the SaleItem object. For example, the following code: SaleItem item = new SaleItem("b123", "Chocolate Biscuits 200g",2); System.out.println(item.toString()); prints: Code-b123,Item-Chocolate Biscuits 200g,Price-$2 public String tostring() { return "Code-" + code + ", Item-" + description + ", Price-$" + price; (3 marks)

10 Question/Answer Sheet CompSci 101 with answers Question 5 (4 marks) Write a code segment that declares and creates an array of integer values with size 100. Use a loop structure to set the value of each element in the array as the square of the corresponding index. For example: the element at position 0 has the value 0, the element at position 1 has the value 1, the element at position 2 has the value 4, the element at position 3 has the value 9, etc. int[] elements = new int[100]; for (int i = 0; i < elements.length; i++) { elements[i] = i * i; Question 6 (6 marks) (4 marks) Give the complete definition of the following copyarray method, which returns a duplicate of the array passed in as a parameter. private int[] copyarray(int[] a) { int[] b; b = new int[a.length]; for (int i = 0; i < a.length; i++) { b[i] = a[i]; return b; (6 marks)

11 Question/Answer Sheet CompSci 101 with answers Question 7 (6 marks) The Stock class represents all the items on sale in a shop. A partial definition of the Stock class is: public class Stock { public static final int MAX_SIZE = 1000; private SaleItem[] items; private int size;... where the items variable is an array of SaleItem objects (from Question 4), and the size variable represents the actual number of items in the array. Give the complete definition of the following findcheapest method in the Stock class, which returns the cheapest item (i.e. the item with the lowest price) in the array. Note: you can assume that the value of size is greater than 0. public SaleItem findcheapest() { SaleItem cheapest; cheapest = items[0]; int pricecheapest = cheapest.getprice(); for (int i = 1; i < size; i++) { if (items[i].getprice() < pricecheapest) { cheapest = items[i]; pricecheapest = cheapest.getprice(); return cheapest; (6 marks)

12 Question/Answer Sheet CompSci 101 with answers Question 8 (10 marks) a) Below is the definition of the array, positions. Note that only some of the elements of the positions array are shown here. Point[] positions = {new Point(70, 10), new Point(90, 30), new Point(50, 30),... ; Write a Java statement which declares a variable p and assigns the LAST element of the positions array to the variable. Point p = positions[positions.length 1]; (2 marks) b) Write a boolean expression which tests whether the Point, p, is inside the Rectangle, r. r.contains(p) (2 marks) c) Write the Java code which swaps the x and the y values of the Point, p. You can assume that the Point, p, has been correctly created. public void start() { Point p =... ; int temp; //x, y values of the Point, p, are not shown temp = p.x; p.x = p.y; p.y = temp; (2 marks)

13 Question/Answer Sheet CompSci 101 with answers d) Below is a diagram showing a Rectangle, r, and a Point, p. The Point, p, is exactly halfway down the left hand side of the Rectangle, r. Complete the Java statement which creates the Point, p, in the correct position. You can assume that the Rectangle, r, has been correctly created. //x, y, width and height of the Rectangle, r, //are not shown Rectangle r =... ; Point p = new Point(r.x, r.y + r.height / 2); (2 marks) e) Below is a diagram showing a Rectangle, r, and a Point. The Rectangle, r, is a square of size 20. The Point, p, has an x value of 50 and a y value of 60 and is the centre of the square. Complete the Java code which creates the Rectangle, r. Point p = new Point( 50, 60 ); Rectangle r = new Rectangle(40, 50, 20, 20); (2 marks)

14 Question/Answer Sheet CompSci 101 with answers Question 9 (6 marks) As accurately as possible, show what would be drawn in the window by the following program. Grid lines have been drawn on the window to help you. The gap between adjacent gridlines is 10 pixels. import java.awt.*; import javax.swing.*; public class MyJPanel extends JPanel { public void paintcomponent(graphics g){ super.paintcomponent(g); drawpattern(g, 70, 60, 20); private void drawpattern(graphics g, int x, int y, int size) { g.fillrect(x, y, size * 3, size); x = x + size / 2; y = y - size * 2; g.drawoval(x, y, size * 2, size * 2); x = x + size / 2; y = y + size * 3; g.drawline(x, y, x, y + size); x = x + size; g.drawline(x, y, x, y + size); y = y + size; g.drawstring("bau!", x, y);

15 Question/Answer Sheet CompSci 101 with answers (6 marks)

16 Question/Answer Sheet CompSci 101 with answers Question 10 (6 marks) The JPanel defined below contains the following components: nightst pricet priceb discountpriceb A JLabel displaying the String "Number of nights", a JTextField in which the user enters the number of nights, a JLabel displaying the String "Price $", a JTextField which displays the price, a JButton displaying the String "PRICE", a JButton displaying the String "PRICE WITH DISCOUNT". Initially, when the JPanel first appears, the JTextFields are both empty. When the user enters a whole number in the nightst textfield and presses the "PRICE" button, the price is displayed in the pricet textfield. The price for each night is $100. When the user enters a whole number in the nightst textfield and presses the "PRICE WITH DISCOUNT" button, the discounted price is displayed in the pricet textfield. The discount price for each night is $90. You are required to complete the following JPanel definition so that the JPanel behaves as described above. The left-hand screenshot below shows the JPanel after the user has entered the value 3 in the nightst and has pressed the "PRICE" button. The right-hand screenshot below shows the JPanel after the user has entered the value 5 in the nightst and has pressed the "PRICE WITH DISCOUNT" button. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class AJPanel extends JPanel implements ActionListener { private JTextField nightst, pricet; private JButton priceb, discountpriceb;

17 Question/Answer Sheet CompSci 101 with answers public AJPanel() { nightst = new JTextField(4); pricet = new JTextField(7); priceb = new JButton("PRICE"); discountpriceb = new JButton("PRICE WITH DISCOUNT"); add(new JLabel(new JLabel("Number of nights")); add(nightst); add(new JLabel("Price $")); add(pricet); add(priceb); add(discountpriceb); priceb.addactionlistener(this); discountpriceb.addactionlistener(this); public void actionperformed( ActionEvent e ) { int numberofnights; int price; numberofnights = Integer.parseInt( nightst.gettext()); if(e.getsource() == priceb) { price = 100 * numberofnights; else { price = 90 * numberofnights; pricet.settext("" + price); (6 marks)

18 Question/Answer Sheet CompSci 101 with answers Question 11 (7 marks) The following JPanel responds to MouseEvents. import java.awt.*; import javax.swing.*; import java.awt.event.*; public class AJPanel implements MouseListener { private final int GAP = 10; private final int CENTRE_X = 100; private int left; private int right; public AJPanel() { addmouselistener(this); left = CENTRE_X; right = CENTRE_X; public void mousepressed(mouseevent e) { int x = e.getx(); int y = e.gety(); if (x > right) { right = right + GAP; else if (x < left) { left = left - GAP; else { if (left < CENTRE_X) { left = left + GAP; if (right > CENTRE_X) { right = right - GAP; repaint(); public void paintcomponent(graphics g) { super.paintcomponent(g); g.fillrect(centre_x - 1, 0, 3, 310); int posx = left; int posy = 20; while(posx < right) { g.drawoval(posx, posy, GAP, 30); posx = posx + GAP; public void mouseclicked(mouseevent e) { public void mouseentered(mouseevent e) { public void mouseexited(mouseevent e) { public void mousereleased(mouseevent e) {

19 Question/Answer Sheet CompSci 101 with answers Note: the grid lines have been drawn in the window to help you. Initially, the JPanel displays a vertical filled rectangle of width 3 pixels (see the JPanel on the right). Show the JPanel after the user has pressed the mouse two times: first mouse press occurs at position 30, 90 second mouse press occurs at position 140, 10 Show the JPanel after the user has pressed the mouse one more time: third mouse press occurs at position 20, 40 Now show the JPanel after the user has pressed the mouse another time: fourth mouse press occurs at position 95, 40 (7 marks)

20 Question/Answer Sheet CompSci 101 with answers Question 12 (10 marks) You are required to complete the following JPanel which uses a Timer object. The Timer object is created with a delay of 300 milliseconds and the Timer starts as soon as the JPanel is created. The JPanel displays twelve squares in a formation similar to a clockface. The top left position of each square is stored in the Point array, POSITIONS, i.e., the top left position of the top square (12 noon) is stored in POSITIONS[0], the top left position of the second square (1pm) is stored in POSITIONS[1], the top left position of the third square (2pm) is stored in POSITIONS[2], etc. Initially, when the JPanel first appears, the top square (12 noon) is filled with red. At each tick of the Timer, the next square is filled with red, moving in a clockwise direction around the clock face. The instance variable, currentindex, stores which element of the POSITIONS array is the top left position of the square which is filled with red. Note: the position of the red square always cycles round and round the clockface in a clockwise direction. The user controls the JPanel using the arrow keys in the following way: The UP arrow key Whenever the user presses the UP arrow key, the top square is displayed in red, i.e., the square with the top left position given by the Point, POSITIONS[0]. Note that pressing the UP arrow key does not affect the Timer in any way. The DOWN arrow key Whenever the user presses the DOWN arrow key, the Timer stops/starts. If the Timer is currently running, pressing the DOWN arrow key causes the Timer to stop. If the Timer is currently stopped, pressing the DOWN arrow key causes the Timer to start. Below are some screenshots of the JPanel in action. The first four screenshots show the JPanel initially and during the first three ticks of the Timer. The last three screenshots show the JPanel as it completes one cycle of the clockface and begins the next cycle Note: you MUST use the variables and constants given in the code.

21 Question/Answer Sheet CompSci 101 with answers import javax.swing.*; import java.awt.*; import java.awt.event.*; public class AJPanel extends JPanel //The top left positions of the squares in the clockface public static final Point[] POSITIONS = { new Point(70, 10), new Point(90, 30), new Point(110, 50), new Point(130, 70), new Point(110, 90), new Point(90, 110), new Point(70, 130), new Point(50, 110), new Point(30, 90), new Point(10, 70), new Point(30, 50), new Point(50, 30) ; public static final int SIZE = 10; private int currentindex; private Timer t; implements KeyListener, ActionListener { public AJPanel() { currentindex = 0; addkeylistener(this); t = new Timer(300, this); t.start(); public void actionperformed(actionevent e) { if (currentindex == POSITIONS.length - 1) { currentindex = 0; else { currentindex++; repaint(); public void paintcomponent(graphics g) { super.paintcomponent(g); g.setcolor(color.red); Point p = POSITIONS[currentIndex]; g.fillrect(p.x, p.y, SIZE, SIZE); g.setcolor(color.black); drawemptysquares(g);

22 Question/Answer Sheet CompSci 101 with answers private void drawemptysquares(graphics g) { Point p; for( int i = 0; i < POSITIONS.length; i++) { p = POSITIONS[i]; g.drawrect(p.x, p.y, SIZE, SIZE); public void keypressed(keyevent e) { if (e.getkeycode() == KeyEvent.VK_UP ) { currentindex = 0; else if (e.getkeycode() == KeyEvent.VK_DOWN) { if (t.isrunning()) { t.stop(); else { t.start(); repaint(); public void keyreleased(keyevent e) { public void keytyped(keyevent e) { (10 marks)

23 Question/Answer Sheet CompSci 101 with answers OVERFLOW PAGE (Please number the question(s) carefully and indicate clearly under the relevant question that you have overflowed to this page)

24 Question/Answer Sheet CompSci 101 OVERFLOW PAGE (Please number the question(s) carefully and indicate clearly under the relevant question that you have overflowed to this page)

User interfaces and Swing

User interfaces and Swing User interfaces and Swing Overview, applets, drawing, action listening, layout managers. APIs: java.awt.*, javax.swing.*, classes names start with a J. Java Lectures 1 2 Applets public class Simple extends

More information

GUI 4.1 GUI GUI MouseTest.java import javax.swing.*; import java.awt.*; import java.awt.event.*; /* 1 */

GUI 4.1 GUI GUI MouseTest.java import javax.swing.*; import java.awt.*; import java.awt.event.*; /* 1 */ 25 4 GUI GUI GUI 4.1 4.1.1 MouseTest.java /* 1 */ public class MouseTest extends JApplet implements MouseListener /* 2 */ { int x=50, y=20; addmouselistener(this); /* 3 */ super.paint(g); /* 4 */ g.drawstring("hello

More information

GUI in Java TalentHome Solutions

GUI in Java TalentHome Solutions GUI in Java TalentHome Solutions AWT Stands for Abstract Window Toolkit API to develop GUI in java Has some predefined components Platform Dependent Heavy weight To use AWT, import java.awt.* Calculator

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors Introduction to Software Systems Honors Lecture #19: November 4, 2015 1/14 Third Exam The third, Checkpoint Exam, will be on: Wednesday, November 11, 2:30 to 3:45 pm You will have 3 questions, out of 9,

More information

CS 120 Fall 2008 Practice Final Exam v1.0m. Name: Model Solution. True/False Section, 20 points: 10 true/false, 2 points each

CS 120 Fall 2008 Practice Final Exam v1.0m. Name: Model Solution. True/False Section, 20 points: 10 true/false, 2 points each CS 120 Fall 2008 Practice Final Exam v1.0m Name: Model Solution True/False Section, 20 points: 10 true/false, 2 points each Multiple Choice Section, 32 points: 8 multiple choice, 4 points each Code Tracing

More information

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics Topic 9: Swing Outline Swing = Java's GUI library Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 7: Expand moving shapes from Assignment 4 into game. "Programming

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 34 April 13, 2017 Model / View / Controller Chapter 31 How is the Game Project going so far? 1. not started 2. got an idea 3. submitted design proposal

More information

AP CS Unit 12: Drawing and Mouse Events

AP CS Unit 12: Drawing and Mouse Events AP CS Unit 12: Drawing and Mouse Events A JPanel object can be used as a container for other objects. It can also be used as an object that we can draw on. The first example demonstrates how to do that.

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 36 November 30, 2018 Mushroom of Doom Model / View / Controller Chapter 31 Announcements Game Project Complete Code Due: Monday, December 10th NO LATE

More information

Unit 7: Event driven programming

Unit 7: Event driven programming Faculty of Computer Science Programming Language 2 Object oriented design using JAVA Dr. Ayman Ezzat Email: ayman@fcih.net Web: www.fcih.net/ayman Unit 7: Event driven programming 1 1. Introduction 2.

More information

Graphical User Interfaces 2

Graphical User Interfaces 2 Graphical User Interfaces 2 CSCI 136: Fundamentals CSCI 136: Fundamentals of Computer of Science Computer II Science Keith II Vertanen Keith Vertanen Copyright 2011 Extending JFrame Dialog boxes Overview

More information

THE UNIVERSITY OF AUCKLAND

THE UNIVERSITY OF AUCKLAND THE UNIVERSITY OF AUCKLAND CompSci 101 FIRST SEMESTER, 2008 Campus: City COMPUTER SCIENCE TEST Principles of Programming (Time allowed: 75 MINUTES) NOTE: Attempt ALL questions Write your answers in the

More information

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2,

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2, Java Mouse Actions C&G criteria: 5.2.1, 5.4.1, 5.4.2, 5.6.2. The events so far have depended on creating Objects and detecting when they receive the event. The position of the mouse on the screen can also

More information

SAMPLE EXAM Exam 2 Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 5 November 2009

SAMPLE EXAM Exam 2 Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 5 November 2009 SAMPLE EXAM Exam 2 Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 5 November 2009 NAME (Printed) NAME (Signed) E-mail Exam Rules Show all your work. Your grade

More information

First Name: AITI 2004: Exam 2 July 19, 2004

First Name: AITI 2004: Exam 2 July 19, 2004 First Name: AITI 2004: Exam 2 July 19, 2004 Last Name: JSP Track Read Instructions Carefully! This is a 3 hour closed book exam. No calculators are allowed. Please write clearly if we cannot understand

More information

2IS45 Programming

2IS45 Programming Course Website Assignment Goals 2IS45 Programming http://www.win.tue.nl/~wsinswan/programmeren_2is45/ Rectangles Learn to use existing Abstract Data Types based on their contract (class Rectangle in Rectangle.

More information

class BankFilter implements Filter { public boolean accept(object x) { BankAccount ba = (BankAccount) x; return ba.getbalance() > 1000; } }

class BankFilter implements Filter { public boolean accept(object x) { BankAccount ba = (BankAccount) x; return ba.getbalance() > 1000; } } 9.12) public interface Filter boolean accept(object x); Describes any class whose objects can measure other objects. public interface Measurer double measure(object anobject); This program tests the use

More information

Java Foundations John Lewis Peter DePasquale Joe Chase Third Edition

Java Foundations John Lewis Peter DePasquale Joe Chase Third Edition Java Foundations John Lewis Peter DePasquale Joe Chase Third Edition Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world Visit us on the

More information

Computer Science 210: Data Structures. Intro to Java Graphics

Computer Science 210: Data Structures. Intro to Java Graphics Computer Science 210: Data Structures Intro to Java Graphics Summary Today GUIs in Java using Swing in-class: a Scribbler program READING: browse Java online Docs, Swing tutorials GUIs in Java Java comes

More information

CMP 326 Midterm Fall 2015

CMP 326 Midterm Fall 2015 CMP 326 Midterm Fall 2015 Name: 1) (30 points; 5 points each) Write the output of each piece of code. If the code gives an error, write any output that would happen before the error, and then write ERROR.

More information

AP CS Unit 11: Graphics and Events

AP CS Unit 11: Graphics and Events AP CS Unit 11: Graphics and Events This packet shows how to create programs with a graphical interface in a way that is consistent with the approach used in the Elevens program. Copy the following two

More information

CSIS 10A Practice Final Exam Solutions

CSIS 10A Practice Final Exam Solutions CSIS 10A Practice Final Exam Solutions 1) (5 points) What would be the output when the following code block executes? int a=3, b=8, c=2; if (a < b && b < c) b = b + 2; if ( b > 5 a < 3) a = a 1; if ( c!=

More information

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI Statics and GUI Dynamics 2 Statics: what s drawn on the screen Components buttons, labels, lists, sliders, menus,... Containers: components that contain

More information

Chapter 1 GUI Applications

Chapter 1 GUI Applications Chapter 1 GUI Applications 1. GUI Applications So far we've seen GUI programs only in the context of Applets. But we can have GUI applications too. A GUI application will not have any of the security limitations

More information

Graphical User Interfaces 2

Graphical User Interfaces 2 Graphical User Interfaces 2 CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2014 2011 Extending JFrame Dialog boxes Overview Ge

More information

Dartmouth College Computer Science 10, Fall 2015 Midterm Exam

Dartmouth College Computer Science 10, Fall 2015 Midterm Exam Dartmouth College Computer Science 10, Fall 2015 Midterm Exam 6.00-9.00pm, Monday, October 19, 2015 105 Dartmouth Hall Professor Prasad Jayanti Print your name: Print your section leader name: If you need

More information

G51PRG: Introduction to Programming Second semester Applets and graphics

G51PRG: Introduction to Programming Second semester Applets and graphics G51PRG: Introduction to Programming Second semester Applets and graphics Natasha Alechina School of Computer Science & IT nza@cs.nott.ac.uk Previous two lectures AWT and Swing Creating components and putting

More information

AP Computer Science Unit 13. Still More Graphics and Animation.

AP Computer Science Unit 13. Still More Graphics and Animation. AP Computer Science Unit 13. Still More Graphics and Animation. In this unit you ll learn about the following: Mouse Motion Listener Suggestions for designing better graphical programs Simple game with

More information

1 Looping Constructs (4 minutes, 2 points)

1 Looping Constructs (4 minutes, 2 points) Name: Career Account ID: Recitation#: 1 CS180 Spring 2011 Final Exam, 3 May, 2011 Prof. Chris Clifton Turn Off Your Cell Phone. Use of any electronic device during the test is prohibited. Time will be

More information

Exam: Applet, Graphics, Events: Mouse, Key, and Focus

Exam: Applet, Graphics, Events: Mouse, Key, and Focus Exam: Applet, Graphics, Events: Mouse, Key, and Focus Name Period A. Vocabulary: Complete the Answer(s) Column. Avoid ambiguous terms such as class, object, component, and container. Term(s) Question(s)

More information

CS2110. GUIS: Listening to Events

CS2110. GUIS: Listening to Events CS2110. GUIS: Listening to Events Also anonymous classes Download the demo zip file from course website and look at the demos of GUI things: sliders, scroll bars, combobox listener, etc 1 mainbox boardbox

More information

Graphical User Interfaces 2

Graphical User Interfaces 2 Graphical User Interfaces 2 CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2011 Extending JFrame Dialog boxes Ge?ng user input Overview Displaying message or error Listening for

More information

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

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. SOLUTION HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2006 FINAL EXAMINATION 7pm to 10pm, 19 DECEMBER 2006, Jeffrey Hall 1 st Floor Instructor:

More information

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

Queen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb Queen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb HAND IN Answers recorded on Examination paper This examination is THREE HOURS

More information

First Name: AITI 2004: Exam 2 July 19, 2004

First Name: AITI 2004: Exam 2 July 19, 2004 First Name: AITI 2004: Exam 2 July 19, 2004 Last Name: Standard Track Read Instructions Carefully! This is a 3 hour closed book exam. No calculators are allowed. Please write clearly if we cannot understand

More information

Class 16: The Swing Event Model

Class 16: The Swing Event Model Introduction to Computation and Problem Solving Class 16: The Swing Event Model Prof. Steven R. Lerman and Dr. V. Judson Harward 1 The Java Event Model Up until now, we have focused on GUI's to present

More information

Method Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is

Method Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is INDEX Event Handling. Key Event. Methods Of Key Event. Example Of Key Event. Mouse Event. Method Of Mouse Event. Mouse Motion Listener. Example of Mouse Event. Event Handling One of the key concept in

More information

Final Examination Semester 2 / Year 2011

Final Examination Semester 2 / Year 2011 Southern College Kolej Selatan 南方学院 Final Examination Semester 2 / Year 2011 COURSE COURSE CODE TIME DEPARTMENT LECTURER : JAVA PROGRAMMING : PROG1114 : 2 1/2 HOURS : COMPUTER SCIENCE : LIM PEI GEOK Student

More information

Name: Checked: Learn about listeners, events, and simple animation for interactive graphical user interfaces.

Name: Checked: Learn about listeners, events, and simple animation for interactive graphical user interfaces. Lab 15 Name: Checked: Objectives: Learn about listeners, events, and simple animation for interactive graphical user interfaces. Files: http://www.csc.villanova.edu/~map/1051/chap04/smilingface.java http://www.csc.villanova.edu/~map/1051/chap04/smilingfacepanel.java

More information

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners GUI (Graphic User Interface) Programming Part 2 (Chapter 8) Chapter Goals To understand the Java event model To install action and mouse event listeners To accept input from buttons, text fields, and the

More information

EXAMINATIONS 2010 END-OF-YEAR COMP 102 INTRODUCTION TO COMPUTER PROGRAM DESIGN

EXAMINATIONS 2010 END-OF-YEAR COMP 102 INTRODUCTION TO COMPUTER PROGRAM DESIGN T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2010 END-OF-YEAR COMP 102 INTRODUCTION TO

More information

THE UNIVERSITY OF AUCKLAND

THE UNIVERSITY OF AUCKLAND THE UNIVERSITY OF AUCKLAND SECOND SEMESTER, 2008 Campus: Tamaki COMPUTER SCIENCE TEST Software Design and Construction (Time allowed: 60 minutes) NOTE: Attempt ALL questions. Write your answers in the

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. CSIS 10A PRACTICE FINAL EXAM SOLUTIONS Closed Book Closed Computer 3 Sheets of Notes Allowed MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) What

More information

EXCEPTIONS & GUI. Errors are signals that things are beyond help. Review Session for. -Ankur Agarwal

EXCEPTIONS & GUI. Errors are signals that things are beyond help. Review Session for. -Ankur Agarwal Review Session for EXCEPTIONS & GUI -Ankur Agarwal An Exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions. Errors are signals

More information

HW#1: Pencil Me In Status!? How was Homework #1? Reminder: Handouts. Homework #2: Java Draw Demo. 3 Handout for today! Lecture-Homework mapping.

HW#1: Pencil Me In Status!? How was Homework #1? Reminder: Handouts. Homework #2: Java Draw Demo. 3 Handout for today! Lecture-Homework mapping. HW#1: Pencil Me In Status!? CS193J: Programming in Java Summer Quarter 2003 Lecture 6 Inner Classes, Listeners, Repaint Manu Kumar sneaker@stanford.edu How was Homework #1? Comments please? SITN students

More information

ECE 462 Object-Oriented Programming using C++ and Java. Key Inputs in Java Games

ECE 462 Object-Oriented Programming using C++ and Java. Key Inputs in Java Games ECE 462 Object-Oriented Programming g using C++ and Java Key Inputs in Java Games Yung-Hsiang Lu yunglu@purdue.edu d YHL Java Key Input 1 Handle Key Events have the focus of the keyboard inputs by calling

More information

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

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2006 FINAL EXAMINATION 7pm to 10pm, 19 DECEMBER 2006, Jeffrey Hall 1 st Floor Instructor: Alan

More information

CS 2113 Software Engineering

CS 2113 Software Engineering CS 2113 Software Engineering Java 5 - GUIs Import the code to intellij https://github.com/cs2113f18/template-j-5.git Professor Tim Wood - The George Washington University Class Hierarchies Abstract Classes

More information

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

CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2012 CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2012 Name: This exam consists of 6 problems on the following 8 pages. You may use your double- sided hand- written 8 ½ x 11 note sheet

More information

Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

Fall CS 101: Test 2 Name UVA  ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17. Grading Page 1 / 4 Page3 / 20 Page 4 / 13 Page 5 / 10 Page 6 / 26 Page 7 / 17 Page 8 / 10 Total / 100 1. (4 points) What is your course section? CS 101 CS 101E Pledged Page 1 of 8 Pledged The following

More information

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread G51PGP Programming Paradigms Lecture 008 Inner classes, anonymous classes, Swing worker thread 1 Reminder subtype polymorphism public class TestAnimals public static void main(string[] args) Animal[] animals

More information

Final Examination Semester 2 / Year 2012

Final Examination Semester 2 / Year 2012 Final Examination Semester 2 / Year 2012 COURSE : JAVA PROGRAMMING COURSE CODE : PROG1114 TIME : 2 1/2 HOURS DEPARTMENT : COMPUTER SCIENCE LECTURER : LIM PEI GEOK Student s ID : Batch No. : Notes to candidates:

More information

Java - Applets. public class Buttons extends Applet implements ActionListener

Java - Applets. public class Buttons extends Applet implements ActionListener Java - Applets Java code here will not use swing but will support the 1.1 event model. Legacy code from the 1.0 event model will not be used. This code sets up a button to be pushed: import java.applet.*;

More information

To gain experience using GUI components and listeners.

To gain experience using GUI components and listeners. Lab 5 Handout 7 CSCI 134: Fall, 2017 TextPlay Objective To gain experience using GUI components and listeners. Note 1: You may work with a partner on this lab. If you do, turn in only one lab with both

More information

CS2110. GUIS: Listening to Events. Anonymous functions. Anonymous functions. Anonymous functions. Checkers.java. mainbox

CS2110. GUIS: Listening to Events. Anonymous functions. Anonymous functions. Anonymous functions. Checkers.java. mainbox CS2110. GUIS: Listening to Events Lunch with instructors: Visit pinned Piazza post. A4 due tonight. Consider taking course S/U (if allowed) to relieve stress. Need a letter grade of C- or better to get

More information

CS2110. GUIS: Listening to Events Also anonymous classes versus Java 8 functions. Anonymous functions. Anonymous functions. Anonymous functions

CS2110. GUIS: Listening to Events Also anonymous classes versus Java 8 functions. Anonymous functions. Anonymous functions. Anonymous functions CS2110. GUIS: Listening to Events Also anonymous classes versus Java 8 functions Lunch with instructors: Visit Piazza pinned post to reserve a place Download demo zip file from course website, look at

More information

CS2110. GUIS: Listening to Events

CS2110. GUIS: Listening to Events CS2110. GUIS: Listening to Events Lunch with instructors: Visit pinned Piazza post. A4 due tonight. Consider taking course S/U (if allowed) to relieve stress. Need a letter grade of C- or better to get

More information

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components CS112-Section2 Hakan Guldas Burcin Ozcan Meltem Kaya Muge Celiktas Notes of 6-8 May Graphics Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how

More information

Outline. More on the Swing API Graphics: double buffering and timers Model - View - Controller paradigm Applets

Outline. More on the Swing API Graphics: double buffering and timers Model - View - Controller paradigm Applets Advanced Swing Outline More on the Swing API Graphics: double buffering and timers Model - View - Controller paradigm Applets Using menus Frame menus add a menu bar to the frame (JMenuBar) add menus to

More information

First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010

First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010 First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010 NAME (Printed) NAME (Signed) E-mail Exam Rules Show all your work. Your grade will be

More information

COMP 102: Test 2 Model Solutions

COMP 102: Test 2 Model Solutions Family Name:.......................... Other Names:.......................... ID Number:............................ Instructions Time allowed: 45 minutes There are 45 marks in total. Answer all the questions.

More information

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

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. QUEEN'S UNIVERSITY SCHOOL OF COMPUTING HAND IN Answers Are Recorded on Question Paper CMPE212, FALL TERM, 2012 FINAL EXAMINATION 18 December 2012, 2pm Instructor: Alan McLeod If the instructor is unavailable

More information

Final Examination Semester 2 / Year 2010

Final Examination Semester 2 / Year 2010 Southern College Kolej Selatan 南方学院 Final Examination Semester 2 / Year 2010 COURSE : JAVA PROGRAMMING COURSE CODE : PROG1114 TIME : 2 1/2 HOURS DEPARTMENT : COMPUTER SCIENCE LECTURER : LIM PEI GEOK Student

More information

Advanced Java Unit 6: Review of Graphics and Events

Advanced Java Unit 6: Review of Graphics and Events Advanced Java Unit 6: Review of Graphics and Events This is a review of the basics of writing a java program that has a graphical interface. To keep things simple, all of the graphics programs will follow

More information

MIT AITI Swing Event Model Lecture 17

MIT AITI Swing Event Model Lecture 17 MIT AITI 2004 Swing Event Model Lecture 17 The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the user. But how do GUIs interact with users? How do applications

More information

THE UNIVERSITY OF AUCKLAND

THE UNIVERSITY OF AUCKLAND VERSION 00000001 COMPSCI 230 THE UNIVERSITY OF AUCKLAND SECOND SEMESTER, 2011 Campus: City Computer Science TEST Software Design and Construction (Time Allowed: 50 MINUTES) Note: The use of calculators

More information

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

1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall (total 7 pages) 1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall 2002 (total 7 pages) Name: TA s Name: Tutorial: For Graders Question 1 Question 2 Question 3 Total Problem 1 (20 points) True or

More information

CompSci 105 S2 C - ASSIGNMENT TWO -

CompSci 105 S2 C - ASSIGNMENT TWO - CompSci 105 S2 C - ASSIGNMENT TWO - The work done on this assignment must be your own work. Think carefully about any problems you come across, and try to solve them yourself before you ask anyone else

More information

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

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver Building a GUI in Java with Swing CITS1001 extension notes Rachel Cardell-Oliver Lecture Outline 1. Swing components 2. Building a GUI 3. Animating the GUI 2 Swing A collection of classes of GUI components

More information

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

Midterm Test II Object Oriented Programming in Java Computer Science, University of Windsor Fall 2014 Time 2 hours. Answer all questions Midterm Test II 60-212 Object Oriented Programming in Java Computer Science, University of Windsor Fall 2014 Time 2 hours Answer all questions Name : Student Id # : Only an unmarked copy of a textbook

More information

An array is a type of variable that is able to hold more than one piece of information under a single variable name.

An array is a type of variable that is able to hold more than one piece of information under a single variable name. Arrays An array is a type of variable that is able to hold more than one piece of information under a single variable name. Basically you are sub-dividing a memory box into many numbered slots that can

More information

The AWT Event Model 9

The AWT Event Model 9 The AWT Event Model 9 Course Map This module covers the event-based GUI user input mechanism. Getting Started The Java Programming Language Basics Identifiers, Keywords, and Types Expressions and Flow

More information

1 Definitions & Short Answer (5 Points Each)

1 Definitions & Short Answer (5 Points Each) Fall 2013 Final Exam COSC 117 Name: Write all of your responses on these exam pages. If you need more space please use the backs. Make sure that you show all of your work, answers without supporting work

More information

Introduction. Introduction

Introduction. Introduction Introduction Many Java application use a graphical user interface or GUI (pronounced gooey ). A GUI is a graphical window or windows that provide interaction with the user. GUI s accept input from: the

More information

CSIS 10A PRACTICE FINAL EXAM Name Closed Book Closed Computer 3 Sheets of Notes Allowed

CSIS 10A PRACTICE FINAL EXAM Name Closed Book Closed Computer 3 Sheets of Notes Allowed CSIS 10A PRACTICE FINAL EXAM Name Closed Book Closed Computer 3 Sheets of Notes Allowed MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) What would

More information

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

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 5: Will be an open-ended Swing project. "Programming Contest"

More information

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!

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! Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Why are we studying Swing? 1. Useful & fun! 2. Good application of OOP techniques

More information

CSSE 220. Event Based Programming. Check out EventBasedProgramming from SVN

CSSE 220. Event Based Programming. Check out EventBasedProgramming from SVN CSSE 220 Event Based Programming Check out EventBasedProgramming from SVN Interfaces are contracts Interfaces - Review Any class that implements an interface MUST provide an implementation for all methods

More information

COSC 123 Computer Creativity. Graphics and Events. Dr. Ramon Lawrence University of British Columbia Okanagan

COSC 123 Computer Creativity. Graphics and Events. Dr. Ramon Lawrence University of British Columbia Okanagan COSC 123 Computer Creativity Graphics and Events Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Key Points 1) Draw shapes, text in various fonts, and colors. 2) Build

More information

Graphic User Interfaces. - GUI concepts - Swing - AWT

Graphic User Interfaces. - GUI concepts - Swing - AWT Graphic User Interfaces - GUI concepts - Swing - AWT 1 What is GUI Graphic User Interfaces are used in programs to communicate more efficiently with computer users MacOS MS Windows X Windows etc 2 Considerations

More information

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2013

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2013 CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2013 Name: This exam consists of 7 problems on the following 6 pages. You may use your single- side hand- written 8 ½ x 11 note sheet during the

More information

PESIT Bangalore South Campus

PESIT Bangalore South Campus INTERNAL ASSESSMENT TEST II Date : 20-09-2016 Max Marks: 50 Subject & Code: JAVA & J2EE (10IS752) Section : A & B Name of faculty: Sreenath M V Time : 8.30-10.00 AM Note: Answer all five questions 1) a)

More information

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction CSC 160 LAB 8-1 DIGITAL PICTURE FRAME PROFESSOR GODFREY MUGANDA DEPARTMENT OF COMPUTER SCIENCE 1. Introduction Download and unzip the images folder from the course website. The folder contains 28 images

More information

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT CSE 143 Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/

More information

SINGLE EVENT HANDLING

SINGLE EVENT HANDLING SINGLE EVENT HANDLING Event handling is the process of responding to asynchronous events as they occur during the program run. An event is an action that occurs externally to your program and to which

More information

Java Coordinate System

Java Coordinate System Java Graphics Drawing shapes in Java such as lines, rectangles, 3-D rectangles, a bar chart, or a clock utilize the Graphics class Drawing Strings Drawing Lines Drawing Rectangles Drawing Ovals Drawing

More information

McGill University School of Computer Science COMP-202A Introduction to Computing 1

McGill University School of Computer Science COMP-202A Introduction to Computing 1 McGill University School of Computer Science COMP-202A Introduction to Computing 1 Midterm Exam Thursday, October 26, 2006, 18:00-20:00 (6:00 8:00 PM) Instructors: Mathieu Petitpas, Shah Asaduzzaman, Sherif

More information

ANSWER KEY First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010

ANSWER KEY First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010 ANSWER KEY First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010 1. True or False: (a) T An algorithm is a a set of directions for solving

More information

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn Java & Graphical User Interface II Wang Yang wyang AT njnet.edu.cn Outline Review of GUI (first part) What is Event Basic Elements of Event Programming Secret Weapon - Inner Class Full version of Event

More information

Object Oriented Programming 2013/14. Final Exam June 20, 2014

Object Oriented Programming 2013/14. Final Exam June 20, 2014 Object Oriented Programming 2013/14 Final Exam June 20, 2014 Directions (read carefully): CLEARLY print your name and ID on every page. The exam contains 8 pages divided into 4 parts. Make sure you have

More information

CS 180 Fall 2006 Exam II

CS 180 Fall 2006 Exam II CS 180 Fall 2006 Exam II There are 20 multiple choice questions. Each one is worth 2 points. There are 3 programming questions worth a total of 60 points. Answer the multiple choice questions on the bubble

More information

Name Section. CS 21a Introduction to Computing I 1 st Semester Final Exam

Name Section. CS 21a Introduction to Computing I 1 st Semester Final Exam CS a Introduction to Computing I st Semester 00-00 Final Exam Write your name on each sheet. I. Multiple Choice. Encircle the letter of the best answer. ( points each) Answer questions and based on the

More information

1st Semester Examinations CITS1001 3

1st Semester Examinations CITS1001 3 1st Semester Examinations CITS1001 3 Question 1 (10 marks) Write a Java class Student with three fields: name, mark and maxscore representing a student who has scored mark out of maxscore. The class has

More information

CS 134 Test Program #2

CS 134 Test Program #2 CS 134 Test Program #2 Sokoban Objective: Build an interesting game using much of what we have learned so far. This second test program is a computer maze game called Sokoban. Sokoban is a challenging

More information

ANSWER KEY Exam 2 Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 5 November 2009

ANSWER KEY Exam 2 Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 5 November 2009 ANSWER KEY Exam 2 Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 5 November 2009 1. True or False: (a) T In Alice, there is an event that is processed as long

More information

CSIS 10A Assignment 14 SOLUTIONS

CSIS 10A Assignment 14 SOLUTIONS CSIS 10A Assignment 14 SOLUTIONS Read: Chapter 14 Choose and complete any 10 points from the problems below, which are all included in the download file on the website. Use BlueJ to complete the assignment,

More information

FirstSwingFrame.java Page 1 of 1

FirstSwingFrame.java Page 1 of 1 FirstSwingFrame.java Page 1 of 1 2: * A first example of using Swing. A JFrame is created with 3: * a label and buttons (which don t yet respond to events). 4: * 5: * @author Andrew Vardy 6: */ 7: import

More information

UCLA PIC 20A Java Programming

UCLA PIC 20A Java Programming UCLA PIC 20A Java Programming Instructor: Ivo Dinov, Asst. Prof. In Statistics, Neurology and Program in Computing Teaching Assistant: Yon Seo Kim, PIC University of California, Los Angeles, Summer 2002

More information

CSIS 10A Assignment 7 SOLUTIONS

CSIS 10A Assignment 7 SOLUTIONS CSIS 10A Assignment 7 SOLUTIONS Read: Chapter 7 Choose and complete any 10 points from the problems below, which are all included in the download file on the website. Use BlueJ to complete the assignment,

More information

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

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Events and Listeners CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides

More information