Laboratory final guidelines

To provide a regularized technique for assessing student learning of computer programming skills, the department faculty have adopted a policy of including in-laboratory finals as part of CSCI 160 and CSCI 200.

General guidelines

Laboratory setup

The exam is two hours and forty-five minutes long. Any incomplete problems will remain incomplete.

The exams are designed according to precise guidelines. The CSCI 160 exam contains 4 questions. Each has exact design guidelines detailed below.

The instructor will answer only questions clarifying what the problem is asking. It is up to the instructor's discretion whether to answer a particular question.

The only resource at your disposal during the exam is the development environment (that is, Forte), but you may not view any previously composed files. (For CSCI 200 only, students may use the Web browser, but only to view Sun's javadoc documentation of the standard libraries.)

You will receive a 0 for the exam if you try to attempt to use any other resources, physical or electronic, during the exam.

When you have completed the problems, do not log off. Just let a proctor know you are finished and leave.

Grading

For each problem, there will be two input sets. The first is the input set given as an example in the problem statement. The second is an input set that you will not see, which we will also use for grading.

Each solution will receive a score between 0 and 5 as follows.

CSCI 160 Problem 1

Guidelines

The program will read in a sequence of numbers, compute some statistic that involves a conditional statement, and print the result. The problem will specify whether the input numbers are integers or real numbers.

The program will be answerable using a single loop and a single conditional statement, and it will use methods only from the IO class. It will not require an array.

Example problem

Write a program that reads in 5 integers from the user and then displays how many of the given numbers are even (that is, how many are exactly divisible by 2).

Sample input: (what user types is in boldface)

Number? 1
Number? 8
Number? 5
Number? 3
Number? 2
2

Solutions to example problems are posted on a different page.

CSCI 160 Problem 2

Guidelines

The program will fill an array with numbers read from the user and then perform a simple array traversal.

The problem will not require the program to change the array once it is filled. It should not require more than one array traversal.

Example problem

Write a program that reads in a sequence of 5 real numbers, prints their total, and then displays the sequence of numbers in reverse order.

Sample input: (what user types is in boldface)

Number? 1.3
Number? 4
Number? 5.2
Number? 3
Number? 2
15.5
2
3
5.2
4
1.3

Solutions to example problems are posted on a different page.

CSCI 160 Problem 3

Guidelines

The problem will define the methods provided by a simple class and it will define a simple task to perform using the class provided. The class will provide a constructor method and three or four instance methods, all of which are required to complete the problem.

At least one of the methods should take a parameter, and at least one should have a return value. The problem should not require the use of any control structures beyond one loop and one conditional statement.

Example problem

The Date class provides the following methods.

Date(int year, int month, int day)
(Constructor method) Constructs a date representing the given year, month, and day. Months are numbered from 0 (representing January). Days of the month are numbered from 1.

boolean equals(Date other)
Returns true if both dates represent the same day.

void increment(int days)
Moves the date forward days days.

String toString()
Returns a string representation of the date.

Write a program that reads in six integers representing the year, month, and day of two dates and computes the number of days separating them. You may assume that the second date is not earlier than the first. Your program must use the Date class to perform its computations.

Sample input: (what user types is in boldface)

Year?  2002
Month? 1
Day?   21

Year?  2002
Month? 2
Day?   11

18 days between 21 Feb 2002 and 13 Mar 2002

Hint: The easiest way to accomplish this task is to begin at the start date and see how many times you can add one day to it before you reach the end date.

Supporting code and solutions to example problems are posted on different pages.

CSCI 160 Problem 4

Guidelines

The problem will ask the student to develop a class. It will describe the methods to be defined and provide an example class that can be used to test the class.

The required methods will include one constructor method and three instance methods. At least one instance method should take a parameter, and at least one should have a return value. The class should require only primitive-type instance variables.

Example problem

Define a Rectangle class to represent a rectangle in the graphical coordinate system (with y-coordinates increasing as you move downward). It should provide the following methods.

Rectangle(int in_left, int in_top, int in_width, int in_height)
(Constructor method) Constructs a rectangle with a top left corner at (in_left, in_top) with a width of in_width and a height of in_height.

boolean contains(int x, int y)
Returns true if the point (x, y) is contained within the rectangle. Note that the rectangle is considered to include the points on its border.

int getArea()
Returns the area of the rectangle.

void grow(int amount)
Grows the rectangle bigger in all four directions by amount units. For example, if the rectangle had a top left corner at (4,5) and a bottom right corner at (7,6), and then it is grown by two units, its new top left and bottom right corners would be at (2,3) and (9,8), respectively.

The following class to test your Rectangle class illustrates how it should work.

import csbsju.cs160.*;

public class RectangleTest {
    public static void main(String[] args) {
        Rectangle rect = new Rectangle(5, 5, 10, 10);
        if(!rect.contains(7, 7)) IO.println("fails 1");
        rect.grow(2);
        if(!rect.contains(4, 4)) IO.println("fails 2");
        if(rect.contains(18, 8)) IO.println("fails 3");
        if(rect.getArea() != 14 * 14) IO.println("fails 4");
        IO.println("done");
    }
}

Solutions to example problems are posted on a different page.