CSE 131 Introduction to Computer Science Fall 2017 Given: 16 December 2017 Final Exam Due: End of session This exam is closed-book, closed-notes, no electronic devices allowed. The exception is the sage page on which you may have notes to consult during the exam. Answer questions on the pages of the exam. Do not unstaple the pages of this exam, nor should you attach any other pages to the exam. You are welcome to use the blank space of the exam for any scratch work. Your workmustbelegible. Work that isdifficulttoread willreceive nocredit. Donot dwell over punctuation or exact syntax in code; however, be sure to indent your code to show its structure. You must sign the pledge below for your exam to count. Any cheating will cause the students involved to receive an F for this course. Other action may be taken. If you need to leave the room for any reason prior to turning in your exam, you must leave your exam and any electronic devices with a proctor. You must fill in your identifying information correctly. Failure to do so is grounds for a zero on this exam. The instructors and proctors will not clarify any material on this exam, so please do not ask. Problems can have more than one correct answer. Be sure to state your assumptions and thinking if you want to get partial credit for incorrect responses. Name (print clearly): Print clearly the following information: Student 6-digit ID (one digit per box): Your answers below tell us where to return your graded exam. What time do you arrive in studio/lab? (circle one) 11:30 1:00 2:30 4:00 Which Urbauer lab? (your best guess, circle one) 214 216 218 222 Pledge: On my honor, I have neither given nor received any unauthorized aid on this exam. Signed: (Be sure you filled in your information in the box above!)
CSE 131 (Final Exam) 2 Due by End of session Problem Possible Received Grader Number Points Points Initials 1 20 2 20 3 20 4 20 5 20 Total 100
CSE 131 (Final Exam) 3 Due by End of session 1. (20 points) Letters for you to use to fill in the blanks: a objects f Plankton b methods c constructors d tostring() e equals(object...) g stack h instance variables i static j interface For each statement below, fill in the blank with a letter chosen from the above list. Correct responses may or may not be unique. A given letter may or may not appear in the solution to the statements below. An example is provided, so that you know to use letters as you fill in the blanks. Each response, including the one I give you for free, is worth 2 points. According to Wikipedia, Sheldon J. f is Mr. Krab s arch-nemesis and business rival. He runs a failing restaurant called the Chum Bucket alongside his sentient computer Karen, who is usually the source of his evil plans. His primary goal is to steal the Krabby Pattie secret formula. Some believe that he might have chosen a different, possibly less-evil path, had he taken CSE131. A method cannot reference its classes instance variables. The method is usually written to provide a String that contains information about an instance of its associated class. A class s are responsible for giving birth to an object. While it is special in that regard, it is also just one of a class s. The method is responsible for determining whether two instances of a given object type are viewed as the same. A class s are often described as the has-a s of an object type. The of a software project generally represent the nouns of that project, such as colors, circles, rectangles, etc. When a method is called, it receives its input parameter values from the. Ifthatmethodisreturningavalue,thenitpushesthatvalueontothe just before returning, unless that method is void.
CSE 131 (Final Exam) 4 Due by End of session 2. (20 points) Address Contents Address Contents Address Contents 1000 12 1006-10 1012 4 1001-14 1007-12 1013 2 1002-3 1008 2 1014 12 1003 0 1009 12 1015 12 1004 0 1010 14 1016 24 1005 4 1011 4 1017 4 The above table contains some Foo objects, whose definition is given below: public class Foo { private final int x, y, z; public Foo(int x) { this.x = x; this.y = 12; this.z = x + y; public int bar() { return z / (x-y); public int baz() { return z / (x+y); Continued on next page...
CSE 131 (Final Exam) 5 Due by End of session (a) (4 points) At which address is the object in memory that was created by the constructor call new Foo(2)? (b) (4 points) At which address is the object in memory that was created by the constructor call new Foo(12)? (c) (4 points) At which address is the object in memory such that when bar() is called on that object, a DivideByZero error occurs? (d) (4 points) The attribute final on the instance variables makes certain that all Foo objects are immutable. What does that mean? (e) (4 points) If equality of two Foo objects is based only on the value of x, then which Foo objects (state their addresses) in the memory shown above equal each other? 3. (20 points) Some questions about lists and sets. (a) (10 points) What are the differences between the list and set data types? (b) (10 points) For each of the scenarios below, place an X in the column whose associated abstract data type (ADT) is better suited for the scenario. Scenario List Set The cities you might visit over Winter break The steps you must perform to pack your suitcase The extensions you have completed this semester The books you intend to read over Winter break The classes you are taking Spring semester
CSE 131 (Final Exam) 6 Due by End of session 4. (20 points) Consider the following methods: public static int f(int x, int y) { return x+y; public static int g(int z) { return 7 * z; public static int h(int a, int b) { return b; and the line of code: int answer = h(f(3,4), g(5)); (a) (10 points) Below show the contents of the stack, just prior to h beginning its execution: (b) (5 points) The stack as drawn above has room for 5 elements. During the execution of the above line, what is the maximum number of elements ever on the stack at any given time? (c) (5 points) What is the last value to be popped from the stack after executing the above line of code?
CSE 131 (Final Exam) 7 Due by End of session 5. (20 points) Read over the following description of an object, and then write code for a class to represent the object in the space reamining for this exam. Be sure to include a constructor with the appropriate arguments, instance variables, and methods as indicated in the story. Do not worry about tostring, hashcode, or equals. You are free to make choices about names, types, etc., unless stated otherwise. You are welcome to introduce any other methods or instance variables you need. A Circle has a center, expressed as an x coordinate and a y coordinate, and a radius, expressed as the value r. Once constructed, the properties of a Circle never change. The values x, y, and r must be accessible from a constructed Circle, but they must not be allowed to change. In addition to the accessors mentioned above, a Circle offers the following methods: Circle twiceradius() returns a new Circle with the same center as this one, but with twice the radius of this one. boolean areconcentric(circle other) returns true if and only if the other Circle and this one have the same center. Two Circles are concentric even if they have the same radii. boolean allareconcentric(list<circle> list) returns true if and only if all of the Circles in the supplied list are concentric with this one. For full credit on your solution for this method, your solution must use recursion instead of iteration. Five points will be deducted if your solution is correct but does not use recursion. OK, write your class below and on the back as necessary.
CSE 131 (Final Exam) 8 Due by End of session