Programming Assignment #2

Computer
Programming I                 

COP 2210                                  

Programming Assignment #2

(Using
an Existing Class: Creating Objects


and
Calling Accessor and Mutator Methods
)

I. The Assignment

This assignment is to write a “test” class (aka: a “driver” class or “client code”) that uses the class Balloon.java, available on the class web page. 

To use the Balloon class, download it and store it in the src folder of your NetBeans
project.  Make sure you save it as Balloon.java.
The best way to learn how to use the Balloon class – or any other Java class - is to consult the documentation, Balloon.html (online).  You can also read the javadoc comments that appear just above the class declaration and above each
method declaration, which explain what each method does, what the method’s
parameters are, and what value – if any - is returned by the method.  The html “help” pages are generated from
these comments.
Don’t worry if you don’t understand the code.  It will
all be covered later.  It is not necessary to know how a method
works as long as you know what it does and how to call it.
 

Review declaring variables, creating objects, calling methods that
return a value vs. “void” methods, and accessor
and mutator methods before beginning.
To receive credit for this assignment,
you must not modify the Balloon class in any way!


II. Your BalloonTester Class
Your BalloonTester class will have only a
single method – main – and will perform each of the following operations, in
the exact order listed below.  Each
operation may be done in one or two statements. 
Make sure you follow directions faithfully, and note that once you have
done step 3, you can copy and paste it to do steps 6, 9, and 12.
1.   Create a Balloon object with a name of your own choosing and an
altitude of 100 meters.
2.   Create a second Balloon object with a name of your own choosing, and
specify an initial altitude of -100 meters.
3.   Call the accessor methods of
the Balloon class to get the name and altitude of each Balloon object. Print
the data, one object per line.
4.   Make the object you created in step 1 ascend to an altitude of 300
meters.
5.   Call the adjustAltitude
method to increase the altitude of the object you created in step 2 by 200
meters.  
Call the accessor methods of
the Balloon class to get the name and altitude of each object. Print the data,
one object per line.
7.   Call the adjustAltitude
method to decrease the altitude of the object you created in step 1 by 150
meters.
8.   Make the object you created in step 2 descend to the same altitude as
the other object. You may assume that
the other object is at a lower altitude.


To get credit for step 8., the statement(s) you write
must
always work, regardless of the actual altitude of the second object. It
cannot depend on
you knowing the
altitude of the second object, but must utilize the fact that the object knows
its own altitude. In other words, if you use a
literal to set the altitude, it is not correct.

9.   Call the accessor methods to get the name and altitude of each object.
Print the data, one object per line.

10.   Move the object you created in step 1 to an altitude that is three
times its current altitude.  As in step 8,
the statement(s) you write must work for any
altitude and may not depend on you “figuring out” the new altitude beforehand.
11.   Attempt to move the object you created in step 2 to an altitude that is
200 meters below its current altitude.
12.   Call the accessor methods to get the name and altitude of each object.
Print the data, one object per line.
III. What to Upload to Moodle
Upload a zip file
containing
1.   Your BalloonTester class
2.   The output generated when the program runs

 

 
Powered by