UTM CSC207: Midterm Examination October 28, 2011

Similar documents
Midterm assessment - MAKEUP Fall 2010

CMP 326 Midterm Fall 2015

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

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

Points Missed on Page page 1 of 8

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

SE1021 Exam 2. When returning your exam, place your note-sheet on top. Page 1: This cover. Page 2 (Multiple choice): 10pts

Give one example where you might wish to use a three dimensional array

Systems Programming. Bachelor in Telecommunication Technology Engineering Bachelor in Communication System Engineering Carlos III University of Madrid

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

Swing - JLabel. Adding a text (and HTML) labels to a GUI

H212 Introduction to Software Systems Honors

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

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

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

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

SampleApp.java. Page 1

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

MIT AITI Swing Event Model Lecture 17

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

Ryerson University Vers HAL6891A-05 School of Computer Science CPS109 Midterm Test Fall 05 page 1 of 6

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

ENGR 2710U Midterm Exam UOIT SOLUTION SHEET

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

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

Please note that if you write the mid term in pencil, you will not be allowed to submit a remark request.

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

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

Instance Method Development Demo

This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for computing and/or communicating) is NOT permitted.

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

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

Unit 10: Sorting/Searching/Recursion

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.

Swing from A to Z Some Simple Components. Preface

Object-Oriented Software Engineering Re-exam, 2012 (Also Object-Oriented Analysis, Design and Programming, Re-exam, 2012)

JApplet. toy example extends. class Point { // public int x; public int y; } p Point 5.2. Point. Point p; p = new Point(); instance,

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1

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

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

Birkbeck (University of London) Software and Programming 1 In-class Test Mar Answer ALL Questions

public int calculatedamage() { // Generate and return the damage inflicted on ship }

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

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

CSC 207H Fall L Java Quiz Duration 25 minutes Aids allowed: none

RAIK 183H Examination 2 Solution. November 11, 2013

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

University of Cape Town Department of Computer Science Computer Science CSC1017F

Swing - JButton. Adding buttons to the main window

Graphical User Interfaces (GUIs)

CS 102/107 - Introduction to Programming Midterm Exam #2 - Prof. Reed Spring 2011

Good Luck! Student Number: Last Name: First Name: Signature:

Lecture 9. Lecture

PART1: Choose the correct answer and write it on the answer sheet:

CS 180 Fall 2006 Exam II

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

York University. AP/ITEC Section M INTRODUCTION TO DATA STRUCTURES Winter Midterm Test

Object-Oriented Software Engineering (Re-exam for Object-Oriented Analysis, Design and Programming)

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

CS180 Spring 2010 Exam 2 Solutions, 29 March, 2010 Prof. Chris Clifton

Multimedia Programming

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

Java Assignment 3: Loop Practice Ver 3.0 Last Updated: 12/1/2015 8:57 AM

University of Palestine. Mid Exam Total Grade: 100

CSci 1103 Final. Name: Student ID:

Graphical Interfaces

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

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.

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

No Aids Allowed. Do not turn this page until you have received the signal to start. Read this entire page or you ll miss the bonus question.

READ AND OBSERVE THE FOLLOWING RULES:

G51PGP Programming Paradigms. Lecture 009 Concurrency, exceptions

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

COMP 102: Test 2 Model Solutions

Solution register itself

State Application Using MVC

CS211 GUI Dynamics. Announcements. Motivation/Overview. Example Revisted

Attempt FOUR questions Marking Scheme Time: 120 mins

CMPS 12A - Winter 2002 Final Exam A March 16, Name: ID:

Java for Interfaces and Networks (DT3010, HT10)

CS 101 Spring 2007 Midterm 2 Name: ID:


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

SINGLE EVENT HANDLING

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

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

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

RAIK 183H Examination 2 Solution. November 10, 2014

ESC101 : Fundamental of Computing

CMPSCI 187 Midterm 1 (Feb 17, 2016)

Final Examination Semester 2 / Year 2010

Hanley s Survival Guide for Visual Applications with NetBeans 2.0 Last Updated: 5/20/2015 TABLE OF CONTENTS

Java for Interfaces and Networks (DT3029)

RobotPlanning.java Page 1

Agenda. Container and Component

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

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

CS Exam 3 - Spring 2010

Transcription:

UTM CSC207: Midterm Examination October 28, 2011 Student Number: Last Name: First Name: This 110 minute exam consists of 6 double sided pages. You are allowed two 8 1 2 11 double sided aid sheets. 1. [10 Marks: Medium] Class Balloon has constructor Balloon(int capacity, String color) which constructs an empty Balloon with the given capacity and color. Other Balloon methods include inflate(int amount) and deflate(int amount). If a Balloon is over inflated its ispopped() method returns true. Complete the class below class UseBalloon { // Create static method bunchofballoons(int count, String color). This method returns // an array of count Balloons with capacities 0,1,2,...,count-1, all with the given color. // Create static method inflateall which takes an array of Balloons and inflates // them all by a specified amount. Remember, if a is an array, a.length is its length. // YOUR CODE GOES HERE 1

public static void main(string [] args){ // Create two Balloons, a "red" one with capacity 10 and a "green" one with // capacity 20. Take turns inflating each of them a few times and cause one to pop. // Finally, ask each Balloon if they are popped, printing out an approprite message. // Use methods bunchofballoons to create an array of 20 Balloons. Use method inflateall // to inflate all Balloons in the array by 10 units. // YOUR CODE GOES HERE 2

2. [10 Marks: Medium] Write the classes Statistic, SumStatistic, AverageStatistic and MaxStatistic described below: IMPORTANT: Your classes should behave as in the UseStatistics class in the Appendix to this midterm. A Statistic has a single value (it is a floating point number). You can ask an instance for the value by calling getvalue. You can update the value by calling addvalue, for example, addvalue(3.4). For a Statistic, addvalue replaces the Statistics value with the new value. The default constructor for a Statistic sets value to 0. SumStatistic is a Statistic. The value of a SumStatistic is the sum of all values added to it. AverageStatistic is a Statistic. The value of an AverageStatistic is the average of all the values added to it. AverageStatistic should count the number of numbers added to it. It should also keep track of the sum of the numbers added to it. MaxStatistic is a Statistic. The value of a MaxStatistic is the maximum of all values added to it. 3

(continued...) 4

3. [15 Marks: Medium] In the Appendix to this exam, you will find some sample UML Class diagrams as well as interface StateHolder and classes ClickState, FirstClickState, SecondClickState and GUIController. (a) In the space below, draw the UML Class diagram for these 5 classes. 5

(b) Describe (from the users point of view) what happens when they run GUIController. Draw the GUI and describe what happens when the user plays with it. 6

(c) Briefly describe how the code actually works. 7

(Extra Space) 8

(Extra Space) 9

Appendix... /** Demonstrate the use of the Statistics classes **/ /** Note: The output is written below the calls to test **/ public class UseStatistics { public static void main(string [] args){ Statistic stat=new Statistic(); UseStatistics.test(stat); // Prints... // 0.0 1.0 2.0 3.0 4.0 5.0 SumStatistic sumstat=new SumStatistic(); UseStatistics.test(sumStat); // Prints... // 0.0 1.0 3.0 6.0 10.0 15.0 MaxStatistic maxstat=new MaxStatistic(); UseStatistics.test(maxStat); // Prints... // 0.0 1.0 2.0 3.0 4.0 5.0 AverageStatistic avgstat=new AverageStatistic(); UseStatistics.test(avgStat); // Prints... (sum/count=average) // 0.0/1=0.0 1.0/2=0.5 3.0/3=1.0 6.0/4=1.5 10.0/5=2.0 15.0/6=2.5 System.out.println(""+avgStat.getSum()); // Prints: 15.0 System.out.println(""+avgStat.getCount()); // Prints: 6 System.out.println(""+avgStat.getValue()); // Prints: 2.5 public static void test(statistic s){ for(int i=0;i<=5;i++){ s.addvalue(i); System.out.print(s+" "); System.out.println(); 10

Appendix (continued)... Some sample UML Class diagrams. In the second diagram, + indicates public, - indicates private. /** ----------- StateHolder --------------------------- **/ public interface StateHolder { public void setstate(clickstate s); public void announce(string first, String second); /** ----------- ClickState --------------------------- **/ public class ClickState { public void handleclick(stateholder s, String which){ /** ----------- FirstClickState --------------------------- **/ public class FirstClickState extends ClickState { public void handleclick(stateholder s, String which) { s.setstate(new SecondClickState(which)); /** ----------- SecondClickState --------------------------- **/ public class SecondClickState extends ClickState { private String firstclick; public SecondClickState(String firstclick){ this.firstclick=firstclick; public void handleclick(stateholder s, String secondclick) { s.announce(firstclick, secondclick); s.setstate(new FirstClickState()); 11

Appendix (continued)... /** ------------ GUIController ----------------------- **/ // Lots of imports omitted public class GUIController implements ActionListener, StateHolder { private JLabel answer = new JLabel("No Button presses yet!", JLabel.CENTER); private ClickState cs=new FirstClickState(); GUIController() { JFrame f = new JFrame("Second Click Frame"); f.setdefaultcloseoperation(jframe.exit_on_close); Container c = f.getcontentpane(); c.setlayout(new FlowLayout()); for (int i = 0; i < 5; i++) { JButton b = new JButton("" + i); b.addactionlistener(this); c.add(b); c.add(answer); f.pack(); f.setvisible(true); public static void main(string[] args) { javax.swing.swingutilities.invokelater(new Runnable() { public void run() { GUIController gui = new GUIController(); ); public void actionperformed(actionevent arg0) { // Note: arg0.getactioncommand() returns the String // label on the JButton (in this case) cs.handleclick(this, arg0.getactioncommand()); public void setstate(clickstate s) { this.cs=s; public void announce(string first, String second) { this.answer.settext(first+" then "+second); 12