CST 112
2019 Fall
Exam #2 (Q2 & R2)
Follow the instructions below to write your own (Processing) Java code
for both exams:
- Submit the in-class exam as a file named "Q2.java" in your folder.
- Submit takehome exam as "R2.java" in your folder, by noon on Sunday 11/3.
Instructions:
Write Java code to define these object classes:
Button,
Monster,
Witch,
Animal,
Tree
.
You may use (and modify) code from the
"template code"
Each instance of these objects must have a (global) name that follows the rules, below.
All object properties must be defined within the object class,
and global variables must not be used for the properties of any of these objects.
Create a dynamic sketch
with scene, buttons, etc., and actions as decribed below.
- Scene:
A pale moon hangs in the middle of a dark sky
(which fills the top quarter of the screen),
above a grassy area.
(Title, author, and score should be displayed.)
- Trees:
Five trees are placed at random positions within the grassy area.
- Buttons:
When any of the the four Buttons is clicked,
a different action is performed.
- Witch:
A witch (with pointy hat)
rides a broomstick across the sky, from right to left.
- Mooon:
When the Witch passes in front of it,
the moon changes to a different color.
- Candy treat:
When mouse is clicked at some point below horizon,
a candy treat is placed at that point,
and Monster appears on left side of screen,
at random height.
- Monster:
While candy treat is visible,
the Monster slowly moves toward it.
If monster gets near treat,
both are reset, disappearing from screen,
and points are deducted from score,
- Animal:
A small animal
(such as a rabbit or cat)
constantly runs around the grassy area,
bouncing off the boundaries.
(The animal is ignored by the other creatures.)
Animation:
Witch, Monster, and Animal should all display some sort of animation, as they move.
(Animation may be added for candy treat,
but none is needed for moon or trees.
Buttons:
The four buttons should have the following labels and perform the actions described below:
- Zap:
Witch shoots a red laser beam downward
(lasting for a short while).
If beam hits monster
(X coordinates near each other),
Monster vanishes and points are added to score.
If beam misses, deduct points;
if it hits Animal, deduct more!
- Back:
Witch moves in the opposite direction.
- Reset:
Reset Monster, Witch and Animal.
- Trees:
Reset all five trees to random positions (and size?)
Names of objects.
When you declare a global variable as an instance of a class,
the name depends on your own name, following these rules:
Monster
instance name
begins with:
| first letter of your Firstname
(in lower case)
|
Witch
instance name
begins with:
| first letter of your Lastname
(in lower case)
|
Animal:
instance name
begins with:
| last letter of your Lastname
|
Tree:
instance names
begin with:
| fourth letter of your Lastname
|
For example, if your name is:
Firstname
Lastname ,
then your declarations might look something like these:
Monster frank;
Witch linda;
Animal elmer = new Animal();
Tree t1, t2, t3, t4, t5;
Available Resources
This exam
(and all computer programming exams)
will be "open book"
This
"template code"
(and this
"starter code")
which you may modify or use in your own code.
|
This
"sample code"
contains a solution,
which you may study;
however, none of this sample code may be submitted as part of your own code.
|