MACS 261J Final Exam. Question: Total Points: Score:

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

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

All classes in a package can be imported by using only one import statement. If the postcondition of a method is not met, blame its implementer

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

CS 455 Midterm Exam 1 Spring 2015 [Bono] Thursday, Feb. 19, 2015

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

ANSWERS. Birkbeck (University of London) Software and Programming 1 In-class Test Feb Student Name Student Number. Answer all questions

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

Midterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009

COS 126 General Computer Science Spring Written Exam 2

ANSWERS. Birkbeck (University of London) Software and Programming 1 In-class Test Feb Student Name Student Number. Answer all questions

Chapter 2: Basic Elements of Java

YOU ARE ALLOWED TO HAVE ONLY THE FOLLOWING ON YOUR DESK OR WORKTABLE:

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

Tutorial No. 2 - Solution (Overview of C)

CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011

Selections. CSE 114, Computer Science 1 Stony Brook University

CMPS 12A - Winter 2002 Midterm 2 March 5, Name: ID:

1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.

int a; int b = 3; for (a = 0; a < 8 b < 20; a++) {a = a + b; b = b + a;}

CSE 20. SAMPLE FINAL Version A Time: 180 minutes. The following precedence table is provided for your use:

Datatypes, Variables, and Operations

8. Functions (II) Control Structures: Arguments passed by value and by reference int x=5, y=3, z; z = addition ( x, y );

Chapter 5 Lab Methods

CS 455 Midterm Exam 1 Fall 2017 [Bono] Thursday, Sep. 28, 2017

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

16-Dec-10. Consider the following method:

LAB 1 INTRODUCTION TO LINUX ENVIRONMENT AND C COMPILER

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

PIC 10A. Lecture 17: Classes III, overloading

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

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

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

CEN 414 Java Programming

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

COS 126 General Computer Science Spring Written Exam 1

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

CSC 1051 Arrays - Review questions

Chapter 5 Lab Methods

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

COS 126 Midterm 1 Written Exam Fall 2011

ESC101 : Fundamental of Computing

PIC 10A. Lecture 15: User Defined Classes

CMPT-166: Sample Final Exam Answer Key

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

Question 2. [5 points] Given the following symbolic constant definition

CSE351 Winter 2016, Final Examination March 16, 2016

Department of Civil and Environmental Engineering, Spring Semester, ENCE 688R: Midterm Exam: 1 1/2 Hours, Open Book and Open Notes

Lesson 02 Data Types and Statements. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

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

Final Exam. COMP Summer I June 26, points

Chapter 5 Lab Methods

Lesson 02 Data Types and Statements. MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

1. [3 pts] What is your section number, the period your discussion meets, and the name of your discussion leader?

Computer System and programming in C

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

Chapter 2 Elementary Programming

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

Chapter 8: Intraprogram Communication. Lecture 8 1

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

CSE wi Midterm Exam 2/8/18. Name UW ID #

CS 177 Week 15 Recitation Slides. Review

Examination in Compilers, EDAN65

Quiz. Programming Languages. CSE 130 : Fall Lecture 16: Static Types for Objects. Ranjit Jhala UC San Diego

CSE 333 Midterm Exam 2/14/14

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

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

Variables and literals

University of Toronto

a. a * c - 10 = b. a % b + (a * d) + 7 =

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

A Java program contains at least one class definition.

CSCI 102 Fall 2010 Exam #1

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

Data Structures CSCI C343, Fall 2016 [B]

Computer Programming, I. Laboratory Manual. Experiment #3. Selections

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

CSE 1223: Exam II Autumn 2016

CS 455 Final Exam Fall 2016 [Bono] December 13, 2016

Spring 2013 COMP Midterm Exam Solutions March 07, 2013

Introduction to C CMSC 104 Spring 2014, Section 02, Lecture 6 Jason Tang

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

Basic Operations jgrasp debugger Writing Programs & Checkstyle

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

Q1: C input/output; operators / 46 Q2: Conditional statements / 34 Q3: While and do-while loops / 20 TOTAL SCORE / 100 Q4: EXTRA CREDIT / 10

CS 455 Midterm Exam 1 Fall 2015 [Bono] Thursday, Oct. 1, 2015

***PRACTICE EXAM 02 for*** CS16 Midterm Exam 2 E02, 09F, Phill Conrad, UC Santa Barbara Actual exam scheduled for: 11/18/2009

CMSC 313 Fall2009 Midterm Exam 1 Section 01 October 12, 2009

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Q1: /20 Q2: /30 Q3: /24 Q4: /26. Total: /100

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

CSE 331 Final Exam 12/9/13

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

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks:

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #05

CSE 142 Su01 Midterm 1 Sample Solution page 1 of 5

Transcription:

MACS 261J Final Exam May 5, 2008 Name: Question: 1 2 3 4 5 6 7 8 9 Total Points: 15 10 15 5 10 5 20 8 12 100 Score: Question 1............................................................. (15 points) (a) [5 points] Write a complete Java program that computes and prints the area of a circle with radius 5. (b) [5 points] Show how you would modify the program above to prompt the user for a radius on the command line, and then compute and print the area of a circle for that radius. Do not rewrite the entire program. Just indicate which line(s) you would replace, and what you would replace them with. (c) [5 points] Show how you would modify the program above to exit gracefully in the exceptional cases where (a) the user enters something that is not a number or (b) enters a negative radius. Again, do not rewrite the entire program.

Question 2............................................................. (10 points) Consider the method foo defined by: public static void foo(double[] a) { double b = 0.0; for (int i=0; i<a.length; ++i) { if (b<a[i]) b = a[i]; return b; (a) [2 points] This code will not compile without error. Fix it. (b) [3 points] What does the following program fragment print? double[] a1 = { 1.0, 3.0, 2.0; double[] a2 = { 1.0, 0.0,-1.0; double[] a3 = {-1.0,-3.0,-2.0; System.out.println(foo(a1)); System.out.println(foo(a2)); System.out.println(foo(a3)); (c) [3 points] Rename the method foo to better describe what it is supposed to do. (d) [2 points] The three tests cases printed above reveal a likely bug. (It s a common error.) Modify the method so that it does what is likely intended.

Question 3............................................................. (15 points) (a) [10 points] Implement the following method as specified: * while n is greater than 1 { * prints the value of n followed by a blank space * if n is even, * replaces n with n/2 * otherwise if n is odd, * replaces n with 3*n+1 * * prints the value of n followed by a newline public static void goofy(int n) { (b) [5 points] Assuming that you have implemented this method as specified, what sequence of numbers is printed by the following program fragment? for (int i=1; i<=4; ++i) goofy(i); Question 4.............................................................. (5 points) (a) [2 points] Given two Java floats x and y, how would you determine if they are equal? (b) [3 points] Given two Java Strings s and t, how would you determine if they are equal?

Question 5............................................................. (10 points) Complete the following methods: (a) [5 points] * Returns a new array that contains the elements in two arrays. * Specifically, for a specified array x with m floats and array * y with n floats, this method returns an array with m+n floats, * with the elements in x followed by those in y. public static float[] combine(float[] x, float[] y) { (b) [5 points] * Returns the number of floats in an array of array of floats. * (Assumes that the lengths of the arrays of floats may vary.) public static int count(float[][] x) { Question 6.............................................................. (5 points) (a) [1 point] How many bits in a Java byte? (b) [1 point] How many bytes in a Java int? (c) [1 point] How many bytes in a Java short? (d) [1 point] How many bytes in a Java float? (e) [1 point] How many bytes in a Java double?

Question 7............................................................. (20 points) Complete the class Point by filling in the blanks below. public class Point { * Constructs a point with specified (x,y) coordinates. * @param x the x coordinate. * @param y the y coordinate. public Point(double x, double y) { * Moves this point by the specified amounts. * @param dx amount to add to the x coordinate of this point. * @param dy amount to add to the y coordinate of this point. public void move(double dx, double dy) { * Returns the distance between this point and another point. * @param p the other point. * @return the distance. public double distanceto(point p) { * Returns a new point with the same coordinates as this point. * @return the new point. public Point clone() {

Question 8.............................................................. (8 points) Using every method in the class Point defined above,... (a) [2 points] Construct a Point p with coordinates (2, 1). (b) [2 points] Get a copy Point q of the Point p. (c) [2 points] Move q a distance of 3 in any direction. (d) [2 points] Print the distance between p and q. Question 9............................................................. (12 points) Consider a binary file with exactly 100,000 floats that represent an image. (a) [2 points] Why would we typically not store this image as a text file? (b) [2 points] Augment the javadoc comments and declaration of the method readimage below to include any extra information you would need to extract the image from the file. (c) [8 points] Complete the method readimage as specified. * Returns the image stored in the specified file. * @param filename name of the file containing the image. * * * @return array of arrays of floats containing the image. static float[][] readimage(string filename, ) {