Adjust the first few lines of the Player and Ball constructors in order to get t
ID: 3734435 • Letter: A
Question
Adjust the first few lines of the Player and Ball constructors in order to get the code to compile by calling the new constructor that you made in MovableObject which now takes 3 parameters, not just the one. When making your changes ... think about which initial direction, speed and location that you want to pass as parameters ... are they fixed values or parameters ? Your Ball constructor should have 2 lines remaining in it once you are done and your Player constructor should have 5 lines. Both Ball and Player should now compile ok.
Add a constructor to the StationaryObject class which calls super(loc); to simply set the initial location. Although there are no shared attributes between Wall, Trap and Prize, we will still make them inherit from StationaryObject in case we need to add additional shared attributes or behaviors in the future. The StationaryObject, Wall, Trap and Prize classes should all compile (i.e., no red) ok. Make sure that they do before you continue.
Cant seem to understand this part ^. Please add comments with detail! thanks
CODE:
Explanation / Answer
here is your modified Code :----------->>>>>>>>
import javafx.geometry.Point2D;
import javafx.scene.paint.Color;
public class Player extends MovableObject {
private String name;
private Color color;
private boolean hasBall;
private int score;
public Player(String n, Color c, Point2D loc, int dir) {
//here i changed the super function call to add two more parameter you can change the speed value 5
//same thing you can do with the Ball class i did not find your Ball class here
super(dir,5,loc);
name = n;
color = c;
hasBall = false;
score = 0;
}
import javafx.geometry.Point2D;
public class MovableObject extends GameObject {
protected int direction;
protected int speed;
public MovableObject(int d, int s, Point2D loc){
super(loc);
direction = d;
speed = s;
}
}
import javafx.geometry.Point2D;
public class GameObject {
protected Point2D location;
public GameObject(Point2D loc){
location = loc;
}
public Point2D getLocation() { return location; }
public void setLocation(Point2D newLocation) { location = newLocation; }
}
import java.awt.geom.Point2D;
public class StationaryObject extends GameObject {
//here i added the Constructor and add a super call with the Point2D object
public StationaryObject(Point2D loc){
super(loc);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.