34 lines
705 B
Java
34 lines
705 B
Java
public class Ball {
|
|
private double diameter;
|
|
private String color;
|
|
private int timesBounced;
|
|
|
|
public Ball(double newDiameter, String newColor) {
|
|
diameter = newDiameter;
|
|
color = newColor;
|
|
timesBounced = 0;
|
|
}
|
|
|
|
public double getDiameter() {
|
|
return diameter;
|
|
}
|
|
|
|
public String getColor() {
|
|
return color;
|
|
}
|
|
|
|
public int getTimesBounced() {
|
|
return timesBounced;
|
|
}
|
|
|
|
public void bounceBall() {
|
|
timesBounced++;
|
|
}
|
|
|
|
public String toString() {
|
|
return "This ball is " + color + " with a diameter of " +
|
|
diameter + " and has been bounced " + timesBounced +
|
|
" times!";
|
|
}
|
|
}
|