Name CIS 201 Midterm II: Chapters 1-8

Similar documents
CSE 142 Sample Midterm Exam #3

CSE 142 Sample Midterm Exam #3

CSE 142 Sample Final Exam #2

CSE 142 Sample Final Exam #2

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

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

CSE 142, Autumn 2007 Midterm Exam, Friday, November 2, 2007

Building Java Programs A Back to Basics Approach 4th Edition Reges TEST BANK Full download at:

CSc 110 Sample Midterm Exam #2

CSE 142 Sample Midterm Exam #2

Computer Science E-119 Fall Problem Set 1. Due before lecture on Wednesday, September 26

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

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

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

CSE 142, Autumn 2010 Final Exam Wednesday, December 15, Name:

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

Practice Midterm 1. Problem Points Score TOTAL 50

CSC 240 Computer Science III Spring 2018 Midterm Exam. Name

CSE 142, Winter 2007 Final Exam. Name:

Final Exam COMP Fall 2004 Dec 16, 2004

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

CS 139 Practice Midterm Questions #2

Introduction to Software Development (ISD) Week 3

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

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

Midterm 1 Written Exam

CS170 Introduction to Computer Science Midterm 2

CSE142 Sample Midterm Autumn 2018

CS 101 Exam 2 Spring Id Name

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

CS Programming I: Arrays

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

COS 126 General Computer Science Fall Exam 1

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

CSE 142 SPRING 2008 FINAL EXAM

CIS 110 Introduction to Computer Programming Summer 2018 Final. Recitation # (e.g., 201):

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

Sample Midterm Exam #2

COMPUTER APPLICATIONS

CS2 Practical 1 CS2A 22/09/2004

Read and fill in this page now

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

(a) Assume that in a certain country, tax is payable at the following rates:

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

Midterm Review Session

b. Suppose you enter input from the console, when you run the program. What is the output?

Java Identifiers, Data Types & Variables

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

CSE 1223: Exam II Autumn 2016

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

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

COS 126 Midterm 1 Written Exam, Fall 2009

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

Spring 2013 COMP Midterm Exam Solutions March 07, 2013

CIS 110 Introduction to Computer Programming Summer 2018 Final. Recitation # (e.g., 201):

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

CSE 142 Sample Final Exam #1

Some Practice Midterm Problems

CS 113 MIDTERM EXAM 2 SPRING 2013

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

Practice Midterm 1 Answer Key

Computer Science E-119 Fall Problem Set 3. Due before lecture on Wednesday, October 31

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

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

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

10/30/2010. Introduction to Control Statements. The if and if-else Statements (cont.) Principal forms: JAVA CONTROL STATEMENTS SELECTION STATEMENTS

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

CSE413 Midterm. Question Max Points Total 100

University of Massachusetts Amherst, Electrical and Computer Engineering

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

CSEN 202: Introduction to Computer Programming Spring term Final Exam

Read and fill in this page now. Your lab section day and time: Name of the person sitting to your left: Name of the person sitting to your right:

Place your name tag here

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

Practice Midterm Examination

Java Tutorial. Saarland University. Ashkan Taslimi. Tutorial 3 September 6, 2011

Chapter 7 User-Defined Methods. Chapter Objectives

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CSE 142 Sample Final Exam #4 (based on Autumn 2008's final)

You will not be tested on JUnit or the Eclipse debugger. The exam does not cover interfaces.

University of Palestine. Mid Exam Total Grade: 100

CS 1083 Introduction to Programming I for Computer Scientists Sample Final Questions

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

CIS 110 Introduction to Computer Programming Summer 2018 Midterm. Recitation ROOM :

CSE142 Sample Midterm Spring Name UW NetId (e.g. whitab) Section (e.g., AA) TA

CS162 Computer Science I Fall 2018 Practice Exam 1 DRAFT (9 Oct.)

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Computer Science II Fall 2009

You must bring your ID to the exam.

CIS 265/506 Exam1 Spring 2012 Prof. V. Matos Exam Last Name First Name:

1 Short Answer (10 Points Each)

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

SEMESTER 1, 2011 EXAMINATIONS. CITS1200 Java Programming FAMILY NAME: GIVEN NAMES:

Java Simple Data Types

Final Exam Practice. Partial credit will be awarded.

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

Programming Basics. Digital Urban Visualization. People as Flows. ia

Arrays. Arrays. Wolfgang Schreiner Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria

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

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Transcription:

Name CIS 201 Midterm II: Chapters 1-8 December 15, 2010 Directions: This is a closed book, closed notes midterm. Place your answers in the space provided. The point value for each question is indicated. There are a total of 80 points on the short answer and 80 points on the programming portion for a total of 160 points that will be weighted to 100 points. You have 120 minutes for this final. Short Answer 1. ( 10 pts) For each expression in the left-hand column, indicate its value in the right-hand column. Be sure to list a constant of appropriate type (e.g., 7.0 rather than 7 for a double, Strings in "quotes"). Expression Value 8 + 5 * 3 / 2 1.5 * 4 * 7 / 8 + 3.4 73 % 10-6 % 10 + 28 % 3 4 + 1 + 9 + "." + (-3 + 10) + 11 / 3 3 / 14 / 7 / (1.0 * 2) + 10 / 6

2. (10 pts) At the bottom of the page, write the output produced by the following program, as it would appear on the console. public class ParameterMystery { public static void main(string[] args) { String a = "felt"; String b = "saw"; String c = "drew"; String saw = "sue"; String drew = "b"; mystery(a, b, c); mystery(b, a, saw); mystery(drew, c, saw); mystery("a", saw, drew); mystery(a, a, "drew"); public static void mystery(string b, String a, String c) { System.out.println(c + " " + a + " the " + b);

3. (10 pts) Consider the following Java method: // This method is supposed to return how many of its three // arguments are odd numbers public static int numberofodds(int n1, int n2, int n3) { int count = 0; if (n1 % 2!= 0) { count++; if (n2 % 2!= 0) { count++; if (n3 % 2!= 0) { count++; return count; If the method is correct, simply state that it is correct to answer this question. If it is incorrect, rewrite the code below.

4. (10 pts) Consider the following Java method: // This method is supposed to return true if the String str contains the // character ch and false otherwise public static boolean contains (String str, char ch) { boolean found = false; for (int i = 0; i< str.length(); i++) { if (str.charat(i) == ch) { found = true; else { found = false; return found; If the method is correct, simply state that it is correct to answer this question. If it is incorrect, rewrite the code below.

5. ( 10 pts) What is the output of the following program? public class Mystery { public static void main (String [] args) { int x = 1; int [] a = new int[2]; mystery(a, x); System.out.println(x + + a[0] + + a[1]); x--; a[1] = a.length; mystery(a, x); System.out.println(x + + a[0] + + a[1]); public static void mystery(int[] list, int x) { list[x]++; x++; System.out.println(x + + list[0] + + list[1]);

6. (10 pts) Consider the following method: public static void mystery(int [] data, int x, int y) { data[data[x]] = data[y]; data[y] = x; What are the values of the elements in the array numbers after the following code executes? int [] numbers = {3, 7, 1, 0, 25, 4, 18, -1, 5; mystery(numbers, 3, 1); mystery(numbers, 5, 6); mystery(numbers, 8, 4);

7. (10 pts) Consider the following class definition: public class Book { private String title; private String author; private int numberofpages; public Book (String t, String a, int n) { String title = t; String author = a; int numberofpages = n; public String tostring() { return title + by + author + : + numberofpages + pages ; What is the output printed by the following client code segment? Book b = new Book( The Black Stallion, Walter Farley, 245); System.out.println(b);

8. (10 pts) List the three uses of a class in Java and briefly state what each use is for.

Programming Exercises: There are 4 exercises to complete in this part of the exam. Each is worth 20 pts. Enter the following copy command: cp r /home/student/classes/201/2009. 9. (20 pts) Change into directory 2009 and open Nine.java. You are not allowed to change the main() except to comment out specific lines to test certain cases. Write a method named before that takes as parameters two month/day combinations and that returns whether or not the first date comes before the second date (true if the first month/day comes before the second month/day, false if it does not). The method will take four integers as parameters that represent the two month/day combinations. The first integer in each pair represents the month and will be a value between 1 and 12 (1 for January, 2 for February, etc, up to 12 for December). The second integer in each pair represents the day of the month (a value between 1 and 31). One date is considered to come before another if it comes earlier in the year. For example, the call: before(6, 3, 9, 20) should return true because June 3rd (6/3) comes before September 20th (9/20). By contrast, the call: before(10, 1, 2, 25) should return false because October 1st (10/1) comes after February 25th (2/25). If the same date is passed twice, your method should return false. For example: before(8, 15, 8, 15) should return false because August 15th (8/15) does not come before August 15th (8/15). You may assume that your method is passed values that represent legal dates. If your method is working correctly, when you run Nine.java, you should get all trues printed out. When you are ready: submit 201 Nine.java

10. (20 pts) Open Ten.java. You are not allowed to change the main() except to comment out specific lines to test certain cases. Write a method named longestword() that accepts a String as its parameter and returns the length of the longest word in the string. A word is a sequence of one or more nonspace characters (any character other than the space character, ' ' ). Here are some example calls to your method and their expected results: Call Value returned longestword("to be or not to be") 3 longestword("oh hello, how are you?") 6 longestword("i am OK") 2 longestword(" this example has many spaces ") 7 longestword("test") 4 longestword("") 0 longestword(" ") 0 Note that the string might be empty, might not contain any words, might begin with spaces, and might contain words separated by multiple spaces. You may assume that the string doesn't contain any other whitespace characters such as tabs or newlines. For full credit, you may not use a Scanner. However, use one for partial credit if you have to. If your method is working correctly, when you run Ten.java, you should get all trues printed out. When you are ready: submit 201 Ten.java

11. (20 pts) Open Eleven.java. You are not allowed to change the main() except to comment out specific lines to test certain cases. Write a method named mingap that accepts an integer array as a parameter and returns the minimum 'gap' between adjacent values in the array. The gap between two adjacent values in a array is defined as the second value minus the first value. For example, suppose a variable called array is an array of integers that stores the following sequence of values. int[] array = {1, 3, 6, 7, 12; The first gap is 2 (3-1), the second gap is 3 (6-3), the third gap is 1 (7-6) and the fourth gap is 5 (12-7). Thus, the call of mingap(array) should return 1 because that is the smallest gap in the array. Notice that the minimum gap could be a negative number. For example, if array stores the following sequence of values: {3, 5, 11, 4, 8 The gaps would be computed as 2 (5-3), 6 (11-5), -7 (4-11), and 4 (8-4). Of these values, -7 is the smallest, so it would be returned. If you are passed an array with fewer than 2 elements, you should return 0. If your method is working correctly, when you run Eleven.java, you should get all trues printed out. When you are ready: submit 201 Eleven.java

12. (20 pts) Open the Twelve.java. This is client code that uses a class Rectangle that you write. You are not allowed to change the main() except to comment out specific lines to test certain cases. a. Each Rectangle has a length and a width which are the fields of the Rectangle. b. There is one constructor for a Rectangle. The constructor takes two integers, a length and a width that become the field values of this new Rectangle. For example: Rectangle r1 = new Rectangle(5, 3); constructs a new Rectangle with a length of 5 and a width of 3. c. Write an area() method for Rectangles. When area() is called on a Rectangle, its area is returned as an integer. For example, for the Rectangle in b, r1.area() would be 15. d. Write an issquare() method for Rectangles. When issquare() is called on a Rectangle, it returns true if the Rectangle is also a square and false if it is not. A Rectangle is a square if its length and width are equal. For example, for the Rectangle in b, r1.issquare() would be false. e. Write a method for Rectangles so that Rectangles can return a String representation of themselves for printing. The String representation should include the Rectangle s length and width followed by the word rectangle. For example, for the Rectangle in b, System.out.println(r1); should result in the output 5 X 3 rectangle If your Rectangle class is working correctly, when you run Twelve.java, you should get the following output 5 X 3 rectangle true true 5 X 5 rectangle true true When you are ready: submit 201 Rectangle.java