CS 1322 Test 2 - Version 1 Tuesday June 24 th

Similar documents
Exam Percentage: / 55 = %

CS Exam 3 - Spring 2010

CS Exam 3 - Spring 2010

CS Exam 2 - Spring 2010

CS 1301 Exam 1 Fall 2010

CS 1301 Exam 1 Fall 2010

CS 1331 Fall 2016 Exam 2

Your (printed!) Name: CS 1803 Exam 3. Grading TA / Section: Monday, Nov. 22th, 2010

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.

CS 2316 Exam 1 Spring 2013

CS 2316 Exam 1 Spring 2014

CS 2316 Exam 4 Fall 2011

CS 1301 Exam 1 Spring 2011

CS 1803 Fall 2010 Exam 1

CS 1301 Exam 3 Fall 2014

CS 2316 Exam 3 Fall 2011

CS 1301 Exam 1 Fall 2011

CS 1301 Exam 3 Spring 2014

CS 1301 Exam 2 A Fall 2015

CS 1301 Exam 2 A Fall 2015

CS 2334: Programming Structures and Abstractions: Exam 1 October 3, 2016

CS 2316 Exam 4 Fall 2012

CS 2316 Exam 4 Fall 2012

Question Possible Points Earned Points Graded By GUI 22 SQL 24 XML 20 Multiple Choice 14 Total Points 80

CS 2316 Exam 4 Spring 2013

CS 1803 Fall 2010 Exam 1

CS 1331 Exam 1 ANSWER KEY

Prelim One Solution. CS211 Fall Name. NetID

CS 2316 Exam 2 Summer 2011

CS 1301 Exam 2 Fall 2013

CS 1301 Exam 1 Fall 2013

1 Method Signatures and Overloading (3 minutes, 2 points)

CS 1301 Exam 1 Fall 2013

CS 1301 Exam 1 Fall 2014

CS Name : Grading TA:

1 Inheritance (8 minutes, 9 points)

CS 1301 Exam 1 Spring 2014

CS 1301 Exam 2 Fall 2010

CS 1301 Exam 1 Fall 2014

CS 1301 Exam 1 Spring 2014

CS 1301 Exam 1 Spring 2015

Announcements. Final exam. Course evaluations. Saturday Dec 15 10:20 am -- 12:20 pm Room: TBA

COMP 401 Midterm. Tuesday, Oct 18, pm-3:15pm. Instructions

Introduction to Programming Using Java (98-388)

CS 1301 Exam 2 Fall 2014

Chapter 13. Inheritance and Polymorphism. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

CS 1301 Exam 3 Spring 2012

CS 170 Exam 2. Version: A Fall Name (as in OPUS) (print): Instructions:

Lecture 6. COMP1006/1406 (the OOP course) Summer M. Jason Hinek Carleton University

Objects as a programming concept

CS 2316 Exam 3 Spring 2013

CS 2316 Exam 4 Fall 2011

CS 1301 Exam 3 A Spring 2015

CIS 110 Introduction to Computer Programming Summer 2017 Final. Recitation # (e.g., 201):

CMPSCI 187 Midterm 1 (Feb 17, 2016)

CS 2316 Exam 4 Fall 2014

Distributed Systems Recitation 1. Tamim Jabban

Distributed Systems Recitation 1. Tamim Jabban

CS 2316 Exam 3 Fall 2012

CS 1301 Exam 3 Fall 2010

Computer Programming II C++ (830)

UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED

CS 1316 Exam 1 Summer 2009

Informatik II (D-ITET) Tutorial 6

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

[ L5P1] Object-Oriented Programming: Advanced Concepts

CS 1301 Exam 2 Spring 2014

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

BM214E Object Oriented Programming Lecture 6. Classes and Objects

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

Abstract Classes and Interfaces

Do not start the test until instructed to do so!

OBJECT ORIENTED PROGRAMMING

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

Cpt S 122 Data Structures. Course Review FINAL. Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University

cs Java: lecture #6

Informatik II. Tutorial 6. Mihai Bâce Mihai Bâce. April 5,

CS 170 Exam 1. Version: B Fall Name (as on OPUS):

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

CSCI 136 Data Structures & Advanced Programming. Lecture 3 Fall 2017 Instructors: Bill & Bill

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Interfaces & Generics

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Prelim 1. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

CSCI 136 Data Structures & Advanced Programming. Lecture 3 Fall 2018 Instructors: Bill & Bill

Chapter 5 Names, Bindings, Type Checking, and Scopes

CS 170 Exam 2. Version: A Spring Name (as in OPUS) (print): Instructions:

CS 170 Exam 1. Version: C Fall Name (as on OPUS):

CS 1316 Exam 2 Summer 2009

Topic 7: Inheritance. Reading: JBD Sections CMPS 12A Winter 2009 UCSC

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

COMP 524 Spring 2018 Midterm Thursday, March 1

Computer Programming II Python

CSE 131 Introduction to Computer Science Fall Exam II

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

Object Oriented Programming: Based on slides from Skrien Chapter 2

Instructor: Yu Wang 11/16/2012

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Transcription:

Name: GT Number: TA: Commenting your code on this test is optional, however it may help the grader understand your code better. Other style issues such as using good variables names and using abstraction are still required. Write your gt number in the spaces provided and color in the corresponding numbers and letters. gt - - - - - - - - - - - - - - - - - - - - - - - - - - d e f g h 0 1 2 3 4 5 6 7 8 9 - - - - - - - - - - - 0 1 2 3 4 5 6 7 8 9 - - - - - - - - - - - - - - - - 0 1 2 3 4 5 6 7 8 9 - - - - - - - - - - - - - - - - 0 1 2 3 4 5 6 7 8 9 - - - - - - - - - - - - - - - - a b c d e f g h i j k l m n o p q r s t u v w x y z Problem Points Possible Points Received Graded By 1 Matching 10 2 Multidimensional Arrays 10 3 Interfaces 10 4 Abstract Classes 10 5 Recursion 10 6 Stacks and Queues 10 7 Static vs. Instance 10 8 Polymorphism 10 9 Linked List 10 10 Tracing 10 TOTAL 100 Please remember: Any academic misconduct (including, but not limited to, the list below) could result in a 0 (zero) on the exam, an F grade in the course, or other penalty: Communication with anyone other than a proctor for ANY reason in ANY language in any manner. Sharing of ANYTHING (e.g. pencils, paper, erasers). Writing on paper that is not given to you by a proctor. Failure to follow directions given by the proctor. Use of cell phones, beepers, handheld computers, calculators, during the exam. Using books or other reference material. Disruption of the exam setting. By taking this exam, you signify that it is your work and that you have neither given nor received inappropriate help during the taking of this exam in compliance with the Academic Honor Code of Georgia Tech. Signature: (you must sign this for your exam to be graded!)

1. Matching[ 10 pts ] Choose the best word for each statement. 1. Provides runtime resolution to the most specific implementation possible. 2. A named collection of method headers (without definitions) that can also declare constants. 3. Holds the location of an object. 4. LIFO data structure. 5. The process in which a reference of a given class can refer to any instance of a subclass. A. Constructor B. Polymorphism C. Abstract D. Compiler E. Recursion F. Reference G. Inheritance H. Interface I. Private method J. Dynamic Binding K. Constructor Overloading L. Stack M. Queue Page 2 of 11

2. Multidimensional Arrays[ 10 pts ] Write public float[][] addmatrices(float[][] a, float[][] b)which adds the values of the two matrices passed in (a and b) and returns the result in a new matrix. You may assume the arrays passed in are rectangular and have the same dimensions.. public float[][] addmatrices(float[][] a, float[][] b){ Page 3 of 11

3. Interfaces[ 10 pts ] Declare a class Money that has the following properties: Has a private double called value Has an accessor and modifier for the private double. Implements the Comparable interface. Items should be compared by the valuer field to determine if it is less than, equal, or greater than the Object it is being compared to as specified by the interface. Page 4 of 11

4. Abstract Classes[10 pts] Given the following class: public abstract class Machine{ private String name; public void setname(string name){ this.name = name; public String getname(){ return name; public abstract double calculatepower(); Declare an instantiable (concrete) subclass of Machine. You may make the subclass do anything as long as it compiles. Page 5 of 11

5. Recursion[ 10 pts ] Write the method public int geomjava(int x) which calculates the following geometric series. If the input is less than 1, the method returns 1. Otherwise, the method returns the sum of geomjava(x/2) plus geomjava(x-4).you must use recursion to solve this problem. If you use any iteration, or do not use recursion, you will not receive credit. public int geomjava(int x) { Page 6 of 11

6. Stacks and Queues[ 10 pts ] Assume you have the following LinkedList class. You may only assume that you have the following methods fully implemented and fields in the LinkedList class: private LLNode head; public void addtofront(object o){... public void addtoback(object o){... public Object removefromfront(){... public Object removefromback(){... Write the following methods for the Stack class. intergrity of the Stack data structure. public class Stack extends LinkedList { The methods should maintain the 5 (a) public void push(object o){ 5 (b) public Object pop(){ //end class Stack Page 7 of 11

7. Static vs. Instance[ 10 pts ] Given the following class, write the output when the main method is run. public class TryMeA{ private static int one; private int two; public static void setone(int x){ one = x; public static int getone(){ return one; public void settwo(int two){ this.two=two; public int gettwo(){ return two; public int specialsum(){ return one*2+two/10; public TryMeA(int x){ one = x/10; two = x; public static void main(string[] args){ TryMeA a = new TryMeA(4); TryMeA b = new TryMeA(6); TryMeA c = new TryMeA(20); System.out.println("a.getOne() is " + a.getone()); System.out.println("c.getOne() is " + c.getone()); a.setone(4); b.settwo(5); System.out.println("b.getOne() is " + b.getone()); System.out.println("a.getTwo() is " + a.gettwo()); System.out.println("c.specialSum() is " + c.specialsum()); Page 8 of 11

8. Polymorphism[ 10 pts ] Given the following class hierarchy with listed methods: public abstract class Emotion has: public void express() public interface Crying has: public void tears() public class Joy extends Emotion implements Crying has: public void smile() has: public void tears() public class PureJoy extends Joy has: public void exult() public class Anger extends Emotion has: public void yell() Determine which of the following statements will compile and run without any errors or exceptions. If there is no error, write OK; if there will be an error at compile time, write Compile Error; if there will be a problem during during execution, write Runtime Error. If you know there is an error but cannot determine whether it is at Run-time or compile-time, you may write error and explain why in 15 words or less. If you write both, you will not receive credit for that part. 2 (a) Emotion e = new Emotion(); 2 (b) Emotion my = new Joy(); 2 (c) Emotion great = new PureJoy(); great.tears(); 2 (d) Emotion well = new Joy(); ((Anger)well).yell(); 2 (e) PureJoy lastone = new Joy(); Page 9 of 11

9. Linked List[ 10 pts ] Given the following class LLNode: public class LLNode{ private Comparable data; private LLNode next=null; public void setdata(comparable data){ this.data = data; public void setnext(llnode next){ this.next = next; public Comparable getdata(){ return data; public LLNode getnext(){ return next; public LLNode(Comparable data){ this.data = data; Write the removealloccurrences(comparable c) method for the LinkedList class, which will remove all occurrences of c from the Linked List. You may not assume anything else about the LinkedList class or the LLNode class. You may write any helper methods you see fit to solve the problem. public class LinkedList{ private LLNode head; public void removealloccurrences(comparable c){ Page 10 of 11

10. Tracing[ 10 pts ] Given the following classes, write the output when the main method is run. public class ParentClass{ public String random(){ return "Cheese"; public String getname(){ return "Me"; public ParentClass(){ this(null); System.out.println("In ParentClass()"); public ParentClass(String x){ System.out.println("In ParentClass(String)"); //end ParentClass public class ChildClass extends ParentClass{ public String random(){ return "Mechanic"; public ChildClass(){ System.out.println("In ChildChildClass()"); public ChildClass(String x){ this(); System.out.println("In ChildChildClass{String)"); public static void main(string[] args){ ParentClass a = new ParentClass(); ChildClass b = new ChildClass(); System.out.println(a.random()); System.out.println(a.getName()); System.out.println(b.getName()); a = b; System.out.println( a.random() ); System.out.println( ((ParentClass)a).random() ); Page 11 of 11