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

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

CS 101 Exam 1 Spring 200 Id Name

CS 101 Exam 2 Spring Id Name

CS 101 Fall 2006 Midterm 3 Name: ID:

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 Spring 2007 Midterm 2 Name: ID:

CS 101 Fall 2006 Midterm 1 Name: ID:

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

COS 126 General Computer Science Fall Written Exam 1

CS 101 Fall 2005 Midterm 2 Name: ID:

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

Notes - Recursion. A geeky definition of recursion is as follows: Recursion see Recursion.

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

CS 101 Spring 2006 Final Exam Name: ID:

CS1083 Week 2: Arrays, ArrayList

APCS Semester #1 Final Exam Practice Problems

Introduction to Programming Using Java (98-388)

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: if Single-Selection Statement CSC 209 JAVA I. week 3- Control Statements: Part I

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

Comp 248 Introduction to Programming Chapter 4 - Defining Classes Part A

Final Exam Practice. Partial credit will be awarded.

CS 113 MIDTERM EXAM 2 SPRING 2013

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

Name CIS 201 Midterm II: Chapters 1-8

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

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

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

Lecture 13 & 14. Single Dimensional Arrays. Dr. Martin O Connor CA166

Variable initialization and assignment

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

CSE 143 SAMPLE MIDTERM

Problem Grade Total

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

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

Language Features. 1. The primitive types int, double, and boolean are part of the AP

Peer Instruction 1. Elementary Programming

CSE 1223: Exam II Autumn 2016

Assignment 1 due Monday at 11:59pm

Chapter 4 Defining Classes I

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

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

COMP 250 Winter 2011 Reading: Java background January 5, 2011

COS 126 General Computer Science Spring Written Exam 1

AP CS Unit 3: Control Structures Notes

The Singleton Pattern. Design Patterns In Java Bob Tarr

Instructions. This exam has 7 questions, worth 10 points each. You have 50 minutes.

University of Palestine. Mid Exam Total Grade: 100

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016

CS 302 Week 9. Jim Williams

AP Programming - Chapter 17 Lecture page 1 of 5

Announcements. Lab 03 inbase late submissions Midterm #1 Friday. Project 2 is posted. Covers everything through basics of OOP

(a) Write the signature (visibility, name, parameters, types) of the method(s) required

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

CSE 142 SPRING 2008 FINAL EXAM

Prelim One Solution. CS211 Fall Name. NetID

// constructor: takes a String as parameter and creates a public Cat (String x) { name = x; age = 0; lives = 9; // cats start out with 9 lives }

Objects as a programming concept

Introduction to Computer Science Unit 2. Notes

CSE 143 Sample Midterm Exam #7 (11wi)

1. Download the JDK 6, from

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

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

Practice Problems: Instance methods

PROGRAMMING FUNDAMENTALS

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

Information Science. No. For each question, choose one correct answer and write its symbol (A E) in the box.

Classes. Classes as Code Libraries. Classes as Data Structures

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

CSCI 1226 Sample Midterm Exam

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs.

Introduction to Computer Science I

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

CS1004: Intro to CS in Java, Spring 2005

FAQ: Classes & Objects

Programming with Java

Introduction to Computer Science Unit 2. Notes

Do not start the test until instructed to do so!

CSE 413 Winter 2001 Midterm Exam

CIS133J. Working with Numbers in Java

Pace University. Fundamental Concepts of CS121 1

Final Examination Semester 3 / Year 2008

Objects and Iterators

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

Reviewing all Topics this term

CS161: Introduction to Computer Science Homework Assignment 10 Due: Monday 11/28 by 11:59pm

Computer Programming, I. Laboratory Manual. Final Exam Solution

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

Getting started with Java

CSE 131 Introduction to Computer Science Fall Exam II

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

CS170 Introduction to Computer Science Midterm 2

ITI 1120 Lab #9. Slides by: Diana Inkpen, Alan Williams, Daniel Amyot Some original material by Romelia Plesa

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

CmSc 150 Fundamentals of Computing I. Lesson 28: Introduction to Classes and Objects in Java. 1. Classes and Objects

Tutorial 03. Exercise 1: CSC111 Computer Programming I

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

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

CSE142 Sample Midterm, Winter 2018

Transcription:

This exam is open book. Each question is worth 3 points. Page 1 / 15 Page 2 / 15 Page 3 / 12 Page 4 / 18 Page 5 / 15 Page 6 / 9 Page 7 / 12 Page 8 / 6 Total / 100 (maximum is 102) 1. Are you in CS101 or CS101E? 2. Suppose n, j and k are previously defined and initialized integer variables. Write an expression that multiplies n times the quantity j plus k. 3. Suppose n is a previously defined and initialized integer variable. Write an expression whose value is the remainder of n when divided by 6. 4. Write a definition for a local integer variable n whose initial value is 21. 5. Suppose n and m are previously defined and initialized integer variables. Write a statement that updates the value of n to the value of m. Pledged Page 1 of 8

6. Suppose n is a previously defined and initialized integer variable. Write a statement that increases the value of variable n by 1, where the statement does not use the = operator. 7. Write a statement that defines an integer constant named ZERO whose value is 0. 8. Suppose n is a previously defined and initialized integer variable and that x is a previously defined and initialized floating point variable. Write a statement that updates the value of n by assigning it the int-casted value of floating point value x. 9. Suppose j and k are previously defined and initialized integer variables. Write an if statement that sets variables j and k to 1 when j is less than k. 10. Suppose j and k are previously defined and initialized integer variables. Write an if statement that sets variables j and k to 1 when j is less than k; otherwise it sets j and k to 10. Pledged Page 2 of 8

11. Suppose j and k are previously defined and initialized integer variables. Write an if-else-if statement that sets variable j to 1, 2, or 3 respectively depending whether j is less than k, j equals k, or otherwise (i.e., j is greater than k). 12. Write a for statement that iterates 1000 times using a previously undefined integer index variable i. Each iteration of the loop should display the current value of i (i.e., the values to be displayed are 0 999). 13. Define a Scanner variable stdin associated with the standard input stream. Your definition should be compatible with the latest version of Java. 14. Define a Scanner variable stream associated the string represented by the previously defined and initialized String variable s. Your definition should be compatible with the latest version of Java. Pledged Page 3 of 8

15. Suppose s and t are previously defined and initialized String variables. Write a code segment that causes t to represent the substring of s defined by indices 3 through 7 inclusive. 16. Suppose input is a previously defined and initialized Scanner variable. Write a while loop that iterates while the input stream associated with variable input has unread values. Each iteration of the loop should read and display the next int value. 17. In TWENTY words or less how do the == operator and the equals() method typically differ. 18. Define a new int[] variable data that references a list composed of the values 1, 2, and 3. 19. Define a new int[] variable data that references a new array with ten elements. 20. Update an initialized int[] variable data so that it references a new array with zero elements. Pledged Page 4 of 8

21. Suppose list is a defined and initialized int[] variable with 100 elements. Write a statement that assigns 10 to the first element of list. 22. Suppose list is a defined and initialized int[] variable with 100 elements. Write a statement that assigns 10 to the last element of list. 23. Suppose list is a defined and initialized int[] variable. Write a statement that displays the number of elements represented by list. 24. Suppose list is a defined and initialized String[] variable for an array with n elements and result is a defined and initialized String variable. Write a code segment that causes result to reference a String whose value is a concatenation of the values represented by list. 25. What is the output of the following program? public class Think { public void static mystery(int n) { n = 5; } } public void static main(string[] args) { int n = 0; mystery(n); System.out.println("n = " + n); } The output is n = Pledged Page 5 of 8

The remaining questions deal with a class named Car. Class Car is to have the following private double-valued attribute. speed current travelling rate of the car in miles per hour. Class Car is to also have the following public methods. Car() default constructor that configures a car to have a speed of 55 miles per hour. Car() specific constructor that has a single double-valued parameter v. The constructor configures the new car to have a speed of v. howfar() indicates how far the car will go if it travels for t hours, where t is its double-valued parameter; i.e., the return value is the product of t and the speed attribute of the car. getspeed() returns the current speed of the car. setspeed() sets the current speed of the car to the value of its single double-valued parameter v. clone() returns a new Car with the same attribute of this car. equals() returns whether its Object-valued parameter value is a Car with the same speed as this car. tostring() returns a String representation of the car. The representation should consist of the value of the speed attribute within parentheses. 26. Implement the Car default constructor using an assignment statement to configure the speed attribute. 27. Implement the Car speed accessor getspeed(). 28. Implement the Car speed mutator setspeed(). Pledged Page 6 of 8

29. Implement the Car specific constructor using a mutator to configure the speed attribute. 30. Implement the tostring() method for Car. 31. Implement the Car default constructor so that it uses the specific constructor to configure the speed attribute of the new Car. 32. Implement the equals() method for Car. Pledged Page 7 of 8

33. Implement the clone() method for Car. 34. Suppose list is a Car[] variable. Write a statement that updates the list element with index i so that its speed is now 25 miles per hour. Pledge: Pledged Page 8 of 8