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

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

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

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

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

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

CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2012

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

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

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

CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2013

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

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

Midterm assessment - MAKEUP Fall 2010

CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2014

CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011

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

More on inheritance CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2014

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

More on methods and variables. Fundamentals of Computer Science Keith Vertanen

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

AP CS Unit 11: Graphics and Events

G51PGP Programming Paradigms. Lecture 009 Concurrency, exceptions

CIS 110 Spring 2013 Final Exam, 29 April 2013, Answer Key. Miscellaneous

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

University of Cape Town Department of Computer Science Computer Science CSC1017F

CSCI 135 Final Fall Problem Points Score Total 100

Graphical User Interfaces 2

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

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

Check out ThreadsIntro project from SVN. Threads and Animation

1 Looping Constructs (4 minutes, 2 points)

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

RAIK 183H Examination 2 Solution. November 10, 2014

Name: CSC143 Exam 1 1 CSC 143. Exam 1. Write also your name in the appropriate box of the scantron

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

Threads. Fundamentals of Computer Science

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

CMP 326 Midterm Fall 2015

Multithreading Pearson Education, Inc. All rights reserved.

Exam 1 - (20 points)

COS 126 Midterm 1 Written Exam Spring 2015

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:

COM S 211/ENGRD 211 May 15, 2003

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

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

CONDITIONAL EXECUTION

Final Exam CS 251, Intermediate Programming December 13, 2017

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

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

CS-140 Fall 2017 Test 2 Version A Nov. 29, 2017

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:

CSCI 201L Midterm Written SOLUTION Fall % of course grade

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each

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

public static boolean isoutside(int min, int max, int value)

Practice Midterm 1. Problem Points Score TOTAL 50

CS Exam 1 Review Suggestions

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

CS 351 Design of Large Programs Threads and Concurrency

Definition: A thread is a single sequential flow of control within a program.

CS 1331 Exam 1 ANSWER KEY

Introduction to Programming Using Java (98-388)

CIS 110 Spring 2012 Final Exam, 7 May 2012, Answer Key. Miscellaneous

CS 307 Midterm 2 Spring 2011

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

CS61B, Spring 2003 Discussion #17 Amir Kamil UC Berkeley 5/12/03

1.00 Introduction to Computers and Engineering Problem Solving. Final Examination - May 19, 2004

Threads Chate Patanothai

IT 313 Advanced Application Development Midterm Exam

CS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

Software Practice 1 - Multithreading

Introduction This assignment will ask that you write a simple graphical user interface (GUI).

Static methods. Not actually a valid Java static method. Fundamentals of Computer Science Keith Vertanen

York University AK/ITEC OBJECT-BASED PROGRAMMING. Midterm Test Sample. Examiner: S.Y. Chen Duration: One Hour and Fifteen Minutes

Michele Van Dyne MUS 204B Threads

Final Exam Practice. Partial credit will be awarded.

CISC 4700 L01 Network & Client-Server Programming Spring Cowell Chapter 15: Writing Threaded Applications

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

CS 113 PRACTICE FINAL

CSC 1351 The Twelve Hour Exam From Hell

We are on the GUI fast track path

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

Programming Languages and Techniques (CIS120)

Graphical User Interfaces 2

Midterm Exam CS 251, Intermediate Programming March 6, 2015

CS 455 Midterm Exam 1 Fall 2015 [Bono] Thursday, Oct. 1, 2015

Multitasking Multitasking allows several activities to occur concurrently on the computer. A distinction is usually made between: Process-based multit

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

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

Multithreaded Programming

Instructions. This exam has 7 questions, worth 10 points each. You have 50 minutes.

CIS 110 Spring 2014 Introduction to Computer Programming 12 May 2014 Final Exam Answer Key

Throughout the exam, write concisely and underline key words or phrases. Have fun! Exam 2. Week 7 (Winter 2013). Dr. Yoder. Sec 031.

CIT Special final examination

NATIONAL UNIVERSITY OF SINGAPORE

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

CIS 110 Introduction to Computer Programming Spring 2016 Midterm

CSci 1103 Final. Name: Student ID:

Final Exam CS 152, Computer Programming Fundamentals December 5, 2014

Topic 7: Algebraic Data Types

Transcription:

CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2015 Name: This exam consists of 6 problems on the following 6 pages. You may use your double- sided hand- written 8 ½ x 11 note sheet during the exam. No computers, mobile devices, cell phones, or other communication devices of any kind are permitted. If you have a question, raise your hand and I will stop by. Since partial credit is possible, please write legibly and show your work. Problem Points Score 1 10 2 10 3 10 4 10 5 10 6 10 Total 60 1

1. Input, output, classes (10 points). Consider the following program: public class Prob1 private boolean big = false; public Prob1(String str) big = (str.length() > 3); public String tostring() if (big) return "big! "; return "small! "; public static void main(string[] args) Prob1 a = new Prob1(args[0]); Prob1 b = new Prob1(args[1]); System.out.printf("%d: %s %s\n", args.length, a, b); Below are five example executions of the program. Give the output produced by the program. If the given input would cause a runtime error, write "error". Command line Output % java Prob1 the % java Prob1 the cat % java Prob1 the cat sat % java Prob1 a frog % java Prob1-485 12 2

2. Multidimensional arrays, inheritance (10 points). Fill in the missing code in the following program that animates 0's and 1's that stay still, drip down, or jiggle by making use of the Label, LabelDrip, and LabelJiggle classes. Here is an example run along with the class hierarchy and APIs: public static void main(string[] args) final int COLS = Integer.parseInt(args[0]); // First arg is rows of 0/1's final int ROWS = Integer.parseInt(args[0]); // Second arg is columns of 0/1's [][] labels = ; // Create 2D array for (int col = 0; col < COLS; col++) for (int row = 0; row < ROWS; row++) double x = 1.0 / COLS * (col + 0.5); double y = 1.0 / ROWS * (row + 0.5); String num = "0"; if ( ) // 50% chance of changing num to "1" num = "1"; Label label = null; // Randomly create one of our three label data types double rand = Math.random(); if (rand < 0.333) label = ; // Normal else if (rand < 0.666) label = ; // Dripping else label = ; // Jiggling ; // Put this label into 2D array // Loop forever // Omitted: clearing drawing window, setting pen color, sleep, etc. for (int col = 0; col < COLS; col++) for (int row = 0; row < ROWS; row++) // Ask labels to update positions // Ask labels to draw themselves 3

3. Regular expressions (10 points). Match the description of a set of strings on the left with the regular expression on the right that matches exactly this set of strings. For the purposes of this problem, assume the following definitions: Binary number consists of only the numbers 0 and 1, e.g. 101010 Hexadecimal number consists of only the numbers 0 through 9 plus the letters A through F (uppercase), e.g. 05F6A Also you can assume the empty string is not considered a binary or hexadecimal number. Letters will be used exactly once. Hexadecimal numbers with exactly two digits Binary numbers with an even number of digits Binary numbers with an odd number of digits Binary numbers in which the sequence 010 appears at least once Hexadecimal numbers that end with F and are more than three digits long Hexadecimal numbers that end with F and are at most three digits long A. [0-9A- F]3,F B. ([01][01])+ C. [0-9A- F][0-9A- F] D. [01]*0[01]*0[01]* E. [0-9A- F]0,2F F. [01]([01][01])* G. [01]*010[01]* H. [0-9]+ I. [01]*1[01]* J. F F[0-9A- F]*F Binary numbers that have at least two zeros Binary numbers that have at least a single one Hexadecimal numbers that start and end with F Hexadecimal numbers that do not contain the digits A- F 4

4. GUIs, threading (10 points). You are building a simple stopwatch GUI. The GUI has a single button that starts labeled 0.00. When the user click the button, it starts displaying the elapsed time in seconds to two decimal places. If the button is clicked again, the stopwatch halts and is left displaying the elapsed time since it was started. Clicking it again causes the timer to be reset and start counting up. Below is the GUI in action. Transitions with an arrow denote clicking the button. Transitions without an arrow are time passing. Put letters into the underlined spaces to create the described GUI. Letters may be used 0 or more times. public class Stopwatch private JButton button = ; private Stats stats = new Stats(); private boolean running = false; public Stopwatch() JFrame frame = new JFrame("Stopwatch"); frame.getcontentpane().add(button); button. ; Thread t = ; t.start(); frame. (150, 75); frame.setvisible(true); public void while (true) if (running) String t = String.format(, stats.elapsedtime()); button.settext(t); try Thread.sleep(10); catch (InterruptedException e) public void running = ; if (running) stats.reset(); public static void main(string[] args) Stopwatch watch = new Stopwatch(); A. extends B. implements C. false D. true E.!running F. Runnable, ActionListener G. Comparable H. new JButton("0.00"); I. setenabled J. setsize K. settext L. add(button); M. reset(button); N. addmouselistener(this); O. addactionlistener(this); P. addactionlistener(button); Q. actionperformed(actionevent e) R. mousepressed(mouseevent e) S. run() T. new Thread(); U. new Thread(this); V. "%2d" W. "%e" X. "%.2f" Y. JFrame Z. JPanel 5

5. Algorithms, conditionals (10 points). Fill in the missing code so each method behaves as described. // Returns the minimum value in the array vals. // Returns Double.NaN if vals has a length of zero. public static double min(double [] vals) return Double.NaN; double result = vals[0]; for (int i = 1; i < vals.length; i++) result = vals[i]; return result; // Returns true if the vals array contains at least one even number. // Returns false if all numbers are odd, or if vals has a length of zero. public static boolean containsevennumber(int [] vals) for (int i : vals) return true; return false; // Returns true if all elements in vals are in interval [low, high] (inclusive). // Returns false if any number in vals is not in [low, high]. public static boolean allinrange(int [] vals, int low, int high) for (int i : vals) return false; return true; // Returns true if vals1 and vals2 have at least one value in common. // Returns false if no number is shared, or if vals1 and/or vals2 contains no values. public static boolean intersects(int [] vals1, int [] vals2) for (int i : vals1) for (int j : vals2) return true; return false; 6

6. Classes (10 points). Assume you have the following hierarchy of Java classes (some details are omitted): public abstract class Item private String name = ""; public String getname() return name; public abstract String tostring(); public abstract class Product extends Item private double cost = 0.0; public double getcost() return cost; public boolean isfree() return cost > 0.0; public class Available extends Product private int quantity = 0; public int getquantity() return quantity; public void buy(int amount) quantity - = amount; public String tostring() return String.format("%d %s %.2f", quantity, getname(), getcost()); public class Discontinued extends Product /* stuff */ public class Recalled extends Product /* stuff */ a) What method(s) must be implemented in Discontinued and Recalled in order for them to compile? b) Circle the concrete class(es) you could successfully instantiate an object of: Item Product Available Discontinued Recalled c) Circle the concrete class(es) you could instantiate and add to the following variable named list: ArrayList<Product> list = new ArrayList<Product>(); Item Product Available Discontinued Recalled d) Given list from part c, provide a code snippet that prints out a string representation of each item. e) Circle the inherited method(s) that you could override in the class Recalled. int getquantity() void buy(int amount) double getcost() boolean isfree() String getname() 7