Final Exam Practice. Partial credit will be awarded.

Similar documents
AP Computer Science Unit 1. Programs

Computational Expression

CS1083 Week 2: Arrays, ArrayList

Lecture 8 " INPUT " Instructor: Craig Duckett

COMP 401 Midterm. Tuesday, Oct 18, pm-3:15pm. Instructions

Introduction to Java Unit 1. Using BlueJ to Write Programs

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

Final Exam COMP Fall 2004 Dec 16, 2004

H212 Introduction to Software Systems Honors

Handout 4 Conditionals. Boolean Expressions.

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

1 Short Answer (15 Points Each)

AP Computer Science Unit 1. Writing Programs Using BlueJ

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

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

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

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

AP Computer Science Unit 1. Writing Programs Using BlueJ

Programming with Java

1 Short Answer (15 Points Each)

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

CS 101 Fall 2006 Midterm 3 Name: ID:

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination

Final Exam. COMP Summer I June 26, points

CISC-124. Dog.java looks like this. I have added some explanatory comments in the code, and more explanation after the code listing.

Java Identifiers, Data Types & Variables

CSCI 111 Midterm Spring 2014

Final Exam CS 152, Computer Programming Fundamentals December 5, 2014

Handout 5 cs180 - Programming Fundamentals Spring 15 Page 1 of 8. Handout 5. Loops.

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

APCS Semester #1 Final Exam Practice Problems

COMP-202: Foundations of Programming. Lecture 8: for Loops, Nested Loops and Arrays Jackie Cheung, Winter 2016

Fundamentals of Programming Data Types & Methods

Object Oriented Programming. Java-Lecture 1

COMP 202 Java in one week

Practice Midterm 1. Problem Points Score TOTAL 50

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

Question: Total Points: Score:

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

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

Oct Decision Structures cont d

Robots. Byron Weber Becker. chapter 6

New York University Introduction to Computer Science Midterm2 Sample Problems 2013 Andrew I. Case. Instructions:

Question: Total Points: Score:

Example Program. public class ComputeArea {

CS 101 Exam 1 Spring 200 Id Name

CSE 1223: Exam II Autumn 2016

Computer Programming, I. Laboratory Manual. Final Exam Solution

COMP-202 Unit 4: Programming With Iterations. CONTENTS: The while and for statements

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

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

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

Selected Questions from by Nageshwara Rao

AP Computer Science A

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

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

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

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz

Control Structures: if and while A C S L E C T U R E 4

COMP 110 Programming Exercise: Simulation of the Game of Craps

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

AP CS Unit 3: Control Structures Notes

CHAPTER 5 VARIABLES AND OTHER BASIC ELEMENTS IN JAVA PROGRAMS

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

1 Short Answer (10 Points Each)

Midterms Save the Dates!

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

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

boolean, char, class, const, double, else, final, float, for, if, import, int, long, new, public, return, static, throws, void, while

1 Short Answer (10 Points Each)

PROGRAMMING FUNDAMENTALS

M e t h o d s a n d P a r a m e t e r s

Practice Midterm 1 Answer Key

CSCI 355 Lab #2 Spring 2007

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

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

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

Solutions to the 2005 exam

1 Short Answer (5 Points Each)

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

Lecture Set 2: Starting Java

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4

CPSC 219 Extra review and solutions

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

Java Classes: Math, Integer A C S L E C T U R E 8

Lecture Set 2: Starting Java

Full file at

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

Chapter 6 Lab Classes and Objects

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

I. True/False: (2 points each)

Object-Oriented Programming (OOP) Basics. CSCI 161 Introduction to Programming I

1 Short Answer (5 Points Each)

CSC142, Computer Science II, Project 5 (2 nd submission)

Lecture 6. Assignments. Summary - Variables. Summary Program Parts 1/29/18. Reading: 3.1, 3.2, 3.3, 3.4

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

CSE 131 Introduction to Computer Science Fall Exam II

Software Practice 1 - Basic Grammar Basic Syntax Data Type Loop Control Making Decision

Midterm Practice Problems - answer key Answers appear in boldface.

Transcription:

Please note that this problem set is intended for practice, and does not fully represent the entire scope covered in the final exam, neither the range of the types of problems that may be included in the final exam. The final exam is a closed-book-closed-notes exam. You may use a crib sheet no more than 2 pages long. No electronic devices of any sort are allowed. Partial credit will be awarded. You can abbreviate System.out.println () with println(). You don t need to include any import statements. You need not use comments and import statements to your code, but otherwise use good style. If anything in the problem definition is unclear, please ask for clarification. Page 1 of 9

Part 1. (10 points) Basics. a. Fill in the blanks 1. Operator is used to create new objects and arrays. 2. When str is a variable of type String, the value of parameter pos in the call str.charat(pos) must be between and (inclusively). 3. Keyword is used to declare methods that do not require a calling object. 4. Suppose class Foo contains a method with the following header: public boolean amethod (double x) o o o What is the return type of this method? Is this an instance method or a static method? Will the Java compiler indicate an error if method with the following header public boolean amethod (int y, String z) was also added to the same class Foo? Include a yes or no answer and an explanation. 5. The name of the constructor method must. Page 2 of 9

Part 2. (10 points) Short answers. b. What will be printed by the following code segment? Note: there are 2 printing statements. Show the intermediate values of participating variables for partial credit. int result = 0, number = 273; int ldigit; do { ldigit = number % 10; System.out.println (ldigit); result = (result * 10) + ldigit; number = number / 10; while (number > 0); System.out.println (result); c. What will be printed by the following code segment (note 2 printing statements)? String [] words = {"one", "three", "four"; System.out.println(words.length); System.out.println(words[1].indexOf('o')); Page 3 of 9

Part 3. (20 points) A gym is offering a yoga class every day, except for Saturdays and Sundays. The gym administration collected attendance data for the past 4 weeks. Complete the program below to visualize the attendance data as follows. The user will enter 200 integers, representing daily attendance of an exercise class. The first number corresponds to a Monday of the first week, the second corresponds to Tuesday and so on with the sixth number representing the Monday of the next week, etc. Print out a diagram showing attendance for every day in the format displayed in the sample interaction below (user input appears in boldface): Please enter attendance data for 200 days: 6 7 21 3 4 5 11 5 3 7 9 8 5 6 2 9 5 6 4 5 Displaying the data week-by-week: Su M T W Th F S - 6 7 21 3 4 - - 5 11 5 3 7 - - 9 8 5 6 2 - - 9 5 6 4 5... In your output, do not worry about perfect alignment of spaces, but make sure to - Print the first row showing the days as shown - Display each week s data on a separate line - Leave a space between each pair of numbers - Put a dash instead of a number for Sunday and Saturday Hints: use Scanner method nextint() to read numbers one by one and store them in an array, before you start printing them out. public class ShowAttendance { public static void main (String []arg){ Scanner kb = new Scanner (System.in); Page 4 of 9

Page 5 of 9

Part 4. (35 points) Consider the definition of class Seat below, representing a seat in Boston s Jordan Hall. The comments in the code define the purpose of each variable or constant. public class Seat { private char row; // character denoting the row private int seatnumber; // seat number in the specified row public static final double STANDARD_PRICE= 45.50; //standard seat price for one performance public Seat (){ this.row = 'A'; this.seatnumber = 1; // Accessors public char getrow() { return this.row; public int getseatnumber() { return this.seatnumber; /* public String sideofhouse(){ Returns a string left or right designating in which side of the hall this seat is located.*/ public String sideofhouse(){ if (seatnumber%2 ==0) return "left"; else return "right"; Define the following methods for the Seat class. Note that parts a,b,c,d can be completed independently of each other. To complete part e you need to at least have completed the headers for methods in a,b,c. a. (5 points) Public instance method tostring () that does not take any parameters and returns a String, containing the row and seat number. For example, if the calling objects represents seat number 56 in row N, the tostring() method should return: Seat N-56 Page 6 of 9

b. (10 points) A constructor, which takes two parameters: a character representing the row, and an integer representing the seat number in that row. The constructor should check that the character parameter stores a letter, using method Character.isLetter() described below, and in such case assign the row instance variable equal to the uppercase version of that letter. Otherwise, the constructor should assign instance variable row to be equal to A. Furthermore, the constructor must check if the parameter denoting the seat number is in the range of 1..60, inclusively, and in such case assign the seatnumber instance variable equal to the value of the parameter. Otherwise, the seatnumber should be assigned value 1. Hint: Static method Character.isLetter(ch) returns true if and only if character ch is a letter. Page 7 of 9

c. (10 points) Public static method numseatsinrow() for class Seat. The method should accept two parameters: an array of Seat objects and a char, designating a row. The method should calculate and return how many of the seats stored in the array that is passed as the first parameter are in the row specified by the second parameter. The check must be case insensitive, i.e. a and A should be treated as the same row. Page 8 of 9

d. (10 points) For this part, you need to at least have completed the headers for methods in a and b. In the unfinished program that follows, add code to 1. Create an object of class Seat based on the data obtained from the user. 2. Print the created object. 3. Call method sideofhouse () for the created object and display the value it returns. 4. Print the standard seat price as defined by the Seat class. The price must be formatted to display exactly 2 digits after the decimal period. public class TestSeat { public static void main(string[] args) { Scanner kb = new Scanner(System.in); System.out.println("Please enter the row"); char row = kb.next().charat(0); System.out.println("Please enter the seat number"); int seatnum = kb.nextint(); Page 9 of 9