Исправления: добавлен вызов метода для передачи параметра количества катков #3

Merged
pgirl1 merged 1 commits from lab2 into lab3 2022-11-01 14:04:40 +04:00
4 changed files with 11 additions and 10 deletions

View File

@ -25,10 +25,14 @@ public class DrawingArmoredCar {
public DrawingArmoredCar(int speed, float weight, Color bodyColor) {
this.armoredCar = new EntityArmoredCar(speed, weight, bodyColor);
IDrawingCaterpillar[] realisations = new IDrawingCaterpillar[]{
new DrawingCaterpillar(bodyColor),
new DrawingCrossCaterpillar(bodyColor),
new DrawingDoubleCaterpillar(bodyColor)};
Random r = new Random();
IDrawingCaterpillar[] realisations = new IDrawingCaterpillar[]{new DrawingCaterpillar(r.nextInt(4, 7), bodyColor),
new DrawingCrossCaterpillar(r.nextInt(4, 7), bodyColor), new DrawingDoubleCaterpillar(r.nextInt(4, 7), bodyColor)};
int num = r.nextInt(4, 7);
this.drawingCaterpillar = realisations[r.nextInt(3)];
drawingCaterpillar.setNumRinks(num);
}
protected DrawingArmoredCar(int speed, float weight, Color bodyColor, int carWidth, int carHeight) {

View File

@ -4,11 +4,10 @@ public class DrawingCaterpillar implements IDrawingCaterpillar {
private NumRinks numRinks = NumRinks.Four;
private Color color;
public DrawingCaterpillar(int n, Color color) {
setNumRinks(n);
public DrawingCaterpillar(Color color) {
this.color = color;
}
@Override
public void setNumRinks(int n) {
switch (n) {
case 4 -> numRinks = NumRinks.Four;
@ -22,7 +21,7 @@ public class DrawingCaterpillar implements IDrawingCaterpillar {
}
}
}
@Override
public void DrawCaterpillar(Graphics2D g2d, int startPosX, int startPosY)
{
color = color != null ? color : Color.YELLOW;

View File

@ -4,8 +4,7 @@ public class DrawingCrossCaterpillar implements IDrawingCaterpillar{
private NumRinks numRinks = NumRinks.Four;
private Color color;
public DrawingCrossCaterpillar(int n, Color color) {
setNumRinks(n);
public DrawingCrossCaterpillar(Color color) {
this.color = color;
}

View File

@ -4,8 +4,7 @@ public class DrawingDoubleCaterpillar implements IDrawingCaterpillar{
private NumRinks numRinks = NumRinks.Four;
private Color color;
public DrawingDoubleCaterpillar(int n, Color color) {
setNumRinks(n);
public DrawingDoubleCaterpillar(Color color) {
this.color = color;
}