Final Exam CS 152, Computer Programming Fundamentals December 9, 2016

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

Final Exam CS 152, Computer Programming Fundamentals May 9, 2014

Midterm Exam CS 251, Intermediate Programming October 8, 2014

Midterm Exam CS 251, Intermediate Programming March 12, 2014

Final Exam CS 251, Intermediate Programming December 10, 2014

Midterm Exam CS 251, Intermediate Programming March 6, 2015

Final Exam CS 251, Intermediate Programming December 13, 2017

Final Exam. COMP Summer I June 26, points

CS111: PROGRAMMING LANGUAGE II

Programming with Java

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

Introduction to Programming Using Java (98-388)

CS 251, Intermediate Programming Midterm Exam October 9, 2013

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

Array. Prepared By - Rifat Shahriyar

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Course Outline. Introduction to java

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

Final Exam Practice. Partial credit will be awarded.

COMP-520 GoLite Tutorial

CSE 142 Su 04 Computer Programming 1 - Java. Objects

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

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.

Use the Scantron sheets to write your answer. Make sure to write your Purdue ID (NOT Purdue Login ID) and your name on the Scantron answer sheet.

Introduction to Java

CS 177 Week 15 Recitation Slides. Review

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

WES-CS GROUP MEETING #9

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

CS 1301 Exam 1 Fall 2010

1007 Imperative Programming Part II

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended

Java Bytecode (binary file)

CS 1331 Exam 1 ANSWER KEY

Computer Science II (20082) Week 1: Review and Inheritance

Csci 102: Sample Exam

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

Question: Total Points: Score:

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

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

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

Reviewing all Topics this term

Spring 2017 CS 1110/1111 Exam 1

Question: Total Points: Score:

Computer Programming, I. Laboratory Manual. Final Exam Solution

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each):

5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!

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

CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011

2. [20] Suppose we start declaring a Rectangle class as follows:

Getting started with Java

CS 1301 Exam 1 Fall 2010

Last Name: Circle One: OCW Non-OCW

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

CS 3360 Design and Implementation of Programming Languages. Exam 1

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program:

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program:

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

CSCI 355 LAB #2 Spring 2004

CSCI 355 Lab #2 Spring 2007

CSCS 261 Programming Concepts Exam 2 Fall EXAM 2 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.

FORM 2 (Please put your name and form # on the scantron!!!!)

CSCS 261 Programming Concepts Exam 2 Fall EXAM 2 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.

Computational Expression

Full file at

Introduction to Python

About this exam review

Final Exam COMP Fall 2004 Dec 16, 2004

Oracle 1Z Java SE 8 Programmer I. Download Full Version :

Chapter 7: Arrays CS 121. April 9, Department of Computer Science College of Engineering Boise State University. Chapter 7: Arrays CS / 41

Prelim One Solution. CS211 Fall Name. NetID

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

CS302: Self Check Quiz 2

CS201- Introduction to Programming Current Quizzes

CS211 Spring 2005 Prelim 1 March 10, Solutions. Instructions

CSE 1223: Exam II Autumn 2016

Final Exam, 3/17/2016 CIS330, Winter 2016

CMSC330 Fall 2016 Midterm #1 2:00pm/3:30pm

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

CS313D: ADVANCED PROGRAMMING LANGUAGE

COMP 202 Java in one week

CSC 1051 Algorithms and Data Structures I. Final Examination December 17, Name:

Section 2.2 Your First Program in Java: Printing a Line of Text

Chapter 4 Defining Classes I

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

Object-Oriented Programming

APCS Semester #1 Final Exam Practice Problems

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

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

Intro to Strings. Lecture 7 CGS 3416 Spring February 13, Lecture 7 CGS 3416 Spring 2017 Intro to Strings February 13, / 16

Midterm Exam 2 CS 455, Spring 2011

CMPSCI 187 Midterm 1 (Feb 17, 2016)

CS Week 5. Jim Williams, PhD

Selected Questions from by Nageshwara Rao

CS111: PROGRAMMING LANGUAGE II

EXAM Computer Science 1 Part 1

Transcription:

Final Exam CS 152, Computer Programming Fundamentals December 9, 2016 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible answers. Print your name at the top of every page. This is a closed book exam. However, each student is allowed to bring one page of notes to the exam. Also, you are permitted the use of a dumb calculator to perform basic arithmetic. Question: 1 2 3 4 5 6 7 8 9 Total Points: 20 7 6 12 13 12 10 10 10 100 Score: 1. Write the answer in the blank provided. (a) What is the keyword used to make a variable or method visible only to the class containing it? (b) What is the keyword used to make a variable that holds a constant value? (c) What is the keyword used to make a variable or method belong to a class rather than an instance? (d) Name one of the types of loops in Java. (e) Name one of the floating point data types in Java. (f) Name one of the integer data types in Java. (g) If I declare a String variable but do not initialize it, what is its value? (h) If I declare an int variable but do not initialize it, what is its value? (i) What is the name of the method that is run first when a Java program executes? (j) What is the return type of the method that is run first when a Java program executes? (a) (b) (c) (d) (e) (f) (g) (h) (i) (j) Page 1 of 8

2. True or false questions (a) An array can be returned by a method. (b) An object can not be passed as a parameter. (c) It is legal to have more than one constructor in a given class. (d) All the elements of an array must be the same type. (e) A method cannot call itself, either directly or indirectly. (f) String is a primitive type in Java. (g) An improperly indented java file will not compile. 3. Given the definitions below, evaluate the following boolean expressions to true or false. boolean apple = true ; boolean banana = false ; boolean kiwi = true ; boolean orange = false ; (a)!kiwi (b) apple && banana (c) apple banana orange (d)!apple (!banana && kiwi && orange) (e)!apple && (!banana kiwi orange) (f) (apple orange) && (banana orange) (a) (b) (c) (d) (e) (f) (g) (a) (b) (c) (d) (e) (f) Page 2 of 8

4. Why do the following code snippets not compile? (Explain in one sentence each.) (a) (3) int a = 1.0 / 3; (b) (3) String greeting = " hello " (c) (3) int [] numbers = int [ 25]; (d) (3) public class MyClass { private int x = 10; System. out. println (x); Page 3 of 8

5. The following Java program compiles and runs. What is its output? (13) public class MethodTest { public static String foo ( int a, String [] strs ) { int b = a % strs. length ; String c = strs [b]; System. out. println ("a = " + a + ", b = " + b + ", c = " + c); if(b == a) { strs [b] = " AAA "; return " equal "; else { strs [b] = " BBB "; return c; int a = 2; int b = 7; String [] c = new String []{ " apple ", " orange ", " banana "; System. out. println (a + ", " + foo (a, c )); System. out. println (b + ", " + foo (b, c )); for ( int i = 0; i < c. length ; i ++) { System. out. println (i + ", " + c[i ]); Page 4 of 8

6. The following Java program compiles and runs. What is its output? (12) Reminder: System.out.print will print its argument without going to a new line afterwards. public class ArrayTest { public static final int ROWS = 3; public static final int COLS = 4; public static void fillarray ( int [][] arr ) { int x = 0; for ( int c = 0; c < COLS ; c ++) { for ( int r = 0; r < ROWS ; r ++) { x += 2; arr [r][c] = x; public static void printarray ( int [][] arr ) { for ( int r = 0; r < ROWS ; r ++) { System. out. print ("[ "); // bracket at row start for ( int c = 0; c < COLS ; c ++) { System. out. print ( arr [r][c] + " "); System. out. println ("]"); // bracket and newline at row end int [][] grid = new int [ ROWS ][ COLS ]; fillarray ( grid ); printarray ( grid ); Page 5 of 8

7. The following Java program compiles and runs. What is its output? (10) public class Foo { private int x; public Foo ( int x) { this.x = x; public void printvals ( int x) { System. out. println ( this.x); System. out. println (x); int x = 2; Foo a = new Foo (x); x += 4; Foo b = new Foo (x); x - -; --x; a. printvals (x); x -= x; b. printvals (x); x += 1; System. out. println (x); Page 6 of 8

8. The following Java program compiles and runs. What are the first line, third line, and last line (10) of its output? (I don t want all the output, just the lines specified.) public class LoopNest { String [] modifier = new String []{ " Merry ", " Survive ", " Enjoy ", " Happy "; String [] occasion = new String []{ " Holidays ", " Christmas ", " Hanukkah ", " Winter Break ", " New Year ", " Finals Week "; for ( int a = 1; a < modifier. length ; ++a) { int b = occasion. length - a; while (b >= 0) { String greeting = modifier [ a] + " " + occasion [ b] + "!"; System. out. println ( greeting ); b - -; Page 7 of 8

9. Write a method that takes an array of strings and returns the average length of the strings in (10) the array, returning -1 if the array is empty. I have already given you the method header so you know the parameter and return types. The following examples are just to give you a feel for how it works. averagelength(new String[]{"hello", "goodbye") 6.0 averagelength(new String[]{"cat", "dog", "mouse", "bird") 3.75 averagelength(new String[]{) -1.0 averagelength(new String[]{"", "", "") 0.0 averagelength(new String[]{"I", "hope", "you", "have", "had", "fun") 3.0 public static double averagelength ( String [] strs ) { Page 8 of 8