Question: This week we want to build an inheritance hierarchy using targets. You now need to take the Target class we have built and create a

This week we want to build an inheritance hierarchy using targets. You now need to take the Target class we have built and create a subclass that inherits from it. You can do whatever you want here, but it should be obvious how you changed the target. Some examples might include adding an additional ellipse to the target to increase the number of levels or changing up the colors. Once you have come up with one way to change the target, do a second. This should also be a subclass of the Target class we made above and the change made should be obvious. In total, you should have three classes to be submitted, the one we did together and the one you built.

//CODE THAT WAS PROVIDED

// --------------- imports ------------------------------ import wheelsunh.users.*; import java.awt.Color; public class Target extends ShapeGroup { //---------------- instance variables ------------------------------ // local "constant" variables define the locations of the inner // circles relative to the level1 circle. protected final int level2X = 15, level2Y = 15; protected final int level3X = 25, level3Y = 25; protected final int level4X = 30, level4Y = 30; // local "constant" variables define the sizes of all circles protected final int level1Size = 80; protected final int level2Size = 50; protected final int level3Size = 30; protected final int level4Size = 20; // other local variables are used to references Wheels objects // used to draw the target. protected Ellipse level1; protected Ellipse level2; protected Ellipse level3; protected Ellipse level4; // ----------------------------------------------------------------- /** * Constructor for the TargetApp class. */ public Target() { super(); this.makeTarget( 0, 0 ); } //////////////////////////////////////////////////////////////////// /** * 2 parameter constructor goes here: */ // Write constructor with position parameters (2 ints) public Target( int x, int y) { super(); this.makeTarget( x, y ); } //////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------- /* * Notice that this method is commented out, that is intentional. Since ShapeGroup has a setLocation method * that will move our shapes for us, we do not need to write one ourselves. We will need to connect our shapes to * the ShapeGroup for this to work though. That will happen down in makeTarget. */ /** * setLocation( int x, int y ). * change the location of the target; * need to invoke setLocation on 4 ellipses that compose target. * * @param x int * @param y int */ // public void setLocation( int x, int y ) { // ///////////////////////////////////////////////////////// // // setLocation code here // // // //////////////////////////////////////////////////////// // } // ----------------------------------------------------------------- /** * move( int dx, int dy ). * move the location of the target by dx and dy * newx = oldx + dx * newy = oldy + dy * use Target's setLocation method to actually change the location * * @param dx int * @param dy int */ public void move( int dx, int dy ) { ///////////////////////////////////////////////////////// // move code here super.setLocation( dx + super.getXLocation(), dy + super.getYLocation() ); //////////////////////////////////////////////////////// } // ----------------------------------------------------------------- /** * makeTarget. * encapsulates all the Wheels components needed to draw a target. * * @param x int * @param y int */ public void makeTarget( int x, int y ) { // create the level1 circle level1 = new Ellipse( x, y ); level1.setSize( level1Size, level1Size ); super.add( level1 ); // create the next level4 circle level2 = new Ellipse( x + level2X, y + level2Y ); level2.setSize( level2Size, level2Size ); level2.setColor( Color.BLUE ); super.add( level2 ); // create the next level4 circle level3 = new Ellipse( x + level3X, y + level3Y ); level3.setSize( level3Size, level3Size ); level3.setColor( Color.CYAN ); super.add( level3 ); // create the level4 circle level4 = new Ellipse( x + level4X, y + level4Y ); level4.setColor( Color.BLACK ); level4.setSize( level4Size, level4Size ); super.add( level4 ); } // ----------------------------------------------------------------- /** * main program just invokes the class constructor. * * @param args String */ public static void main( String[] args ) { Frame f = new Frame(); Target t1 = new Target(); t1.setLocation( 100, 100 ); //Notice here even though we do not have a setLocation, we can call the parent one //////////////////////////////////////////////////////////////// // Add much more Target creation code here // Utilities.sleep( 1000 ); t1.move(100, 100); Utilities.sleep( 1000 ); t1.move(100, 100); Utilities.sleep( 1000 ); t1.move(100, 100); //////////////////////////////////////////////////////////////// } } //End of Class TargetApp 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!