First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010

Similar documents
ANSWER KEY First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010

Final Exam Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 20 May 2010

SAMPLE Final Exam Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 17 December 2009

Final Exam Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 17 December 2009

Second Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 11 November 2010

SAMPLE EXAM Second Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 11 November 2010

SAMPLE EXAM Final Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 16 December 2010

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

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

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

CMP 326 Midterm Fall 2015

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

Building Java Programs. Chapter 2: Primitive Data and Definite Loops

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

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

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

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Tutorial 6 CSC 201. Java Programming Concepts مبادئ الربجمة باستخدام اجلافا

SAMPLE EXAM Exam 2 Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 5 November 2009

York University AK/ITEC OBJECT-BASED PROGRAMMING. Midterm Test Sample. Examiner: S.Y. Chen Duration: One Hour and Fifteen Minutes

Final Exam. COMP Summer I June 26, points

Assignment 1 due Monday at 11:59pm

Building Java Programs

CS 102/107 - Introduction to Programming Midterm Exam #2 - Prof. Reed Spring 2011

CS 101 Exam 2 Spring Id Name

This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for computing and/or communicating) is NOT permitted.

I. True/False: (2 points each)

COS 126 Midterm 1 Written Exam, Fall 2009

Building Java Programs

Building Java Programs

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

I. True/False: (2 points each) On your bubble form fill out a for true and b for false.

Programming with Java

Problem Grade Total

if (x == 0); System.out.println( x=0 ); if (x = 0) System.out.println( x=0 );

1.00/1.001 Introduction to Computers and Engineering Problem Solving Spring Quiz 1

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

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination

I. True/False: (2 points each)

CSE 142, Autumn 2008 Midterm Exam, Friday, October 31, 2008

Question: Total Points: Score:

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

NATIONAL UNIVERSITY OF SINGAPORE

CSE 1223: Exam II Autumn 2016

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

Selected Questions from by Nageshwara Rao

WES-CS GROUP MEETING #9

Place your name tag here

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

Birkbeck (University of London) Software and Programming 1 In-class Test Mar Answer ALL Questions

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External

CSE 142, Autumn 2011 Midterm Exam: Friday, November 4, 2011

Exam II Computer Programming 420 Dr. St. John Lehman College City University of New York 20 November 2001

I. True/False: (2 points each)

Prelim 1. CS 2110, 13 March 2018, 5:30 PM Total Question Name Short answer

Introduction to Programming Using Java (98-388)

1 If you want to store a letter grade (like a course grade) which variable type would you use? a. int b. String c. char d. boolean

Lec 3. Compilers, Debugging, Hello World, and Variables

Final Examination Computer Science 420 Dr. St. John Lehman College City University of New York 21 May 2002

1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 4, 2005

CS 113 MIDTERM EXAM 2 SPRING 2013

CS 102 / CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2010

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

Bjarne Stroustrup. creator of C++

CS 101 Spring 2007 Midterm 2 Name: ID:

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

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring What is your name?: (4 points for writing it on your answer sheet)

TOPIC 12 CREATING CLASSES PART 1

Midterm Exam CS 251, Intermediate Programming March 6, 2015

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

Practice Midterm 1. Problem Points Score TOTAL 50

University of Palestine. Mid Exam Total Grade: 100

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

Computer Programming, I. Laboratory Manual. Final Exam Solution

I. True/False: (2 points each)

CSCI 201L Written Exam #1 Fall % of course grade

Final Exam CS 251, Intermediate Programming December 13, 2017

CSE 142, Summer 2013 Midterm Exam, Friday, July 26, 2013

CS 113 PRACTICE FINAL

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

CSC207H: Software Design. Java + OOP. CSC207 Winter 2018

Building Java Programs Sample Final Exam #1. Name of Student. Section (e.g., AA)

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

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

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ June Exam

CS 101 Exam 1 Spring 200 Id Name

CSE 114 Midterm 1. Please leave one seat between yourself and each of your neighbors.

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

16. Give a detailed algorithm for making a peanut butter and jelly sandwich.

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

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

Arrays. COMS W1007 Introduction to Computer Science. Christopher Conway 10 June 2003

Topic 4 Expressions and variables

SFWR ENG/COMP SCI 2S03 Principles of Programming SOLUTIONS

Transcription:

First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010 NAME (Printed) NAME (Signed) E-mail Exam Rules Show all your work. Your grade will be based on the work shown. The exam is closed book and closed notes. When taking the exam, you may have with you pens or pencils, and an 8 1/2 x 11 piece of paper filled with notes, programs, etc. You may not use a computer or calculator. All books and bags must be left at the front of the classroom during this exam. Do not open this exams until instructed to do so. Question 1 Question 2 Question 3 Question 4 Question 5 Question 6 Question 7 Question 8 Question 9 Question 10 TOTAL 1

1. True or False: (a) (b) (c) An algorithm is a a set of directions for solving a problem. You can use the symbol to indicate the concatenation of two strings. The switch and while statements are examples of branching statements. (d) Arrays always start with an index of 1. (e) (f) (g) (h) (i) (j) Everything that can be done with for statement can be done with a while statement. In Java, all variables are local. The operators = and == perform the same action. Arrays cannot be parameters (inputs) to a method. Constructors must have parameters. A static variable is shared by all the objects of its class. 2. Write the Java code that declares and instantiates: (a) a integer count that holds the number 1: (b) a double pi which is 3.1459: (c) a string lastname that holds your name: (d) an array friends of 10 Person objects: (e) that converts the string inputstring into an integer, x: 2

3. What is the output of the following code fragments: (a) (b) (c) (d) int numtimes = 5; while ( numtimes >= 2 ) System.out.print("Hi!"); numtimes--; System.out.print("Bye!"); boolean done = false; int total = 5; while (!done ) if ( total > 4 ) done = true; total = total*2; System.out.println(total); int i, j; for ( i = 3 ; i > 0 ; i--) for ( j = 0 ; j < i ; j++) System.out.print("*"); System.out.println(); int i, j; for ( i = 0 ; i < 4 ; i++) for ( j = 0 ; j < 4 ; j++) if ( i+j > 3 ) System.out.print("+"); else System.out.print("-"); System.out.println(); 3

4. What is the output when the code is run? (a) (b) char[] letters = a, z, e, b, r, a int m = 0; for (int i = 1; i < letters.length; i++) if ( letters[i] > letters[m] ) m = i; System.out.println(i + ": " + letters[i] + " " + letters[m]); double[] s = 5,1.2, 0.3, 5.89, 2, 0.1 for (int i = 0; i < s.length-1; i++) for (int j=0; j < s.length-1; j++) if ( s[j] > s [j+1] ) double tmp = s[j]; s[j] = s[j+1]; s[j+1] = tmp; System.out.print(s[j] + " "); System.out.println(); 5. Declare and instantiate the following arrays: (a) an array, scores, that holds ten integers: (b) an array, even, that holds the even numbers from 0 to 10: (c) a 2 dimensional array, board, of 3 rows by 4 columns of characters: 4

6. Assume the following class definition: public class Mystery public int[] numbers; public String message; public Mystery() numbers = 1,2,3; message = "Hello"; public String tostring() return(numbers.length+" "+message); public void query() int i; System.out.print(message); for ( i = 0 ; i < numbers.length ; i++ ) System.out.print(numbers[i] + " "); System.out.println(); and the following code has been executed: Mystery first = new Mystery(); Mystery second; first.numbers[0] = 4; first.message = "Hi"; second = new Mystery(); second.numbers[1] = 2*first.numbers[1]; What is the output from the following statements? (a) System.out.print(first.message); (b) first.query(); (c) System.out.print(first); (d) second.query(); (e) System.out.print(second); 5

7. Examine the class below and answer the following: (a) What is the output of this program? (b) How many times is the first getaverage() method called? (c) How many times is the last getaverage() method called? (d) In your own words, describe how the compiler decides which of the getaverage() methods to call: public class Overload public static void main(string[] args) double average1 = Overload.getAverage(40.0, 50.0); double average2 = Overload.getAverage(1.0, 2.0, 3.0); char average3 = Overload.getAverage( a, c ); System.out.println("average1 = " + average1); System.out.println("average2 = " + average2); System.out.println("average3 = " + average3); public static double getaverage(double first, double second) return (first + second) / 2.0; public static double getaverage(double first, double second, double third) return (first + second + third) / 3.0; public static char getaverage(char first, char second) return (char)(((int)first + (int)second) / 2); 6

8. (a) Write a method that returns the maximum of two integers: public static int max(int first, int last) (b) Write a method that takes an array of real numbers and returns the average number: public static double average( double[] in) (c) Write a method that interchanges two elements in an array of String at the given indices public static void swap( String[] a, int first, int last) 7

9. Fill in the following class that holds information about a student. Each of the methods of the class is proceeded by a comment that explains what the method should do. Fill in each method with the appropriate code: public class Student public String name; //Student s name public int studentid; //Student ID number public int numcredits; //Number of credits completed public String[] currentcourses; //Names of current classes public Student(String t, int n, int m, String[] c) name = t; studentid = n; numcredits = m; currentcourses = c; /* Returns the student ID number. */ public int getid() /* Set the student ID number. */ public void setid(int n) /* Returns all the information about the student (including the current courses): */ public String tostring() /* Returns true if taken more than 60 credits, otherwise returns false*/ public boolean isupperclassman() 8

10. Create a new class called Lighten that implements ActionListener. Your class has access to a global variable picture of the Picture class and pictureframe of class PictureFrame. Your class should refresh the pictureframe with a lighter version of the picture. class Lighten implements ActionListener public void actionperformed (ActionEvent e) The API for the Picture and Pixel classes are included on the next page: 9

10