Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Start with superclass CircleinSquare and with subclass RunCIS. Using code provided: In superclass, create new overloaded method travel4 parms Independent change in size and width

Start with superclass CircleinSquare and with subclass RunCIS.

Using code provided:

In superclass, create new overloaded method travel4 parms

Independent change in size and width of circle and square

In subclass

Run new method on drag

Test with: (-.2, .6, 1, -.1)

code for circle in square class

import objectdraw.*; import java.awt.*; public class CircleInSquare { private static final int SQUARE_SIZE = 100, // dimensions of the square CIRCLE_RADIUS = 50, // dimensions of the circle POS = 50, // position of msg OFFSET = 25; // offset value circle inside square private FilledRect square; // filled rect for square private FilledOval circle; // filled oval for circle private Text msg; // msg for inside or outside of box RandomIntGenerator goWhere = new RandomIntGenerator(-30,30); // Create pieces of CircleInSquare public CircleInSquare( double left, double top, DrawingCanvas canvas) { square = new FilledRect( left, top, SQUARE_SIZE, SQUARE_SIZE, canvas ); circle = new FilledOval( left + OFFSET, top + OFFSET, CIRCLE_RADIUS, CIRCLE_RADIUS, canvas ); } // Determine whether pt is inside square public boolean containsS(Location pt) { return square.contains(pt); } // Determine whether pt is inside circle public boolean containsC(Location pt) { return circle.contains(pt); } // set color based on parm passed public void setCISColor( int e ){ if ( e == 1 ) { square.setColor ( Color.RED ); circle.setColor ( Color.BLUE ); } else if ( e == 2) { square.setColor ( Color.BLUE ); circle.setColor ( Color.RED ); } else { square.setColor ( Color.YELLOW ); circle.setColor ( Color.YELLOW ); } } // move the circle and the square by the proscribed amounts // an example of polymorphism public void travel(double dx, double dy) { square.move(dx,dy); circle.move(dx,dy); } // overload and move by the negative amount public void travel(double dz) { //dz = dz * -1; square.move(-dz, -dz); circle.move(-dz, -dz); } // overload and split the shapes randomly public void travel(char c){ if (c == 'r') { int x = goWhere.nextValue(); int y = goWhere.nextValue(); square.move(x, y); x = goWhere.nextValue(); y = goWhere.nextValue(); circle.move(x, y); } } // overload and change size // complete the code for this override // hint: setWidth and setHeight give size of base object public void travel(double da, double db, double dc, double dd) { } } 

code for runCis is

import objectdraw.*; import java.awt.*; public class RunCIS extends WindowController { private static final int OFFSET = 50; // offset for center private static final int POS = 25; // offset for message private CircleInSquare cis; // circle in square // msg for inside or outside of box private Text msg = new Text(" ", POS, POS, canvas ); // creat new cis at center // set color to option 1 // set text to Click Somewhere public void begin() { cis = new CircleInSquare( canvas.getWidth()/2 - OFFSET, canvas.getHeight()/2 - OFFSET, canvas ); cis.setCISColor(1); msg.setText(" Click Somewhere or Drag " ); } // call method to determine if inside square // print message based on results // inside square, inside circle, outside of square // for circle hit move (20,20) // for square hit move (-20,-20) // elswhere split shapes randomly if parm is r public void onMouseClick(Location pt) { msg.setText( " " ); if ( cis.containsC( pt )) { msg.setText( "You clicked inside the circle " ); cis.travel(20, 20); } else if ( cis.containsS( pt ) ) { msg.setText( "You clicked inside the square " ); cis.travel(20); } else { msg.setText( "You clicked outside the square " ); cis.travel('r'); //cis.travel('x'); } } // clear and begin public void onMouseEnter( Location point ) { canvas.clear(); begin(); } // hide messsage - setText " " // set box color to option 2 public void onMouseExit( Location point ) { msg.setText( " " ); cis.setCISColor(2); } // complete this code // values will make the circle and square resize indenpendently public void onMouseDrag( Location point ) { } } 

i have provided you the question and the code also.please do as per the question for same code.

thankyou

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions