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

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

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

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

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

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

This exam is open book. Each question is worth 3 points.

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

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, 17 December 2009

CS 113 PRACTICE FINAL

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

Final Examination Semester 3 / Year 2008

Page 1 / 3. Page 2 / 18. Page 3 / 8. Page 4 / 21. Page 5 / 15. Page 6 / 20. Page 7 / 15. Total / 100. Pledge:

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

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

F I N A L E X A M I N A T I O N

1. An operation in which an overall value is computed incrementally, often using a loop.

Two hours QUESTION PAPER MUST NOT BE REMOVED FROM THE EXAM ROOM UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE

CS 101 Exam 2 Spring Id Name

Example Program. public class ComputeArea {

CS 101 Fall 2006 Midterm 1 Name: ID:

CS 113 MIDTERM EXAM 2 SPRING 2013

Second Exam SAMPLE Computer Programming 338 Dr. St. John Lehman College City University of New York Tuesday, 5 April 2011

JAVA Ch. 4. Variables and Constants Lawrenceville Press

CS 101 Exam 1 Spring 200 Id Name

CS 101 Spring 2007 Midterm 2 Name: ID:

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

Chapter 4: Control Structures I

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course

Faculty of Science COMP-202A - Foundations of Computing (Fall 2012) - All Sections Midterm Examination

Exam I Computer Science 420 Dr. St. John Lehman College City University of New York 12 March 2002

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

IT 313 Advanced Application Development Midterm Exam

CSE 1223: Exam II Autumn 2016

CMPS 134: Computer Science I Fall 2011 Test #1 October 5 Name Dr. McCloskey

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

Object Oriented Programming. Java-Lecture 1

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to write programs for executing statements repeatedly using a while, do while and for loop

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

CS61BL. Lecture 1: Welcome to CS61BL! Intro to Java and OOP Testing Error-handling

COSC 123 Computer Creativity. I/O Streams and Exceptions. Dr. Ramon Lawrence University of British Columbia Okanagan

CS 132 Midterm Exam Fall 2004

Loops. Eng. Mohammed Abdualal. Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department

Dining philosophers (cont)

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

10/3/2018 Programming Data Structures. Casting: upcasting, downcasting Debugging again! Yay! Exception Handling

Assignment 1 due Monday at 11:59pm

Final. Your Name CS Fall 2014 December 13, points total Your Instructor and Section

Full file at Chapter 2 - Inheritance and Exception Handling

Ryerson University Vers HAL6891A-05 School of Computer Science CPS109 Midterm Test Fall 05 page 1 of 6

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

Problem Grade Total

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

EXAMINATION FOR THE BSC (HONS) INFORMATION TECHNOLOGY; BSC (HONS) INFORMATION SYSTEMS & BSC (HONS) COMPUTER SCIENCE; YEAR 1

Midterm Exam 2 CS 455, Spring 2013

CS212 Midterm. 1. Read the following code fragments and answer the questions.

NATIONAL UNIVERSITY OF SINGAPORE

Fundamentals of Object Oriented Programming

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2014

NoSuchElementException 5. Name of the Exception that occurs when you try to read past the end of the input data in a file.

CS 101 Fall 2006 Midterm 3 Name: ID:

Introduction to Programming Using Java (98-388)

CSC Java Programming, Fall Java Data Types and Control Constructs

File class in Java. Scanner reminder. File methods 10/28/14. File Input and Output (Savitch, Chapter 10)

First Name: AITI 2004: Exam 2 July 19, 2004

CS 101 Fall 2005 Midterm 2 Name: ID:

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

CMSC 331 Second Midterm Exam

H212 Introduction to Software Systems Honors

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

COP 3330 Final Exam Review

CSC 1214: Object-Oriented Programming

I. True/False: (2 points each)

CS1083 Week 2: Arrays, ArrayList

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

B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA

Introduction to Computer Science I

Exam Duration: 2hrs and 30min Software Design

CSCE 145 Exam 2 Review No Answers. This exam totals to 100 points. Follow the instructions. Good luck!

CMSC132 Summer 2018 Midterm 1

Name CIS 201 Midterm II: Chapters 1-8

COE 212 Engineering Programming. Welcome to Exam I Thursday June 21, Instructor: Dr. Wissam F. Fawaz

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

Name Section Number. CS210 Exam #2 *** PLEASE TURN OFF ALL CELL PHONES*** Practice

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

CSE 143 Lecture 25. I/O Streams; Exceptions; Inheritance. read 9.3, 6.4. slides adapted from Marty Stepp

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

CS115. Chapter 17 Exception Handling. Prof. Joe X. Zhou Department of Computer Science. To know what is exception and what is exception handling

Object Oriented Programming 2014/15. Final Exam July 3, 2015

BBM 102 Introduction to Programming II Spring Exceptions

Data dependent execution order data dependent control flow

CMPT 125: Lecture 4 Conditionals and Loops

Loops. CSE 114, Computer Science 1 Stony Brook University

Week 14 Lab A Linked List of Integers Maximum Points = 10

First Name: AITI 2004: Exam 2 July 19, 2004

Objects and Classes 1: Encapsulation, Strings and Things CSC 121 Fall 2014 Howard Rosenthal

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

CMP 326 Midterm Fall 2015

CSE 142, Spring 2009, Sample Final Exam #2. Good luck!

Transcription:

SAMPLE EXAM Second Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 11 November 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) (d) (e) (f) (g) (h) (i) (j) Objects having the same interface can be used interchangeably. Only one class can implement any interface. A final class is always a base class. All methods are inherited by a derived class, including the private methods. You can create an object of an abstract class. Even if an exception occurs within a try block, the entire block is executed. A method that does not handle an exception must have a throws clause in a header. Objects of type implementable can be written to a binary file. You can write values of any primitive type to a binary file. A flow of data into or out of a program is called a stream. 2. (a) Define a Java interface and give an example. (b) Circle all of the following that are included in an interface: public constructors headings of private instance constants public methods variables 3. (a) Write the statement that will throw a new exception with the message File Not Found : (b) Write a try-block that divides x by y: (c) Write the first line of a java class called Truck than extends the class Vehicle: (d) Write the first line of a java class called Hexagon than implements the interface Measurable: 2

4. Given the classes: public class Mystery { private int x; private String s; Mystery() { x = -10; s = "???"; Mystery(int i) { x = i; s = "!!!"; public String tostring() { return(x+" "+s+" "+x); public int get() { return (x); public class Enigma extends Mystery { private double code; Enigma() { super(); code = 3.1459; Enigma(int i, double j){ super(i); code = j; public String tostring() { return(super.tostring()+" "+code); Assume the following code has been executed: Mystery first = new Mystery(); Enigma second = new Enigma(); Enigma third = new Enigma(5,10.01); What is the output from the following statements? (a) System.out.print(first); (b) System.out.print(second); (c) System.out.print(third); (d) System.out.print(first.get()); (e) System.out.print(second.get()); 3

5. Given the following program: import java.util.*; public class ModProgram { public static void main(string[] args) { System.out.println("Welcome to the modulus computer"); Scanner reader = new Scanner(System.in); boolean done = false; while(!done){ System.out.println("Enter two integer values"); try{ int first = reader.nextint(); int second = reader.nextint(); System.out.println(first+" mod "+second+" is "+(first % second)); catch (ArithmeticException e){ System.out.println("Sorry, can not compute mod by 0"); catch (Exception e) { System.out.println("Sorry, you must enter two integer values"); reader.nextline(); System.out.println("Do another pair of values? (y)"); String response = reader.next().tolowercase(); if(!response.equals("y")) done = true; (a) What is the output of the program if the user enters: 10 3? (b) What is the output of the program if the user enters: 5 0? 4

6. Assuming istream has been instantiated and linked to the file shown, what is the output of the following? (a) File: while (istream.hasnextline()) 1 2 { Buckle my shoe String line = istream.nextline(); 3 4 line = line.substring(0,2); Open the door System.out.println(line); (b) File: while (istream.hasnextint()) 1 2 { Buckle my shoe int line = istream.nextint(); 3 4 System.out.println(line); Open the door (c) File: int count = 0; 1 2 while ( count < 3) Buckle my shoe { 3 4 String line = istream.nextline(); Open the door count++; System.out.println(line); (d) File: int count = 0; 1 2 while (istream.hasnextline()) Buckle my shoe { 3 4 String line = istream.nextline(); Open the door count= line.length(); System.out.println(count); 5

7. (a) Write a method that takes as input a input stream and returns the first line: public static String messagetofile( Scanner in ) { (b) Write a method that takes a file as input, and returns true if the file exists and can be written to. Otherwise, it returns false: public static boolean ismodifiable( File f ) { (c) Write a method that takes a file name, and returns the number of lines in the file. (Note: you should open the file and handle any exceptions.) public static int linecount( String filename ) { 6

8. Create an abstract class DiscountPolicy. It should have a single abstract method computediscount() that will return the discount for the purchase of a given number of a single item. The method has two parameters, count and itemcost. 7

9. Derive a class BulkDiscount from DiscountPolicy, as described above. It should have a constructor that has two parameters, minimum and percent. It should define the method computediscount() so that if the quantity purchased of an item is more than minimum, the discount is percent percent. 8

10. Write a complete program that asks the user for the name of an input and output file and copies the contents of the input file to the output file. 9