Answered step by step
Verified Expert Solution
Question
1 Approved Answer
java code write a method Player.java To display the Player on the grid, we have created a Player class that extends RoundedSquare. You are responsible
java code
write a method
Player.java
To display the Player on the grid, we have created a Player class that extends RoundedSquare. You are responsible for filling in the constructor and the setSize() method.
public Player()
Choose two unique colors - use one for the fill color and the other from the stroke (outline) color. We allow one of these colors to match the trail color, if you prefer. Finally, set the stroke type to centered.
public void setSize(double size)
Follow the directions in the comments to update the stroke width and call super's setSize().
RoundSquare class -
import javafx.scene.paint.color; import javafx.scene.shape.strokeType; public class Player extends RoundedSquare ( final static double STROKE_FRACTION 0.1; public Player) @override public void setsize(double size) f /TODO: 1. update the stroke width based on the size and STROKE FRACTION /2. call super setsize(), bearing in mind that the size parameter we are passed here includes stroke but the superclass's setsize() does not include the stroke import javafx.scene.shape. Rectangle public class RoundedSquare extends Rectangle ( static final double DEFAULT ARC FRACTION 0.325; static final int HALF-DIVISOR = 2; double arcFraction DEFAULT_ARC FRACTION; double centerX, centerY Constructors public Roundedsquare) this(e, e, 0); public RoundedSquare (double size) this(e, , size); public RoundedSquare (double centerx, double centerY, double size) { this .centerx centerx; this.centery centerY; setsize(size); Accessors for centerx public double getCenterx) return centterX; public void setCenterX(double centerx) this.centerx - centerX; Our superclass Rectangle is position by upper right, not by center this.setx(centerx - getsize() / HALF_DIVISOR); Accessors for centery public double getCenterY) return centery; public void setCenterY (double centerY) { this.centerv = centery; Our superclass Rectangle is position by upper right, not by center this.sety(centery - getsize() / HALF_DIVISOR); public double getsize) return getwidth(; public void setsize(double size) this.setwidth(size); this.setHeight(size); / Update super 's arcwidth for the new size: double arcWidth -size arcFraction; this.setArcwidth (arcwidth); this.setArcHeight (arcwidth); / Reposition to keep the center at centerx, centery this.setX(centerX - size / HALF_DIVISOR): this.setY (centerY - size/ HALF_DIVISOR): Accessors for arcFraction public double getArcFraction) return arcFraction; void setArcFraction (double arcFraction) this.arcFraction arcFraction; double arcwidth- this.getsize() arcFraction; this.setArcwidth (arcwidth); this.setArcHeight (arcwidth); import javafx.scene.paint.color; import javafx.scene.shape.strokeType; public class Player extends RoundedSquare ( final static double STROKE_FRACTION 0.1; public Player) @override public void setsize(double size) f /TODO: 1. update the stroke width based on the size and STROKE FRACTION /2. call super setsize(), bearing in mind that the size parameter we are passed here includes stroke but the superclass's setsize() does not include the stroke import javafx.scene.shape. Rectangle public class RoundedSquare extends Rectangle ( static final double DEFAULT ARC FRACTION 0.325; static final int HALF-DIVISOR = 2; double arcFraction DEFAULT_ARC FRACTION; double centerX, centerY Constructors public Roundedsquare) this(e, e, 0); public RoundedSquare (double size) this(e, , size); public RoundedSquare (double centerx, double centerY, double size) { this .centerx centerx; this.centery centerY; setsize(size); Accessors for centerx public double getCenterx) return centterX; public void setCenterX(double centerx) this.centerx - centerX; Our superclass Rectangle is position by upper right, not by center this.setx(centerx - getsize() / HALF_DIVISOR); Accessors for centery public double getCenterY) return centery; public void setCenterY (double centerY) { this.centerv = centery; Our superclass Rectangle is position by upper right, not by center this.sety(centery - getsize() / HALF_DIVISOR); public double getsize) return getwidth(; public void setsize(double size) this.setwidth(size); this.setHeight(size); / Update super 's arcwidth for the new size: double arcWidth -size arcFraction; this.setArcwidth (arcwidth); this.setArcHeight (arcwidth); / Reposition to keep the center at centerx, centery this.setX(centerX - size / HALF_DIVISOR): this.setY (centerY - size/ HALF_DIVISOR): Accessors for arcFraction public double getArcFraction) return arcFraction; void setArcFraction (double arcFraction) this.arcFraction arcFraction; double arcwidth- this.getsize() arcFraction; this.setArcwidth (arcwidth); this.setArcHeight (arcwidth)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started