Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Burger {
- private String cheese, patty, buns;
- public Burger() {}
- public void setCheese(String cheese) {
- this.cheese = cheese;
- }
- public void setPatty(String patty) {
- this.patty = patty;
- }
- public void setBuns(String buns) {
- this.buns = buns;
- }
- @Override
- public String toString() {
- return "Burger{" +
- "cheese='" + cheese + '\'' +
- ", patty='" + patty + '\'' +
- ", buns='" + buns + '\'' +
- '}';
- }
- }
- class BurgerBuilder {
- private Burger burger;
- public BurgerBuilder() {
- burger = new Burger();
- }
- public BurgerBuilder addBuns(String bunStyle) {
- burger.setBuns(bunStyle);
- return this;
- }
- public BurgerBuilder addCheese(String cheeseStyle) {
- burger.setCheese(cheeseStyle);
- return this;
- }
- public BurgerBuilder addPatty(String patty) {
- burger.setPatty(patty);
- return this;
- }
- public Burger build() {
- return this.burger;
- }
- }
- public class Main {
- public static void main(String[] args) {
- var burgerBuilder = new BurgerBuilder();
- var burger = burgerBuilder
- .addBuns("sesame")
- .addPatty("fish-patty")
- .addCheese("chedar")
- .build();
- System.out.println(burger);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement