Problem Points Score Grader Total 100

Similar documents
Problem Points Score Grader Total 75

Problem Points Score Grader Total 75

Final Examination CS 125 Introduction to Computer Science Fall Hours

Spring 2012 Final Examination 3 hours CS 125 Introduction to Computer Science

Practice Midterm 1 Answer Key

Practice Midterm 1. Problem Points Score TOTAL 50

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

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

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

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

Second Examination Solution

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

Final Exam. COMP Summer I June 26, points

CS171 Midterm Exam. October 29, Name:

Prelim 1. CS2110, October 2, 2014, 5:30 PM Extra Total Question TrueFalse Multiple Object Oriented

First Examination. CS 225 Data Structures and Software Principles Spring p-9p, Tuesday, February 19

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

CS 455 Midterm Exam 2 Fall 2015 [Bono] Nov. 10, 2015

CMSC132 Summer 2018 Midterm 1. Solution

CIS 110 Introduction to Computer Programming Spring 2016 Midterm

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

CS 101 Fall 2005 Midterm 2 Name: ID:

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

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

Midterm Exam CS 251, Intermediate Programming March 6, 2015

CS 101 Spring 2006 Final Exam Name: ID:

CS 307 Midterm 1 Fall 2007

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

Computer Programming, I. Laboratory Manual. Final Exam Solution

University Interscholastic League. Computer Science Competition

Midterm Exam (REGULAR SECTION)

Account joeacct = new Account (100, new Account (500)); Account joeacct = new Account (100, new Account (500, null));

Prelim One Solution. CS211 Fall Name. NetID

CMSC132 Summer 2018 Midterm 1

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

Prelim 1. CS 2110, 13 March 2018, 7:30 PM Total Question Name Short answer

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

CIS 110 Introduction to Computer Programming. February 29, 2012 Midterm

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

Total Score /15 /20 /30 /10 /5 /20 Grader

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

CS 134 Midterm Fall 2006

ENGR 2710U Midterm Exam UOIT SOLUTION SHEET

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

CIS 110 Introduction to Computer Programming. 7 May 2012 Final Exam

CS171 Final Practice Exam

Solutions to Sample JAC444 Midterm Test

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

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

CS 455 Midterm 2 Spring 2018 [Bono] Apr. 3, 2018

Exam 1 - (20 points)

CSI 1100 / 1500 Fall 2004 Introduction to Computer Science I Final Examination

COS 126 Midterm 1 Written Exam Fall 2011

University of Illinois at Urbana-Champaign Department of Computer Science. Final Examination

CS 314 Exam 2 Spring

Prelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion

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

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader

Introduction to Programming Using Java (98-388)

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

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

CS 10, Fall 2015, Professor Prasad Jayanti

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

Midterm Exam CS 251, Intermediate Programming March 12, 2014

Introduction to Java

SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177. Programming

CIS 110 Introduction to Computer Programming Summer 2018 Midterm. Recitation ROOM :

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

Prelim 1, Solution. CS 2110, 13 March 2018, 7:30 PM Total Question Name Short answer

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

CSE 143, Winter 2010 Midterm Exam Wednesday February 17, 2010

CSE 1223: Exam II Autumn 2016

Prelim 1. Solution. CS 2110, 14 March 2017, 7:30 PM Total Question Name Short answer

CS 101 Exam 2 Spring Id Name

University of Illinois at Urbana-Champaign Department of Computer Science. Final Examination

CMSC 433 Section 0101 Fall 2012 Midterm Exam #1

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

Problem Points Score Grader Total 75

CSE331 Winter 2014, Midterm Examination February 12, 2014

Total Score /15 /20 /30 /10 /5 /20 Grader

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

CIS Introduction to Computer Programming. 5 October 2012 Midterm

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

CS 132 Midterm Exam Spring 2004

Name CIS 201 Midterm II: Chapters 1-8

I. True/False: (2 points each)

CIS 110 Introduction to Computer Programming. 17 December 2012 Final Exam

CIS 110 Introduction to Computer Programming Summer 2014 Midterm. Name:

CSE 131 Introduction to Computer Science Fall Exam II

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

CS 307 Midterm 1[corrected] Spring 2008

CS 455 Midterm 2 Fall 2017 [Bono] Nov. 7, 2017

CS 314 Midterm 1 Spring 2014

Transcription:

University of Illinois at Urbana-Champaign Department of Computer Science Second Examination Fall 2011 CS 125 Introduction to Computer Science 90 minutes permitted First name: Last name: NetID: @ illinois.edu (please write legibly) Discussion Section: AY (We will return your exam manuscript to you in this section) AYA Tues 09:00am-10:50 AYB Tues 11:00am-12:50 AYC Tues 01:00pm-02:50 AYD Tues 03:00pm-04:50 AYE Tues 05:00pm-06:50 AYF Tues 07:00pm-08:50 AYG Wed 09:00am-10:50 AYH Wed 11:00am-12:50 AYK Wed 01:00pm-02:50 AYI Wed 03:00pm-04:50 AYJ Wed 05:00pm-06:50 This is a closed book and closed notes exam. No electronic aids are allowed. You must turn this exam booklet in before leaving. You have 9 sheets total including one scratch sheet. You may use both sides of the paper for your response. The last sheet is scratch paper; you may detach it while taking the exam, but must turn it in with the exam when you leave. Carefully read the specification given for each class. You may not write, or assume the existence of, any unspecified additional methods or constructors. Unless we say otherwise in the specific problem, you can assume all values entered by the user will be acceptable input for that program. When you write code, you may use a shorthand for System.out and TextIO input and output methods provided it is obvious to the graders which method you are using. For example it is acceptable to use Sopln in place of System.out.println and to use Sopt in place of System.out.print Likewise, you can use T.rlnI(), T.rlnC(), and T.rlnD() in place of TextIO.readlnInt(), TextIO.readlnChar(), and TextIO.readlnDouble(). For full marks correct syntax is required: Ensure all statements include a semicolon and the correct use of upper/lower case, single quotes and double quotes. However a syntactically correct but flawed program will earn a low score i.e. semantics and correctness is more important than minor typos and syntax errors. Problem Points Score Grader 1 15 2 16 3 15 4 21 5 18 6 15 Total 100

CS125 Midterm Exam II, Fall 2011 Page 2 of 9 NetID: 1. Short Answers 15 points (3 points each) (a) What is printed by the last two lines of the following Java code? Assume that the constructor initializes the private instance variables and that no compile or runtime errors occur. You do not need to write an explanation. Account a1 = new Account("James", 1234); Account a2 = new Account ("Jill", 4444); Account a3 = new Account ("John", 9870); a1 = a2; a2 = a3; a3 = a1; System.out.print(a2 == a3); System.out.print(a1 == a2); Write exactly the program output here and nothing else: (b) The following code compiles without error. What can you conclude about the classes A and B? A x = new B(); (c) "The class provides public methods and hides it's implementation" is best described as which one of the following? A) Primitive types B) Operator overloading C) Encapsulation D) Compile-time type checking E) Polymorphism Your answer: (d) Which answer best describes immutable? A) The class must define at least one constructor. B) The class must not define a copy constructor. C) The class must not have any class methods. D) In Java, only primitive values can be immutable. E) None of the above. Your answer: (e) Consider the following code example, then answer two questions: How many String objects are created and which line will cause an Exception to be thrown? 1 String[] data = new String[8]; 2 for(int i=0;i<4;i++) 3 data[i] = data[7-i]; 4 String result = data[1]; 5 System.out.println( result.touppercase() ); Number of String objects created: Exception thrown at line:

CS125 Midterm Exam II, Fall 2011 Page 3 of 9 NetID: 2. Lists, Stacks and Queues 16 points Complete the First-In-Last-Out Stack class by implementing peektop, getshortstack, anyempty public instance methods. public class Stack { private String[] arr = new String[0]; public int getcount() { return arr.length; public void push(string s) { // Code not shown. Appends the string: Copies arr references to a new array. Appends string s to the end of this array and updates arr to point to the new array. public String pop(){/* reduces the stack by one string (code not shown) */ /* A. The public instance method peektop takes no parameters and returns a String. Returns the String most recently added but does not modify the stack. Returns a null reference if the stack is empty. */ /* B. The public instance method getshortstack takes no parameters and returns a new Stack object. Returns a stack of the strings from the original stack that have a length less than 32. The ordering of strings is unspecified. The original stack is unchanged. Use String's length() method and Stack's push method to construct the result. */ /* C. The public instance method anyempty takes no parameters and returns a boolean. Returns true if any of the strings are zero length, false otherwise. Perform this search efficiently: Do not check any more strings as soon as an empty string is found. */ // end class

CS125 Midterm Exam II, Fall 2011 Page 4 of 9 NetID: 3. I took CS125 & all I got was a new planet named after my dog 15 Points You are searching for exoplanets by looking for periodic variations in star brightness. You downloaded two grayscale pictures of exactly the same patch of stars taken at different times and want to calculate the change in brightness at every point. A picture is represented as a 2D int array. Valid integer values are in the range 0(black) to 255 (white) i.e. only brightness is represented and there are no red/green/blue components. You can assume that both pictures are rectangular and are identical in size (width of A = width of B). Complete the class method below to create a new picture of the same size. If either parameter is null, immediately return null. Each output pixel brightness value represents the twice (2x) the absolute difference of the corresponding pixel in image A and image B. If the output value is greater than 255, set the output value to 255. The source arrays are never modified. public static int[][] diff(int[][] A, int[][] B) {

CS125 Midterm Exam II, Fall 2011 Page 5 of 9 NetID: 4. X marks the spot 21 Points The entire Geo class is shown below. public class Geo { private double lat = 180* Math.random() - 90; // a random latitude private double longi = 360* Math.random(); // a random longitude public double getlat() {return lat; public double getlong() {return longi; Write a new class named "Secret". Your class: 1. Extends the Geo class. 2. Has one additional private variable named 'showafter' of type long that represents time in milliseconds since Midnight Jan 1 1970 UTC. 3. Has a constructor that takes no parameters. The constructor sets the showafter variable to the current time (use the class method currenttimemillis() in the System class) plus a random delay of up to 60 000 milliseconds. 4. Has an instance method named 'tostring' that takes no parameters and returns a String. If the current time is at least showafter, then return the string "latitude,longitude" (where latitude and longitude are replaced by the instance values), otherwise return an empty string. Hint: Notice the Geo class does not define a tostring method and the instance variables are private. Complete the following program. Your program calls a class method, named "create", defined in a different class named "Factory" that takes no parameters and returns an array of 100 Secret objects. Waits for the user to press return then prints the location of the Secret objects that are now known. Use their tostring method to print the location. Do not print any empty strings. Print one location per line. Continue overleaf if necessary. public class Finder { // Continue overleaf if more space is required public static void main(string[] args) {

CS125 Midterm Exam II, Fall 2011 Page 6 of 9 NetID: 5. Objects I 18 Points Do not create any other additional constructors, instance or class methods or instance or class variables only create the constructors, methods and instance variables specified below. A sparse binary list is a very large list of data where most of the entries are zero and only a few entries are one. To efficiently store a massive list, the list internally holds the positions of the non-zero entries. Your programming buddy has already started the BigList class shown below: public class BigList { private int[] pos; // should this be static? public void reset(int[] newpositions) { this.pos = newpositions; 0 1 0 1 0 A. Create a public instance method named 'getv' that takes an integer parameter named 'index' and returns an integer. If the pos array contains the parameter value return 1, otherwise return 0. B. Create a public constructor that takes one integer named 'count'. Initialize pos to a new integer array of length count. Initialize the contents of the array to random integers, including the first entry. Each integer entry should be greater than the previous entry by a small random amount (e.g. +1...+10). All array values should be positive. C. Create a public copy constructor that takes a reference to another BigList object (which will not be changed). Perform a deep copy i.e. the new object will use its own position array.

CS125 Midterm Exam II, Fall 2011 Page 7 of 9 NetID: 6. Objects (BigList Continued) 15 points D. Complete a public instance method anyoverlap that takes a reference to another BigList and returns a boolean. Return true if the two biglists have any ones in the same position, false otherwise i.e. there's a integer value that exists in both arrays. You may assume the position values are in increasing order. BigList continues... E. Your buddy claims their BigList equals method below returns true only when two big lists are identical (ones in the same position). BigList continues... public boolean equals(biglist o) { // works!?? if(o == null) return false; for(int i =0;i < pos.length; i++) if(this.pos[i]!= o.pos[i] ) return false; return true; Complete the test code below to show that the equals method is broken: Add data values to complete the example so that list1.equals(list2) returns true when in fact the lists are different. BigList list1 = new BigList(0); BigList list2 = new BigList(0); list1.reset({3,7,13); // The reset method assigns pos to the given int array. >> list2.reset({ ); boolean b = list1.equals(list2); // equals method returns true! (should be false) F. Your buddy claims it's OK to add the 'static' modifier to BigList's pos variable. They even created a short example to show you that it works! Modify their example below: Insert a very small amount of code to demonstrate to your buddy that adding static to pos is incorrect. Assume getv works as specified in Q5. public class BigListExample { public void static main(string[] args) { // Demonstrates that I can add static to pos! :-)?? BigList t = new BigList(0); t.reset({4,7); System.out.println(t.getV(7)); // prints one as expected System.out.println(t.getV(6)); // prints zero as expected

CS125 Midterm Exam II, Fall 2011 Page 8 of 9 NetID: Empty Page.

CS125 Midterm Exam II, Fall 2011 Page 9 of 9 NetID: Scratch paper