fork download
  1.  
  2. import java.util.*;
  3. import java.lang.*;
  4. import java.io.*;
  5.  
  6. class Main
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. Pizza myPizza = new PizzaBuilder()
  11. .setDough(Dough.WHITE)
  12. .setCheese(Cheese.WHITE)
  13. .addTopping(Topping.Kittens)
  14. .addTopping(Topping.Salami)
  15. .buildPizza();
  16. }
  17.  
  18. static enum Dough{
  19. WHITE, BROWN
  20. }
  21. static enum Cheese{
  22. WHITE, BROWN
  23. }
  24. static enum Topping{
  25. Kittens, Onions, Salami
  26. }
  27.  
  28. static class Pizza{
  29.  
  30. private Dough dough;
  31. private Cheese cheese;
  32. private HashSet<Topping> toppings;
  33.  
  34. private Pizza(Dough dough, Cheese cheese, HashSet<Topping> toppings){
  35. this.dough = dough;
  36. this.cheese = cheese;
  37. this.toppings = toppings;
  38. }
  39.  
  40. //add some getters
  41.  
  42. }
  43.  
  44. static class PizzaBuilder{
  45.  
  46. private Dough dough;
  47. private Cheese cheese;
  48. private HashSet<Topping> toppings = new HashSet<Topping>();
  49.  
  50. public PizzaBuilder(){
  51.  
  52. }
  53. public PizzaBuilder setDough(Dough dough){
  54. this.dough = dough;
  55. return this;
  56. }
  57. public PizzaBuilder setCheese(Cheese cheese){
  58. this.cheese = cheese;
  59. return this;
  60. }
  61. public PizzaBuilder addTopping(Topping topping){
  62. this.toppings.add(topping);
  63. return this;
  64. }
  65. public Pizza buildPizza(){
  66. return new Pizza(this.dough, this.cheese, this.toppings);
  67. }
  68.  
  69. }
  70.  
  71. }
  72.  
  73.  
  74.  
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
Standard output is empty