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

Similar documents
CS162 Computer Science I Winter 2006 Practice Exam 2

CS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

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

Final Exam Practice. Partial credit will be awarded.

Topic 4 Expressions and variables

Key Concept: all programs can be broken down to a combination of one of the six instructions Assignment Statements can create variables to represent

EECS168 Exam 3 Review

Final Exam. COMP Summer I June 26, points

CS 1331 Exam 1 ANSWER KEY

Sample First Midterm Exam The Answers

Building Java Programs

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

CS 101 Spring 2007 Midterm 2 Name: ID:

Final Exam COMP Fall 2004 Dec 16, 2004

CS 101 Fall 2006 Midterm 3 Name: ID:

Variables and data types

CS 113 PRACTICE FINAL

User Defined Classes. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

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

Name CIS 201 Midterm II: Chapters 1-8

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

MODULE 02: BASIC COMPUTATION IN JAVA

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Com S 227 Spring 2018 Topics and review problems for Exam 1 Monday, February 19, 6:45 pm Exam locations by last name:

CS18000: Problem Solving And Object-Oriented Programming

Object-Oriented Programming

CMSC132 Summer 2018 Midterm 1

CS 112 Introduction to Programming

Admin. CS 112 Introduction to Programming. Recap: Java Static Methods. Recap: Decomposition Example. Recap: Static Method Example

Question: Total Points: Score:

Exam Duration: 2hrs and 30min Software Design

Object Class. EX: LightSwitch Class. Basic Class Concepts: Parts. CS257 Computer Science II Kevin Sahr, PhD. Lecture 5: Writing Object Classes

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

Programming with Java

What we will do today Explain and look at examples of. Programs that examine data. Data types. Topic 4. variables. expressions. assignment statements

Week 11: Class Design

CIS133J. Working with Numbers in Java

CSE 11 Midterm Fall 2008

Term 1 Unit 1 Week 1 Worksheet: Output Solution

1. The programming language C is more than 30 years old. True or False? (Circle your choice.)

CS1004: Intro to CS in Java, Spring 2005

if Statement Numeric Rela5onal Operators The if Statement Flow of Control: Branching (Savitch, Chapter 3)

if Statement Numeric Rela7onal Operators The if Statement Flow of Control: Branching (Savitch, Chapter 3)

CS111: PROGRAMMING LANGUAGE II

I. True/False: (2 points each)

Practice Midterm 1. Problem Points Score TOTAL 50

Building Java Programs

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

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

UMBC CMSC 331 Final Exam

CS 455 Final Exam Fall 2015 [Bono] Dec. 15, 2015

Built-in data types. logical AND logical OR logical NOT &&! public static void main(string [] args)

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

CMSC132 Summer 2018 Midterm 1. Solution

Building Java Programs

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

More Java Basics. class Vector { Object[] myarray;... //insert x in the array void insert(object x) {...} Then we can use Vector to hold any objects.

CS 231 Data Structures and Algorithms, Fall 2016

Final Exam CS 152, Computer Programming Fundamentals May 9, 2014

Built-in data types. public static void main(string [] args) logical AND logical OR logical NOT &&! Fundamentals of Computer Science

York University Fall 2001 / Test #1 Department of Computer Science

CS 101 Spring 2006 Final Exam Name: ID:

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

CS 113 MIDTERM EXAM 2 SPRING 2013

Chapter 6 Introduction to Defining Classes

Final Exam CS 152, Computer Programming Fundamentals December 9, 2016

WEEK 4 OPERATORS, EXPRESSIONS AND STATEMENTS

CSE 142, Winter 2007 Final Exam. Name:

CSE 113 A. Announcements - Lab

CS 374 Fall 2014 Homework 2 Due Tuesday, September 16, 2014 at noon

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

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

Algorithms and Conditionals

BCIS 3630 Dr. GUYNES SPRING 2018 TUESDAY SECTION [JAN version] GRADER COURSE WEBSITE

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

CT 229. Java Syntax 26/09/2006 CT229

Introduction to Software Development (ISD) Week 3

Remaining Enhanced Labs

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2

AP CS Unit 3: Control Structures Notes

Building Java Programs

CS111: PROGRAMMING LANGUAGE II

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

Computer Science II Data Structures

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

McGill University School of Computer Science COMP-202A Introduction to Computing 1

CS 161. SAMPLE FINAL Fall 2014

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

Topic 7: Inheritance. Reading: JBD Sections CMPS 12A Winter 2009 UCSC

Chapter 2: Data and Expressions

I. True/False: (2 points each)

CS61B - Exam 2 March 17, Consider the following example of a program that uses inheritance.

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

Midterm 1 Study Guide

CSI 1100 / 1500 Fall 2004 Introduction to Computer Science I Final Examination

Review Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous

Question: Total Points: Score:

CS445 Week 9: Lecture

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

Transcription:

Name: CS162 Computer Science I Fall 2018 Practice Exam 1 DRAFT (9 Oct.) The real test will look much like this one, but it will be shorter. I suggest taking this practice test under real conditions (closed book, closed note) first, then going back and using your book and notes to correct your answers. I will grade parts of this test for homework points, then give it back in time for you to study from it. I strongly suggest that you limit your collaboration. The real test will be Monday, 15 October. Sample short answer essay questions: (you need not turn these in): o Briefly explain the difference between classes and objects. o Explain the difference between an actual parameter and a formal parameter o What does void mean. o What are scope and lifetime (with respect to Java). o What is shadowing and how does it affect a Java program? Review the problems on CodingBat. 1a). Which of the following expressions evaluate to true?!(4<5)!false (2>2) ((4 == 4) && (1 < 0)) (2>2) (4 == 4) && (1 < 0) (34!= 33) &&!false 1b). Evaluate the following expressions: 3 + 4 * 5 4 * 5 + 6 35 % 7 35 % 8 5 + 4 % 2 5 + 4 % 2 + 3 C + 3 + PO 7 + 6 + Trombones 27 / 4 3 + 4 / 5 3 + 4 / 5 + 6

2). Complete the method below that calculates how many packages of hot dogs you will use (i.e., open) and how many hot dogs will be left in an open package. Assume that half the people at your party (rounded down, if odd) will eat two hot dogs and the rest will eat only one. You may not use any of the methods in the Math package (e.g., Math.round). Remember how Java handles integer division. For example, if the input is 50, your output should look like this: You will use 10 packages and have 5 hot dogs left over. class HotDogs public void dogsandbuns(int people_at_party) final int DOGS_PER_PACKAGE = 8; // Your code here // end method // end class

3). On the back of the previous page, write a Student class that contains the following: a) Four fields: Strings named firstname and lastname, an int named credithours, and a double named qualitypoints b) A constructor that takes the Student s names as parameters, but sets credithours and qualitypoints to 0. c) A method named getgpa that takes no parameters and returns the student s GPA (quality points divided by credit hours). d) A method named addclass that takes as parameters the number of hours of the class and the student s grade in the class. Update credithours and qualitypoints accordingly. e) A method named isondeanslist that takes no parameters and returns true if the student has a GPA of 3.0 or more, and returns false otherwise. Do not write code to compute the GPA; use the existing getgpa() method instead. Now, follow the directions in the comments below to complete the method testsudentclass. Note: This method is not part of the Student class. public void teststudentclass() // Declare and create two Student objects using appropriate literal values (i.e., make up data). // Call the addclass method once for each student using appropriate literal values. // Print the average of the two students GPAs. (Use getgpa, don t calculate GPA by hand.) // end teststudentclass

4). Consider the Date class described below. Then, complete the isweekend and testdateclass methods described below. Do not implement the constructor, getdayofweek, daysuntilchristmas, increment, or tostring. class Date public Date(int year, int month, int day) public String getdayofweek() public int daysuntilchristmas() public void increment(int numdays) ; public String tostring() Write a method named isweekend that takes no parameters and returns true if the current date is a Saturday or Sunday. Complete the method below according to the comments. This method is not part of the Date class. public void testdateclass() // Create a Date object using appropriate literal values. // Call the Date object s tostring method and print the String returned. // If it s Christmas print out It s Christmas! If it s not Christmas, print I can t wait and // use the daysuntilchristmas and increment methods together to set the date object // to Christmas.

5). For each of the provided terms at the right, circle an example in the code and label it with the appropriate number. If the term does not apply anywhere in the code on this place, write none. Use pencil, plan ahead, and label neatly! Don t obscure the code, you ll need it later. class MysteryGamePlayer private int redpoints; private int bluepoints; private int greenpoints; public MysteryGamePlayer(int a, int b) redpoints = a; bluepoints = b; greenpoints = 0; public void setgreenpoints(int c) greenpoints = c; 1 string concatenation 2 internal method call 3 field declaration 4 - constructor 5 conditional stmt 6 equality operator 7 formal parameter 8 external method call 9 return type 10 actual parameter 11 return value 12 local variable 13 comment public int getgreenpoints() return greenpoints; public int method1() return redpoints - bluepoints + greenpoints; public int method2(int p) int m1val = method1(); return m1val + (p 1)*greenPoints; public void modify(int d, int e) redpoints = redpoints*d; bluepoints = bluepoints*4; e = greenpoints; public String tostring() return rgb points: + redpoints + + bluepoints + + greenpoints; // end class MysteryGamePlayer

6). Predict the output of the method playmysterygame. This code uses the MysteryGamePlayer class on the previous page. There are no compile errors, or run-time errors. (If you find one, then I made a mistake when preparing the problem.) class MysteryGame public void playmysterygame() MysteryGamePlayer object1 = new MysteryGamePlayer(1,2); System.out.println( A: + object1.method1()); object1.setgreenpoints(3); System.out.println( B: + object1.method1()); System.out.println( C: + object1.method2(2)); int a = 5; int b = 6; MysteryGamePlayer object2 = new MysteryGamePlayer(b, a); System.out.println( D: + object2.method1()); object1.setgreenpoints(7); System.out.println( E: + object2.method1()); System.out.println( F: + object2.method2(object1.getgreenpoints())); int d = 3; int e = 4; object1.modify(d, d); System.out.println( H: + object1.tostring()); object2.modify(object1.method2(e) + d, 0); System.out.println( I: + object2.tostring()); 7). Complete the method below that takes all of m1 s green points and gives them to m2. void giveandtake(mysterygameplayer m1, MysteryGamePlayer m2)

8). In the state of Georgia, you must use a car (or booster) seat until you are either (1) at least 7 years old, or (2) weigh at least 70 pounds. Complete the method carseatrequired below that returns true if, and only if, the child described still needs a car or booster seat. For example: carseatrequired(8, 65) should return false carseatrequired(8, 75) should return false carseatrequired(6, 65) should return true carseatrequired(6, 75) should return false public static boolean carseatrequired(int age, double weight) // end carseatrequired 9). Write a line of code that would give different answers if the associativity were left to right instead of right to left. 10). Write a line of code that would give different answers if the precedence were different. 11). What is short-circuit evaluation? 12). Write a line of code that relies on short-circuit evaluation for correct operation. 13). Explain what the following code does in plain English. (Specifically, describe what the method does as a whole. Don t describe it line-by-line.) public static boolean mystery(string str) int lastindex = str.length() 1; for (int i = 0; i < str.length() / 2; i++) if (str.charat(i)!= str.charat(lastindex -1) return false; return true;