Skip to content

Commit

Permalink
Issues fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpopko committed Mar 7, 2024
1 parent 2cbfed4 commit fa85d63
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/main/java/core/basesyntax/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ public static void main(String[] args) {
Engine engine = new Engine();
engine.setModel("V12");
engine.setManufactureDate(new Date());

Car car = new Car();
car.setEngine(engine);

Car carClone = car.clone();
carClone.getEngine().setModel("V8");

System.out.println(car);
System.out.println(carClone);
}
Expand Down
42 changes: 39 additions & 3 deletions src/main/java/core/basesyntax/Car.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
package core.basesyntax;

public class Car implements Cloneable {
private String id;
private String model;
private int price;
private String color;
private Engine engine;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getModel() {
return model;
}

public void setModel(String model) {
this.model = model;
}

public int getPrice() {
return price;
}

public void setPrice(int price) {
this.price = price;
}

public String getColor() {
return color;
}

public void setColor(String color) {
this.color = color;
}

public Engine getEngine() {
return engine;
}
Expand All @@ -24,8 +60,8 @@ public Car clone() {

@Override
public String toString() {
return "Car{" +
"engine=" + engine +
'}';
return "Car{"
+ "id='" + id + '\'' + ", model='" + model + '\'' + ", price=" + price
+ ", color='" + color + '\'' + ", engine=" + engine + '}';
}
}
34 changes: 30 additions & 4 deletions src/main/java/core/basesyntax/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
import java.util.Date;

public class Engine implements Cloneable {
private String id;
private String model;
private String type;
private int price;
private Date manufactureDate;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getModel() {
return model;
}
Expand All @@ -14,6 +25,22 @@ public void setModel(String model) {
this.model = model;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public int getPrice() {
return price;
}

public void setPrice(int price) {
this.price = price;
}

public Date getManufactureDate() {
return manufactureDate;
}
Expand All @@ -33,9 +60,8 @@ public Engine clone() {

@Override
public String toString() {
return "Engine{" +
"model='" + model + '\'' +
", manufactureDate=" + manufactureDate +
'}';
return "Engine{"
+ "id='" + id + '\'' + ", model='" + model + '\'' + ", type='" + type + '\''
+ ", price=" + price + ", manufactureDate=" + manufactureDate + '}';
}
}

0 comments on commit fa85d63

Please sign in to comment.