CS 101 Exam 2 Spring Id Name

Similar documents
Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

CS 101 Exam 1 Spring 200 Id Name

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 open book. Each question is worth 3 points.

CS 101 Spring 2007 Midterm 2 Name: ID:

CS 101 Fall 2006 Midterm 3 Name: ID:

CS 101 Fall 2005 Midterm 2 Name: ID:

Practice Midterm 1. Problem Points Score TOTAL 50

COS 126 General Computer Science Spring Written Exam 1

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

Controls Structure for Repetition

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

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

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

CSC 240 Computer Science III Spring 2018 Midterm Exam. Name

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

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

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

JAVA OPERATORS GENERAL

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

H212 Introduction to Software Systems Honors

CS 302 Week 9. Jim Williams

CS180. Exam 1 Review

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods

Handout 7. Defining Classes part 1. Instance variables and instance methods.

Exam Duration: 2hrs and 30min Software Design

ENGR 2710U Midterm Exam UOIT SOLUTION SHEET

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

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Key Java Simple Data Types

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

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

1. Reference Mystery, 5 points. What output is produced by this program? import java.util.*;

CSE 1223: Exam II Autumn 2016

Midterm Examination (MTA)

Java Simple Data Types

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

Final Exam COMP Fall 2004 Dec 16, 2004

Practice Midterm 1 Answer Key

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

CS111: PROGRAMMING LANGUAGE II

Boolean Expressions. So, for example, here are the results of several simple Boolean expressions:

CS 101 Fall 2006 Midterm 1 Name: ID:

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

Name CIS 201 Midterm II: Chapters 1-8

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CS 113 PRACTICE FINAL

AP COMPUTER SCIENCE A

Problem Grade Total

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

Question: Total Points: Score:

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

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

Prelim One Solution. CS211 Fall Name. NetID

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

Final Exam. COMP Summer I June 26, points

CS170 (005): Introduction to Computer Science Exam 2

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

CSE 143 SAMPLE MIDTERM

Chapter 6 Lab Classes and Objects

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

CMP 326 Midterm Fall 2015

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

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

CS 113 MIDTERM EXAM 2 SPRING 2013

COS 126 Midterm 1 Written Exam, Fall 2009

1 Method Signatures and Overloading (3 minutes, 2 points)

Question: Total Points: Score:

Selenium Class 9 - Java Operators

CSC 172 Intermediate Progamming

CSE 142 Sample Midterm Exam #3

COS 126 General Computer Science Fall Written Exam 1

King Saud University College of Computer and Information Sciences Computer Science Department

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

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

CSE 142 SPRING 2008 FINAL EXAM

Loops. CSE 114, Computer Science 1 Stony Brook University

CSCI 111 Midterm Spring 2014

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

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

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

CS 3360 Design and Implementation of Programming Languages. Exam 1

Place your name tag here

Section 002 Spring CS 170 Exam 1. Name (print): Instructions:

AP CS Unit 3: Control Structures Notes

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

CS 101 Spring 2006 Final Exam Name: ID:

CSC 1051 Algorithms and Data Structures I. Final Examination May 2, Name:

CSCI 355 Lab #2 Spring 2007

CompSci 125 Lecture 11

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

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

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

Lecture 5: Methods CS2301

CSCI 355 LAB #2 Spring 2004

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

Java Simple Data Types

Lab Exercise 1. Objectives: Part 1. Introduction

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

1 Short Answer (15 Points Each)

Transcription:

CS 101 Exam 2 Spring 2005 Email Id Name This exam is open text book and closed notes. Different questions have different points associated with them. Because your goal is to maximize your number of points, we recommend that you do not spend too long on any particular question during your first pass through the exam. Assume stdin is an initialized Scanner throughout the test. In questions asking whether two object references are the same we are asking whether they represent like objects (i.e., we are not asking whether the references point to the same memory location). Page 1 / 5 Page 3 / 18 Page 4 / 12 Page 5 / 14 Page 6 / 9 Page 7 / 21 Page 8 / 21 Page 8 / 20 Pledge: Total / 100 1. (5 points) What section of CS101 are you in? 2 CS101E 3 0800-0915 Thursday 4 0930-1045 Thursday 5 1100-1215 Thursday 6 1230-1345 Thursday 7 1400-1515 Thursday 8 1530-1645 Thursday 9 1700-1815 Thursday 10 1830-1945 Thursday 11 2000-2115 Thursday Pledged Page 1 of 8

CS 101 Exam 2 Spring 2005 Email Id Name Pledged Page 2 of 8

CS 101 Exam 2 Spring 2005 Email Id Name 2. (6 points) What are the values of the following expressions? true && false true false! true! true && false ( 3 / 4 )!= 0 1 + 2 < 1 + 4 3. (3 points) Suppose method evaluate() is a method that takes two boolean parameters and returns a boolean value according to the following truth table. p q result false false true false true false true false true true true false What are the values of the following invocations? evaluate(true, false) evaluate(false, true) evaluate(false, false) 4. (4 points) Define and initialize a boolean Java variable issilent that will be used to maintain the ring mode of a cell phone. The cell phone in question is currently not allowed to ring. 5. (5 points) Use an appropriate if statement to complete the following code segment that displays wahoo only if the extracted integer is not equal to 88. Pledged Page 3 of 8

CS 101 Exam 2 Spring 2005 Email Id Name 6. (8 points) Complete the following code segment that displays wahoo if the extracted integer is zero and displays herring otherwise. (We believe your answer should not need all of the provide space.) 7. (4 points) Consider the following method mystery(). public static boolean mystery(boolean p, boolean q) { if ( p == q ) { return true; else if ( q ) { return true; return false; What truth table is implemented by method mystery()? p q result false false false true true false true true Pledged Page 4 of 8

CS 101 Exam 2 Spring 2005 Email Id Name 8. (5 points) Consider the following code segment. if ( i > j ) { if ( j > k ) { System.out.println("A ); else if ( k == i ) { System.out.println( B ); System.out.println( C ); else if (j > k ) { System.out.println( D ); if ( i == k ) { System.out.println( E ); System.out.println( F ); What is the output if i = 3, j = 2, and k = 1? What is the output if i = 2, j = 4, and k = 3? What is the output if i = 2, j = 1, and k = 3? What is the output if i = 2, j = 1, and k = 4? What is the output if i, j, and k all have same value? 9. (4 points) What is the most misleading part of the following legal code segment? int i = 0; while ( i < n ) ++i; System.out.println("A ); System.out.println("B ); 10. (5 points) The following code segment does not compile. Explain why the code segment cannot display the value of n. (Your answer should not mention infinite loops, missing input, or missing prompts.) while ( stdin.hasnextint() ) { System.out.println(n); Pledged Page 5 of 8

CS 101 Exam 2 Spring 2005 Email Id Name 11. (5 points) Consider the following code segment. int m = stdin.nextint(); int i = m; while ( i < n ) { System.out.println("A ); ++i; How many times is A displayed if the values supplied for m and n are respectively 1 and 2? How many times is A displayed if the values supplied for m and n are respectively 0 and 3? How many times is A displayed if the values supplied for m and n are respectively 2 and 1? How many times is A displayed if the values supplied for m and n are respectively 1 and 0? How many times is A displayed if the same value is supplied for both m and n? 12. (4 points) Examine the following definition of a Tune constructor public Tune() { String artist = "Thomas Alva Edition"; String title = "Mary had a little lamb"; int year = 1877; and explain why the following code segment Tune fave = new Tune(); System.out.println( fave ); produces output Tune( null, null, 0 ) Pledged Page 6 of 8

CS 101 Exam 2 Spring 2005 Email Id Name 13. (7 points) Give a definition for Tune method getyear() where the method body consists of a single statement. 14. (7 points) Complete the following definition for a Tune constructor, which configures the new object based on its parameters. The constructor body must not have any variable definitions or assignment statements. public Tune(String performer, String name, int year) { 15. (7 points) Complete the definition for Tune method sameartist() with a single Tune parameter named that. The method returns true only if the current object being accessed (the this object) and that have the same performer (See page 1 for a definition of same). public boolean sameartist(tune that) { String thisperformer = String thatperformer = if ( ) return true; return false; Pledged Page 7 of 8

CS 101 Exam 2 Spring 2005 Email Id Name 16. (7 points) Use an appropriate if-else statement to complete the definition for Tune method setyear() with its single int parameter y. If y is at least 1, then y is the new value for the year attribute of the Tune. Otherwise, the year attribute is unchanged and a message is displayed rejecting the update. public void setyear(int y) { 17. (2 points) TRUE FALSE The default constructor for class Tune takes three parameters. 18. (2 points) TRUE FALSE Tune method settitle() is a mutator instance method. 19. (2 points) TRUE FALSE Variable title is an instance variable in method settitle(). 20. (2 points) TRUE FALSE Variable performer is an instance variable in method tostring(). 21. (2 points) TRUE FALSE Variable track is a formal parameter in method settitle(). 22. (2 points) TRUE FALSE The below code compiles as the method main() in a program Access.java. public static void main(string[] args) { Tune tune = new Tune(); String s = tune.title; 23. (2 points) TRUE FALSE The below code compiles as the method main() in a program Access.java. public static void main(string[] args) { Tune tune = new Tune(); String s = tune.gettitle(); Pledged Page 8 of 8