CSC 241- Assignment 2
Part 1 -- Changeable Tank + test Applet (Due September 30, 1999)
Design the class changeableTank which is a subclass of
class displayTank. changeableTank.java should be in your
Tank directory. changeableTank inherits all fields and methods
of displayTank as well as Tank itself. Here are the elements
that are needed in changeableTank:
- The only field in changeableTank is:
protected boolean big_=true;
- A constructor:
public changeableTank(int x, int y) {
super(x,y); //Invoke the class displayTank's constructor
}
- Write the method that switches the size of a tank from small to large
or from large to small. IF big_ is true, divide the
height_ and width_ by 4 (i.e. make tank small), otherwise,
multiply them by 4 (i.e. make tank big). The big_ variable needs to be
set appropriately as well, when going from big to small or small to big.
public void switchSize()
- Write the method that given a new x,y coordinate to reposition the
tank:
public void changePosition(int x, int y) {
Build an applet that demonstrates that it works, have the applet work like
my Changeable Tank Applet , here is a snapshot of what it looks like in a browser. Develop your
applet in the Tank directory as well. Save the .html file for my
version (changeableTankApplet.html) in your Tank directory.
Your applet here is very much like Tank Applet except for
the fact that it tests the functionality of changableTank by adding a couple
buttons that either change the coordinates of the Tank, or change its size.
Mail me your changableTank.java and changeableTankApplet.java. Add a link
to your 241.html page as well.
Part 2 -- Tank Queue Applet (Due October 20th 1999)
Part 2-1
Turn all .java files in your Tank directory into members of package
csc241.Tank:
- you will need package csc241.Tank; added to the top of every .java involved in the Tank directory. (Tank.java, displayTank.java,
changeableTank.java, and changeableTankApplet.java)
- Recompile everything in the Tank directory with
javac Tank.java
javac displayTank.java
javac changeableTank.java
javac changeableTankApplet.java
- change the changeableTankApplet.html file by replacing the
applet tag in it with the following:
<applet
codebase="http://www.oswego.edu/~your_user_name/classes"
code="csc241.Tank.changeableTankApplet.class"
width=800
height=500
>
</applet>
- proceed if you can still load your changeableTankApplet.
Part 2-2
You will build an applet that maintains a queue of tanks. Check my
Tank Queue Applet to see how your applet should
work. In general, write with safety in mind. A tank object should not
be manipulated if the variable referencing it is null. The same
things holds true for a queue object, or any other objects. If
nullpointerExceptions are generated when you run the applet with
appletviewer, you should pay attention to them and correct the problem.
- Create an Applets directory off of your csc241 directory.
- Start creating this applet based on the changeableTankApplet.
- The package name in this case should be csc241.Applets.
- You need to import two packages from your area amongst other
things that you import, such as, awt. These packages are:
csc241.Queue and csc241.Tank.
- You need to have a panel that provides a text field, a button
for Enqueue and one for Dequeue.
- You need to have a panel with buttons to let the user create
new tanks, add, and remove fluid. This panel should also have a
text field providing tank status information.
- You will need a field for an active tank that must start as
null.
Any time, the New Tank button is hit, a new active tank is
created, as long as, there isn't an active tank already in place.
- You will need a field for a queue of tanks. The queue should be
created upon construction, but of course, nothing will displayed
until tanks are placed on it. This queue of tanks object is a
Queue and must be constructed as a fixedQueue of size 100.
- When the enqueue button is clicked with an active tank
displayed in the middle, 1st, the switchSize method of the
the active tank needs to be called to make it small; then, it needs to
be placed on to the queue . The tank field must be set
to null or it will continue to reference the tank you just moved
to the queue. Finally, a call to repaint() must be made.
- When the dequeue button is clicked with at least one tank on the
queue, regardless of existence of an active tank, one tank is dequeued
and referenced by the active tank field. The switchSize field
is again needed to restore the Tank to its large size. Finally, a call
to repaint() must be made.
- The active tank and tanks on the queue need to be displayed
appropriately, similar to Tank Queue Applet .
When the paint method is invoked:
- If an active tank exists,
it must be displayed. the changePosition should be used to ensure it
is displayed in the correct coordinates.
- if the queue is is not empty,
all tanks that have been placed on the queue need to be displayed.
Each tank must be dequeue, their position changed to where you want
them displayed and then display. Remember that if you get them
off the queue and display them without keeping them somewhere and
restoring the queue later, you will lose the tanks.
What to Turn In
mail me the tankQueueApplet.java file and keep a link to
the html file for this applet in your csc241 page.