You will develop two components in this part:
Design the class changeableTank which is a subclass of class displayTank. Be sure to save displayTank.java in your Tank directory. changeableTank that will also reside in your Tank directory.
changeableTank inherits all fields and methods of displayTank. The following skeleton should be used for building this class:
import java.awt.*; public class changeableTank extends displayTank { public static final int UP=1; public static final int RIGHT=2; public static final int DOWN=3; public static final int LEFT=4; protected boolean big_=true; protected int facing_=UP; protected boolean right_= true; public changeableTank(int x, int y) { super(x,y); //Invoke the class displayTank's constructor } public boolean right(){ return right_; } public boolean big(){ return big_; } public void switchSize() { /*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 changePosition(int x, int y) { /*Write the method that given a new x,y coordinate to reposition the tank. Set x_ and y_ to these parameters.*/ } public void setDirection(boolean right) { right_=right; } public void turn(){ /*Write the method that controls the value of facing_ which is used in display method. Manipulation of facing_ here enables us to rotate the tank by quarter of a turn each time turn is called. The direction we turn (i.e change facing_) depends on right_. When right_ is true we turn the tank clockwise (i.e. change right_ from UP to RIGHT, from RIGHT to DOWN, from DOWN to LEFT, or from LEFT to UP. When right_ is false we turn the tank counterclockwise. */ } //Draw the Tank public void display (Graphics g) { /* Draw the tank. if facing_ is UP, fluid should draw on the bottom, and empty area on top (just like displayTank does it). If facing_ is RIGHT, fluid should draw on the left, and empty area on the right. if facing_ is DOWN, fluid should draw on the top, and empty area on bottom (upside down tank). finally, if facing_ is LEFT, fluid should draw on the right, and empty area on the left. */ } }
Use the applet Test Changeable Tank Class to test your class. Download testChangeable.java into your Tank directory along with its .html file.
Develop your own applet to work like my Changeable Tank Applet . use the code for Display Tank Applet as a guide to make this one. Download tankApplet.java.
Mail me your changableTank.java and changeableTankApplet.java. Add links for both testChangeable.html and changeableTankApplet.html to your 241.html page as well.
Turn all .java files in your Tank directory into members of package csc241.Tank:
<applet codebase="http://www.oswego.edu/~your_user_name/classes" code="csc241.Tank.changeableTankApplet.class" width=800 height=500 > </applet>
<applet codebase="http://www.oswego.edu/~your_user_name/classes" code="csc241.Tank.testChangeable.class" width=600 height=500 > </applet>
mail me a note saying that I can check your link for part1 again, don't send any files here.
You will build an applet that maintains a queue and a stack of tanks. Check my Tank Priority Applet to see how your applet should work.
You will need to have completed the fixedStack implementation of the Stack interface in your lab3 before doing this assignment.
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, stack object, etc. If nullpointerExceptions are generated when you run the applet with appletviewer, you should pay attention to them and correct the problem.
This applet implements a priority scheme which should be fairly straightforward. There are only two buttons in this applet, Make Tank and Release Tank.
Each time a Make Tank button is clicked, a tank is created, a random amount of fluid is added to it, and it is either made to be the active tank or placed on a queue. if there is already an active tank and it has more fluid in it than our new tank, the new tank joins the queue, otherwise, the active tank joins the stack and the new tank becomes the active tank.
Each time Release Tank button is clicked, a tank is taken off the queue or stack to replace the active tank. Obviously, if only one of the two has one or more tanks on it, thats where you would get the tank from. If both have tanks on them, then you must pick either the one in front of the queue or the one on top of the stack depending on which has the higher content.
The active tank, if one exists, is displayed at the bottom of the screen and centered. It should be in its "big" state and displayed upright.
The tanks in the queue must be displayed in the upper left corner. Tanks in this case, must be facing left and be in their "small" state with the tank in front displayed first right after the label "front". The tanks on the stack, need to be displayed on the right side of the screen. The tank on top displayed first right under the label "top".
mail me the tankQueueApplet.java file and keep a link to the html file for this applet in your csc241 page.