Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Done. #281

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Done. #281

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/main/java/core/basesyntax/Application.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
package core.basesyntax;

import java.util.Date;

public class Application {
public static void main(String[] args) {
// test your code here ...
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);
}
}
64 changes: 63 additions & 1 deletion src/main/java/core/basesyntax/Car.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,67 @@
package core.basesyntax;

public class Car {
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;
}

public void setEngine(Engine engine) {
this.engine = engine;
}

@Override
public Car clone() {
try {
Car carClone = (Car) super.clone();
carClone.setEngine(engine.clone());
return carClone;
} catch (CloneNotSupportedException e) {
throw new RuntimeException("Can not clone car.", e);
}
}

@Override
public String toString() {
return "Car{"
+ "id='" + id + '\'' + ", model='" + model + '\'' + ", price=" + price
+ ", color='" + color + '\'' + ", engine=" + engine + '}';
}
}
64 changes: 63 additions & 1 deletion src/main/java/core/basesyntax/Engine.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,67 @@
package core.basesyntax;

public class Engine {
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;
}

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;
}

public void setManufactureDate(Date manufactureDate) {
this.manufactureDate = manufactureDate;
}

@Override
public Engine clone() {
try {
return (Engine) super.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException("Can not clone engine.", e);
}
}

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