Assignment 3: New objects, random numbers, return values from methods, and while loops
Introduction to Computer Program Design: Assignment 3


Goals
The goal of this assignment is for you to be able to construct programs in Java that- create new objects and call methods on them
- use random numbers
- return values from methods
- have while loops
Resources and links
- Online Part: Online questions
- Programming part:
- Download Zip file
- Submit your java files.
- Marks and Feedback.
- Java Documentation
Online part
Start with the online part as it will help you consolidate your knowledge for the programming part. This part is compulsory and you must pass all the online questions related to this assignment by the deadline to pass this assignment.The Challenge questions are optional but would help your learning.


Programming part
To Submit:
-
PetShow.java
-
Animal.java
(if you do the challenge part)

setupGui
and main
methods.

Zip file
PetShow: Pass level

PetShow
program should tell a short animated story using Animal
objects. The story consists of 3 animals (randomly situated), that performs the same "welcome" routine. Then the left and right most animals will compete towards their respective exit (the closest to them). The animation stops when one of them has crossed their respective exit line. The animal that is horizontally in the middle remains still.


-
closestToLeft
which returns the animal closest to the left of the Graphic Pane -
closestToRight
which returns the animal closest to the right of the Graphic Pane -
routine
which makes the animal perform some routine. The routine can be as simple as "introducing itself, going left, jumping, going right, speaking". Try to use a mix of methods from theAnimal
class. You can be as creative as you want. You will need to think about what parameter(s) the routine method needs to have. -
animate
that animate the whole story.
- You must use the
EXIT_LEFT
,EXIT_RIGHT
,START_LEFT
, andSTART_RIGHT
constants. - The 3 animals must be initially randomly placed horizontally between
START_LEFT
andSTART_RIGHT
. - You may choose their vertical position.
- The
animate
method must call theroutine
,closestToLeft
, andclosestToRight
methods with the right parameters. - Use a
while
loop to move the animals towards their goal line. - You should also look at the documentation version of
Animal.java
to find out the parameters of the constructor and the names and parameters of the methods in theAnimal
class. (OpenAnimal.java
in the BlueJ editor and select the "documentation" option.)
Animal
class has already been written for you and includes various methods such as goLeft
, goRight
, jump
, speak
etc.

Animal
constructor must be the name of an image in the animals
folder. There are several images called "bird", "dinosaur", "dog", "grasshopper", "snake", "tiger", and "turtle" in the download folder, but you can make your own if you wish. They must be gif files. Remember to submit them!