CSci 1211 Problem set 1. Due Friday, Jan. 23rd at 5pm
fillRect methods, Java
class, and Java Random
This is the first problem set. We are still taking "baby
steps" in Java, so our first programs are "baby
Problem 1 (20 points): draw a house in a Java applet
In this program you will draw a simple picture of a house in a Java
applet. Download the following House.html
file and the House.class file to see how the
program should work.
To run the demo, save these two files in the same
folder, start the command prompt, type
myfolder by your folder name), and then type
House.class contains the
bytecode, so you don't need to compile anything.
Note: If your browser has the right plug-in, then the applet
will start automatically when you click on House.html, you don't need
to save the demo.
What you need to do:
- Create a new folder for your problem set (say,
- Copy/paste the code from this file
into a new file
House.java (start jEdit, open a new file,
copy/paste the code, and save the file into the folder
pset1). Also, save the file
House.html into the same folder.
- Add the code to draw the house (using
Color.lightGray, the windows (using
Color.yellow), and the door (using
You can figure out the rest of the parameters based on
these numbers. The picture must look exactly like the one in the demo.
- The size of the building is 200 by 250
pixels, the left upper corner is at (50, 100).
- The windows are 50 by
60 pixels, they are 25 pixels away from the sides.
- The door is 100 pixels tall.
Problem 2 (20 points): adding random numbers
This program is a Java application. You should start by copy/pasting
code from the file Add.java.
This program generates and solves a very simple arithmetic problem: if
Jack picked n apples and Jill picked m, how many apples did they pick
total? Each of them could pick any number of apples less than 10.
The output of the program should look something like this:
The program should give you different results every time you run
it. The program must have three different integer variables:
Jack picked 9 apples
Jill picked 2 apples
Together they picked 11 apples
- The variable to store the number of apples picked by Jack (already
declared in the given part of the program, called
- The variable to store the number of apples picked by Jill,
- The variable to store the total number of apples they picked.
Problem 3 (extra credit, 10 points): random rectangles.
Use file RandomRectangles.java and
of RandomRectangles.html to create
a picture that displays three random rectangles of different
colors. Clicking on RandomRectangles.html shows you the
demo if your browser is set up right (refreshing the page generates
a new picture). Otherwise download RandomRectangles.class.
This page is a part of the course CSci
1211 at UMM.
The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.