



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The cs61b exam 1 for the spring 2003 semester, which includes instructions, problem statements, and grading rubrics. Students are required to fill in their personal information and solve various problems related to account class, palindromes, and constructing a vector of riddle objects.
Typology: Exams
1 / 5
This page cannot be seen from the preview
Don't miss anything!
CS61B (Yelick) Spring 2003
Do not open this booklet until you are told to begin!
There are 20 points on this exam. Read each problem carefully, and avoid spending too much time on any one question! There is a 1-page appendix at the end of this exam that included code you have seen before. You may tear that page off your exam if you wish.
Problem 0 (1 point): Fill out all the following information. Once you are told to begin, also fill out your name and login at the top of each page.
Your name:
Your cs61b login:
Lab time or section #:
Lab TA’s name:
Name of person to your left:
Name of person to your right:
Grading: Do not write below this line. The following grid will be used for grading.
Problem Score Possible
0 1
1 5
2 5
3 4
4 5
Total 20
Do not open this booklet until you are told to begin!
Problem 1: (5 points) This problem refers to the Account class from Lab2, which is attached to the end of this exam booklet as an appendix.
Parts A-D: Below are some possible box-and-pointer diagrams for Account objects. Which of the pictures are legal diagrams that could be produced by a program outside the Account class, e.g., a separate test class. Circle “yes” if such a program could produce the picture, “no” if it could not. (For parts A-D only, +1 point for each correct answer, -2 for each incorrect one.)
A) Yes No B) Yes No
C) Yes No D) Yes No
Part B: Fill in the 1-line body of a method clearAcct with the following specification. As in parts A-D, this method is part of a test class that is not the Account class.
/** Modifies the given Account by clearing it of funds; afterwards, the balance() will be 0.
kathy myBalance
myParent
100
myBalance
myParent
100 mike
150
myBalance
myParent
kathy myBalance
myParent
100
myBalance
myParent
kathy
kathy
Problem 4 (5 points) Consider working with a Riddle class about which you have only the following specification of a constructor.
public class Riddle {
/** Creates a new Riddle object.
/* rest of Riddle class unknown */ }
Write a method that constructs a Vector of Riddle objects according to the specification below. The elements of the result may be in any order. (Your solution need not use every line.)
/** Creates a Vector of Riddle objects from the given String.
return result; }
Account class from the Lab 2 solution. (Some methods simplified for brevity, but the simplifications do not affect your answers.) You may detach this page from your exam.
/** This class represents a bank account whose current balance is a
/** Construct an account with the given initial balance. */ public Account (int balance) { myBalance = balance; myParent = null; }
/** Construct an account with the given balance and parent account.
/** Deposit into this account.
/** Subtract the amount from the account, if possible. If it would leave
/** Get the balance.
private int myBalance; private Account myParent; }