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

implemented pattern Buidler #209

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 24 additions & 3 deletions src/main/java/core/basesyntax/BuilderTestApp.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
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 boeing747 = new Plane.PlaneBuilder()
.setName("Boeing 747")
.setYear(2018)
.setCapacity(480)
.build();
System.out.println(boeing747.toString());
nut-pine marked this conversation as resolved.
Show resolved Hide resolved

Plane.PlaneBuilder airbus = new Plane.PlaneBuilder()
.setColor("White")
.setCelling(13000);

Plane airbusA330 = airbus.setName("Airbus A330")
.setCapacity(246)
.setRange(13450).build();

Plane airbusA330neo = airbus.setName("airbus A330neo")
.setCapacity(260)
.setRange(15000)
.build();
System.out.println(airbusA330);
System.out.println(airbusA330neo);
}
}
77 changes: 77 additions & 0 deletions src/main/java/core/basesyntax/Plane.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,82 @@
package core.basesyntax;

public class Plane {
private String airPlaneType;
private String name;
private String color;
private int capacity;
private int range;
private int celling;
private int year;

private Plane(PlaneBuilder builder) {
this.airPlaneType = builder.airPlaneType;
this.name = builder.name;
this.color = builder.color;
this.capacity = builder.capacity;
this.range = builder.range;
this.celling = builder.celling;
nut-pine marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public String toString() {
return "Plane{"
+ "airPlaneType='" + airPlaneType + '\''
+ ", name='" + name + '\''
+ ", color='" + color + '\''
+ ", capacity=" + capacity
+ ", range=" + range
+ ", celling=" + celling
+ ", year=" + year
+ '}';
}

public static class PlaneBuilder {
private String airPlaneType;
private String name;
private String color;
private int capacity;
private int range;
private int celling;
private int year;

public PlaneBuilder setCelling(int celling) {
this.celling = celling;
return this;
}

public PlaneBuilder setAirPlaneType(String airPlaneType) {
this.airPlaneType = airPlaneType;
return this;
}

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

public PlaneBuilder setCapacity(int capacity) {
this.capacity = capacity;
return this;
}

public PlaneBuilder setRange(int range) {
this.range = range;
return this;
}

public PlaneBuilder setYear(int year) {
this.year = year;
return this;
}

public PlaneBuilder setName(String name) {
this.name = name;
return this;
}

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