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

added solution #207

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 11 additions & 3 deletions src/main/java/core/basesyntax/BuilderTestApp.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package core.basesyntax;

public class BuilderTestApp {
public static void main(String[] args) {
// Remove this comment and test your Builder implementation here...
}
public static void main(String[] args) {
Plane plane = new Plane.PlaneBuilder()
.setMaker("Airbus")
.setModel("A321")
.setEnginePower(15000)
.setPassegerCapacity(220)
.setMaxFlightHigh(5950)
.build();

System.out.println(plane.toString());
}
}
60 changes: 60 additions & 0 deletions src/main/java/core/basesyntax/Plane.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,65 @@
package core.basesyntax;

public class Plane {
private String maker;
private String model;
private int enginePower;
private int passegerCapacity;
private int maxFlightHigh;

private Plane(PlaneBuilder builder) {
this.maker = builder.maker;
this.model = builder.model;
this.enginePower = builder.enginePower;
this.passegerCapacity = builder.passegerCapacity;
this.maxFlightHigh = builder.maxFlightHigh;
}

@Override
public String toString() {
return "Plane{"
+ "maker='" + maker + '\''
+ ", model='" + model + '\''
+ ", enginePower=" + enginePower
+ ", passegerCapacity=" + passegerCapacity
+ ", maxFlightHigh=" + maxFlightHigh
+ '}';
}

public static class PlaneBuilder {
private String maker;
private String model;
private int enginePower;
private int passegerCapacity;
private int maxFlightHigh;

public PlaneBuilder setMaker(String maker) {
this.maker = maker;
return this;
}

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

public PlaneBuilder setEnginePower(int enginePower) {
this.enginePower = enginePower;
return this;
}

public PlaneBuilder setPassegerCapacity(int passegerCapacity) {
this.passegerCapacity = passegerCapacity;
return this;
}

public PlaneBuilder setMaxFlightHigh(int maxFlightHigh) {
this.maxFlightHigh = maxFlightHigh;
return this;
}

public Plane build() {
return new Plane(this);
}
}
}