CS 201, Lab Assignment 1
This assignment is based in part on the programming exercises at the end of chapter 1. What you need to hand in is a set of clearly labelled pages, in order, with the code for any programs you've written, plus any output from the programs. Remember to put your name at the top of each page and staple or clip the assignment together for safekeeping. Notice that the easy way to get your name and other information at the top of a program is by inserting it in a comment (the stuff between /* ... */. The example program Firstprog has a comment like this and you can replace it with your information.
Part 1, 5 pts.
Book exercise P1.1. The output that your program is supposed to produce is clear. Note that the easiest way to get a start on this program is by copying the example program Firstprog and modifying it. You would need to add two more lines to the program that will print lines of output and change the stuff inside the quotation marks to produce the output desired.
Part 2, 5 pts.
Book exercise P1.3. Again, the easy way to get started with the program is to simply select, edit, copy, and paste your previous program into a new space in the editor, give the new program a suitable name, modify it to give the output desired, and remember to save it under the new name. Recall that you can do simple arithmetic inside print statements.
Part 3, 5 pts.
Here’s a modification of the book’s example program from page 38:
import java.awt.Rectangle;
public class MoveRectangle
{
public static void main(String[] args)
{
Rectangle cerealBox = new Rectangle(5, 10, 20, 30);
System.out.println(cerealBox);
cerealBox.translate(15, 25);
System.out.println(cerealBox);
}
}
In the space below, describe in your own words as best you can what the 7 lines of code in this program do. Beneath that, show what the output of the program would be. If you’re not clear, go ahead and run the program to see and compare with your handwritten answer. You do not have to turn in a copy of this program or the output of a run. However, include this assignment page with your handwritten answers when you turn in the assignment.