CS 1316 Exam 1 Summer 2009

Similar documents
Exam Percentage: / 55 = %

CS 1316 Exam 2 Summer 2009

CS Exam 2 - Spring 2010

CS 1316 Exam 2 Fall 2009

Introduction to Programming Using Java (98-388)

CS 1301 Exam 1 Answers Fall 2009

CS 1301 Exam 1 Fall 2009

Objects and Classes Lecture 2

Section 003 Fall CS 170 Exam 2. Name (print): Instructions:

CS 1316 Exam 3 Fall 2009

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

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

Question: Total Points: Score:

CS 1301 Exam 1 Fall 2010

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

Chapter 4 Defining Classes I

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

CS 1301 Exam 1 Fall 2010

CS 231 Data Structures and Algorithms, Fall 2016

Question: Total Points: Score:

Chapter 6 Introduction to Defining Classes

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

CS 1301 Exam 2 Fall 2013

Chapter 14 Abstract Classes and Interfaces

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

Question: Total Points: Score:

Question: Total Points: Score:

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Section 003 Fall CS 170 Exam 1. Name (print): Instructions:

CS Exam 3 - Spring 2010

CS 1803 Fall 2010 Exam 1

CS Exam 2 Name: Your Grading TA: This exam has 7 pages including the title page. Please check to make sure all pages are included.

Inheritance (Outsource: )

CS 1301 Exam 3 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014

CS Exam 3 - Spring 2010

CO Java SE 8: Fundamentals

Programs as Models. Procedural Paradigm. Class Methods. CS256 Computer Science I Kevin Sahr, PhD. Lecture 11: Objects

Place your name tag here

STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes

1 Inheritance (8 minutes, 9 points)

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

2. The object-oriented paradigm

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

COP 3330 Final Exam Review

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

Computer Programming, I. Laboratory Manual. Final Exam Solution

Object Oriented Programming in C#

This exam has 10 pages including the title page. Please check to make sure all pages are included.

COMP 401 Spring 2013 Midterm 1

TeenCoder : Java Programming (ISBN )

Practice for Chapter 11

JAVA: A Primer. By: Amrita Rajagopal

CS 1331 Fall 2016 Exam 2

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.

C++ Important Questions with Answers

APCS Semester #1 Final Exam Practice Problems

Chapter 10 Classes Continued. Fundamentals of Java

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

CS 1301 Exam 3 Spring 2014

CS 1803 Fall 2010 Exam 1

CS171:Introduction to Computer Science II

Instructor: Yu Wang 11/16/2012

Section 004 Spring CS 170 Exam 1. Name (print): Instructions:

Student Performance Q&A:

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

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

Creating Java Programs with Greenfoot

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

CS 155 Exam 2 Spring 2015

CompuScholar, Inc. 9th - 12th grades

CS 2316 Exam 4 Fall 2012

Using the API: Introductory Graphics Java Programming 1 Lesson 8

The Java language has a wide variety of modifiers, including the following:

CS 1301 Exam 3 Spring 2012

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

CS 1301 Exam 1 Spring 2011

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

Inheritance & Polymorphism

Programming Exercise 14: Inheritance and Polymorphism

Java Applets. Last Time. Java Applets. Java Applets. First Java Applet. Java Applets. v We created our first Java application

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

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

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

CS 2316 Exam 4 Spring 2013

Lecture 02, Fall 2018 Friday September 7

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding

Logistics. Final Exam on Friday at 3pm in CHEM 102

Announcement. Agenda 7/31/2008. Polymorphism, Dynamic Binding and Interface. The class will continue on Tuesday, 12 th August

CS 2102 Exam 2 D-Term 2013

CS 2316 Exam 4 Fall 2012

CS260 Intro to Java & Android 03.Java Language Basics

COMSC-051 Java Programming Part 1. Part-Time Instructor: Joenil Mistal

2. The object-oriented paradigm!

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

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

Transcription:

1 / 8 Your Name: I commit to uphold the ideals of honor and integrity by refusing to betray the trust bestowed upon me as a member of the Georgia Tech community. CS 1316 Exam 1 Summer 2009 Section/Problem Points Earned Points Possible 1. Vocabulary Matching 32 2. Fill in the Blank 12 3. Multiple Choice 4 4. Code Understanding 9 5. Turtle Graphics 6 6. Write Code: SumTo 12 7. Better Dorm 15 8. Convert Picture 10 Total Points: 100

2 / 8 Your Name: 1. Vocabulary Matching (32 points) Write the number before the definition on the right on the line before the matching vocabulary word. Array Block Boolean Boolean Expression Cast / Casting Class Constructor Data Encapsulation Double Field Final Graph Inheritance Int Iterate Linked List Method Method Signature Model Object Private Public Simula Simulation Smalltalk Static String Subclass Superclass Traverse Type Declaration Void 1. A detailed description of structure and behavior. 2. Execution of a model. 3. A data structure that uses nodes/points and their edges/connections to model aspects of the real world. 4. A data structure made up of a collection of nodes, where each node points to the next node in line. 5. The earliest object oriented programming language. 6. An early object oriented programming language created by Alan Kay. 7. The process of telling the compiler what type of data a variable will hold. 8. A data type that holds numbers with fractional components. 9. A data type that holds numbers without a fractional component. 10. A data type that holds sequences of characters. 11. A data type that has only two possible values. 12. A section of code, typically enclosed with curly brackets { that makes up the body of a loop, function, or conditional. 13. A logical statement that evaluates to either True or False. 14. The fundamental building block of Java programs, they act as the blueprints from which objects are constructed, including definitions of fields and methods. 15. The instantiation of a class, they have fields that store state and methods (functions) that encode behavior. 16. The process of hiding internal state from direct access by outsiders, and instead requiring that all accesses to the internal state be done through methods that can act as gatekeepers. 17. A keyword that means that anybody can see and manipulate a particular field or method. 18. A keyword that means that only methods within the object can access a particular field or method. 19. A keyword that means that a field will not change. 20. A keyword that means a field or method belongs to the class, and not specific objects that are instantiated from it. 21. A method that is called when a new instance is created. 22. A class that inherits behaviors and state (methods and fields) from a superclass. 23. The process of extending a superclass, gaining it's behaviors and state. 24. A class that is extended by subclasses. 25. A keyword that indicates nothing, as in returns nothing. 26. The process of forcing Java to convert data from one data type to another. 27. These contain state within an object, sometimes called object variables. 28. A function that is associated with an object and implements behavior. 29. A homogeneous linear collection of objects which are stored together in memory. 30. The unique collection of method name and parameter number and type that define a method. Multiple methods may share the same name as long as the type or number of their parameters differ. 31. To (potentially) repeat the execution a block of code multiple times, as with a for or while loop. 32. To move through a linear data structure (or a sequence) doing something to or with each individual element.

3 / 8 Your Name: 2. Fill in the Blank ( 12 points) In Java, a is used to indicate assignment, while a is used for equality checking. Most statements in Java must be ended with a. The only exception is if you have only a single statement alone in a. In Java, logical and is written using the symbol, and logical or is written using the symbol. Assume that the Student class is a subclass of the Person class, and the Person class is a subclass of the Human class. A variable that is defined to be of type Person can refer to (hold) an object of type or type but a variable defined to be of type Student can only refer to an object of type. A picture that is 200 pixels wide and 100 pixels high has a total of pixels. Each pixel needs BYTES, to represent the color of the pixel. How many total BITS are used to represent the 200 by 100 picture? Answer: 3. Multiple Choice (4 points) Circle the correct answer. Which of the following is an incorrect conditional statement? A. if ( thiscolor == mycolor ) setcolor( thispixel, newcolor ); B. if ( thiscolor == mycolor ) { setcolor( thispixel, newcolor ); C. if ( thiscolor == mycolor ) {x = 12; setcolor ( thispixel, newcolor ) ; ; D. All are correct. The new operator: A. invokes the constructor of an object. B. instantiates a specific instance of a class. C. allocates memory space for the object. D. A and C only. E. A, B, and C.

4 / 8 Your Name: 4. Code Understanding ( 9 points) What does the following code output? int [] a = new int[10]; for ( int i = 0; i < 10; i++) { a[i] = 9 i; for( int i = 0; i < 10; i++) { int index = a[i]; a[i] = a[ index ]; for(int i = 0; i < 10; i++) { System.out.println( a[i] ); 5. Turtle Graphics ( 6 points) The following code creates a turtle and moves it around. Draw the turtle's path in the box on the right: Turtle t = new Turtle(new World()); for( int i = 0; i < 20; i++) { if (i %2 == 0) { t.forward( 10 * i ); else { t.turn(90); // end if/else // end for

5 / 8 Your Name: 6. Write Code (12 points) Write (twice) a method sumto which returns the sum of the first n reciprocals. In other words, sumto( n ) returns: 1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 +... + 1/n You may assume that n is never a negative number. sumto(0) returns 0.0, and sumto(1) returns 1.0. The first time you write the method, use a for or while loop. The second time you write the method, you must use recursion instead of a loop. The return value and header for the method(s) are the same: // sumto with a for or while loop public static double sumto(int n) { // sumto using recursion public static double sumto(int n) {

6 / 8 Your Name: 7. Create an Object: Better Dorm (15 points) Examine the source code for the Dorm object provided at the end of this exam. Write code for a subclass of the Dorm object called BetterDorm. Your subclass must have: A constructor that accepts a string and two int's representing the name of the dorm and the number of men and women in the dorm. A method called percentmale that takes no parameters and returns the percentage of the dorm's population that is male (as a double). Your function must work for all possible numbers of men & women in the dorm.

7 / 8 Your Name: 8. Convert a picture (10 points) Write a new method for the Picture class that will return a black and white copy of itself. The method should make a new copy of itself, convert the pixels to B&W (using the following formula), and return it. Your method must be named bwcopy, take no parameters, and return a Picture object. Use the following formula to convert from R,G,B values to a single Luminance (Y) value to put into all 3 (r,g,b) color slots : Y = 0.299 * R + 0.587 * G + 0.114 * B

8 / 8 Your Name: Definition of the DORM class: public class Dorm { private String myname; private int mynummen; private int mynumwomen; // Constructor public Dorm( String name, int men, int women) { myname = name; mynummen = men; mynumwomen = women; public void setnummen( int men) { mynummen = men; public void setnumwomen( int women) { mynumwomen = women; public void setname( String name) { myname = name; public int getnummen() { return mynummen; public int getnumwomen() { return mynumwomen; public String getname() { return myname; // end dorm