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

Similar documents
CS 101 Exam 1 Spring 200 Id Name

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.

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

APCS Semester #1 Final Exam Practice Problems

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

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

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

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

COMPUTER APPLICATIONS

Account joeacct = new Account (100, new Account (500)); Account joeacct = new Account (100, new Account (500, null));

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

CS 101 Exam 2 Spring Id Name

Prelim 1 SOLUTION. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants. Recursion OO Short answer

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

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

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

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

We have written lots of code so far It has all been inside of the main() method What about a big program? The main() method is going to get really

Computer Programming, I. Laboratory Manual. Final Exam Solution

CSCI 355 Lab #2 Spring 2007

Introduction to Programming (CS112): Sample

CSCI 355 LAB #2 Spring 2004

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

CS 101 Fall 2006 Midterm 3 Name: ID:

CS111: PROGRAMMING LANGUAGE II

More types, Methods, Conditionals. ARCS Lab.

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

Final Exam. COMP Summer I June 26, points

CS1083 Week 2: Arrays, ArrayList

Research Group. 2: More types, Methods, Conditionals

Java Review. Fundamentals of Computer Science

CMP 326 Midterm Fall 2015

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

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

Chapter 4 Defining Classes I

Question: Total Points: Score:

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

NATIONAL UNIVERSITY OF SINGAPORE

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

Visual Programming. Lecture 2: More types, Methods, Conditionals

Assignment 1 due Monday at 11:59pm

Do not start the test until instructed to do so!

Practice Midterm 1 Answer Key

Practice Midterm 1. Problem Points Score TOTAL 50

AP CS Unit 3: Control Structures Notes

Classes, interfaces, & documentation. Review of basic building blocks

Question 1a) Trace of program

DM503 Programming B. Peter Schneider-Kamp.

CS170 Introduction to Computer Science Midterm 2

University of Massachusetts Amherst, Electrical and Computer Engineering

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

Course Outline. Introduction to java

CSE 21 Intro to Computing II. Post-Midterm Review

Introduction to Computer Science Unit 2. Notes

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

a) Answer all questions. b) Write your answers in the space provided. c) Show all calculations where applicable.

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1

CS101 Part 2: Practice Questions Algorithms on Arrays, Classes and Objects, String Class, Stack Class

DM550 Introduction to Programming part 2. Jan Baumbach.

Arrays and Strings. Arrays - homogeneous indexed collections Selection sort as array example. String class, revisited

Objects and Classes. 1 Creating Classes and Objects. CSCI-UA 101 Objects and Classes

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

CMPS 12A Winter 2006 Prof. Scott A. Brandt Final Exam, March 21, Name:

Administrivia. Last modified: Fri Aug 25 10:59: CS61B: Lecture #2 1

CS 101 Spring 2007 Midterm 2 Name: ID:

I. True/False: (2 points each)

CSIS 10A Practice Final Exam Solutions

CS1004: Intro to CS in Java, Spring 2005

Chapter 6 Lab Classes and Objects

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

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)

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

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

COE 212 Engineering Programming. Welcome to Exam I Tuesday November 11, 2014

Introduction to Programming Written Examination

EXAMINATION INSTRUCTIONS

CSC 240 Computer Science III Spring 2018 Midterm Exam. Name

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

Introduction to Computer Science Unit 2. Notes

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

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

ENGR 2710U Midterm Exam UOIT SOLUTION SHEET

APCS Assessment Sheet Consider the following program segment int count = 1;

Name Section Number. CS210 Exam #1 *** TURN OFF ALL ELECTRONIC DEVICES *** Practice

Expression: Expression: Statement: Output: Expression: Expression:

Introduction to Software Development (ISD) Week 3

CMSC 202H. Classes and Objects: Reusing Classes with Composition

CSE 331 Midterm Exam 2/13/12

CS 455 Midterm Exam 1 Spring 2015 [Bono] Thursday, Feb. 19, 2015

9/19/2018 Programming Data Structures. Polymorphism And Abstract

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

Exam 1 - (20 points)

Class 9: Static Methods and Data Members

Encapsulation. Administrative Stuff. September 12, Writing Classes. Quick review of last lecture. Classes. Classes and Objects

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

Instance Method Development Demo

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

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

COMP102: Test 2: Part B Model Solutions

Transcription:

Sample Final Exam 1. Evaluate each of the following expressions and show the result and data type of each: Expression Value Data Type 14 % 5 1 / 2 + 1 / 3 + 1 / 4 4.0 / 2.0 Math.pow(2.0, 3.0) (double)(2 / 5) 15 + 3 4 * 5 5.0e2 + 6 Math.sqrt(100) 5 / 2 * 2.0 2.0 * 5 / 2 2. Examine each line of code in the program below and correct the syntax errors by rewriting the line correctly on the right. If a line does not contain an error, write NO ERROR. Code Import java.util.random; public class Errors ; public attics void main (String [] args) int x; y = 0; Random r = new Random; x = r; y += x; System.out.println( y= y); ) Correction Sheller Page 1

1. (10 points) Identify and correct the errors in each snippet of code below. Each section of the table is selfcontained. All the snippets are supposed to print x=0 if and only if variable x equals 0; however, the actual value of x doesn t really matter in terms of identifying the errors: if (x == 0); if (x = 0) if (x!= 0) else System.out.println( x is not 0 ); if (x == 0) System.out.print ( x ); System.out.print( = ); System.out.print( 0 ); 2. (15 points) Show the truth value of each expression a through e given the declarations below: int a = 2, b = 0, c = -3; a) (a + b) > c b) a > b && b < c c) (b > c)!= (a > b) d) a == b (c < a && b < c) e) ((b c) > (a b) ) && ((a + c) < (a c)) Sheller Page 2

3. Show the output of the following program using the grid below. You will only be graded on the output, but if it is incorrect you can get partial credit by filling the other columns of the grid: public class Exam2Q public static void main (String [] args) int x = 0, y = 1; while (x < 10) x++; if (x % 2 == 1) System.out.println("x="+x); y++; if (y % 2 == 0) System.out.println("y="+y); Iteration x at start x at end y at start y at end Output 1 2 3 4 5 6 7 8 9 10 4. Show the truth value of each expression a through e given the code below: String s1 = abc ; String s2 = bbc ; a) s1.charat(1) == s2.charat(1) b) s1.compareto(s2) > 0 c) s1.substring(1).equalsignorecase(s2.substring(1)) d) s1.length() < s2.length() e) s1.indexof( b ) == s2.indexof( b ) Sheller Page 3

5. Use the class below to determine if instructions a through i are valid; if so, write valid in the space next to the instruction and if not, explain what is wrong or correct the error. Each subsequent instruction can assume that previous instructions were valid: public class Albatross private int wings; private String bellow; public Albatross() wings=2; bellow= awk ; public void setfire(int match) wings = (int)(math.random()*match); public String getaway() return bellow; Code (in main method, different class) Error/Correction a) Albatross a = new Albatross(-4, whoop ); b) System.out.println(a); c) Albatross.getAway(); d) int x = a.setfire(100); e) a.getout( of here ); f) String shout = a.getaway(); g) a.setfire(a.getaway()); h) a.setfire(wings); i) a.getaway( eh? ); Sheller Page 4

6. Write a Java class that models a Pixel (one of the many colored dots that makes up the display on a computer screen). Instance variables must include: red, green and blue: int values (in the range 0..255) that represent the saturation of each of the colors represented by a pixel size: an int value between 1 and 50, representing the size of a pixel; we can think of a pixel as a size x size solid square in the designated color Instance methods (these must enforce the integer limits described above): 3 constructors: o default constructor creates a 1 x 1 white pixel (NOTE: white is full color saturation; all 3 color values are 255); o constructor with 4 int arguments, representing red, green, blue and size; o constructor with an int argument representing size, and default color of white Mutator methods to set size, set individual color values, and set all 3 color values Accessor methods to return values for colors & size a tostring method that returns a String with this format: red:xxx, green:xxx, blue:xxx, size:xx (where the x s are the actual int values) an equals method that returns true if the calling object and a Pixel argument are the same size, false otherwise You do not need to write a main method just the Pixel class itself, with the elements described above. Sheller Page 5