Computer Science 61B - Spring 2001 - Clancy - Midterm 1

Computer Science 61B - Spring 2001 - Clancy - Midterm 1 -...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 61B, Midterm #1, Spring 2001 CS 61B, Spring 2001 Midterm #1 Professor Paul N. Hilfinger Problem #0 (1 point, 1 minute) Put your login name on each page. Also make sure you have provided the information requested on the first page. Problem #1 (2 points, 4 minutes) Write a single Java assignment statement that declares and assigns the variable maryAcct to have the value shown in the picture. Solutions of more than one statement may earn partial credit. The Account class definition from lab assignment 2 appears at the end of this exam. Your solution: _______________________________________________________________ Problem #2 (8 points, 20 minutes) The two parts of this problem both involve an IslamicDate class that is somewhat simpler than that used for homework assignment 2. An implementation of this class appears near the end of this exam. Part a Given below is an implementation of a DateTester class that could be used with the abbreviated IslamicDate class provided at the end of this exam. The statements in the body of the main method are not necessarily correct; errors include both compile-time and run-time errors. For each statement, indicate whether it is OK or will result in an error by circling the appropriate word. You may assume that all methods in the abbreviated IslamicDate work correctly and that each line with an error is fixed before you consider the lines that follow it. public class DateTester { public static void main (String [ ] args) { IslamicDate d1 = IslamicDate (1, 1); OK error file:///C|/Documents%20and%20Settings/Jason%20Raft. ..20Spring%202001%20-%20Clancy%20-%20Midterm%201.htm (1 of 8)1/27/2007 5:40:32 PM
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 61B, Midterm #1, Spring 2001 System.out.println ("" + d1); OK error IslamicDate d2 = d1.makeTomorrow (); OK error IslamicDate d3 = null; OK error System.out.println (d3.tomorrow ()); OK error } } Part b Give the Java code for a DateTester method isLaterThan that determines if the first of its argument dates is later than the second. The isLaterThan method will be used by adding the statement System.out.println ("IS " + d1 + " later in the year than " + d2 + "? " + isLaterThan (d1, d2)); to the end of the (Corrected) main method in the DateTester class of part a. (As in part a, DateTester will be used with the abbreviated IslamicDate class, not the class you implemented in homework assignment 2. You aren't allowed to change the IslamicDate class.) // REQUIRES: two nonnull IslamicDate references, representing dates // in the same year. // MODIFIES: nothing
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/17/2009 for the course CS 61B taught by Professor Canny during the Spring '01 term at Berkeley.

Page1 / 8

Computer Science 61B - Spring 2001 - Clancy - Midterm 1 -...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online