CSC 241- Assignment 2


Part 1 -- Changeable Tank (Due February 23, 2001)

You will develop two components in this part:

changeableTank Class

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.
   */    
  }

}