1
+ package builder ;
2
+
3
+ public class Customer {
4
+
5
+ private String firstName ;
6
+ private String lastName ;
7
+ private String email ;
8
+ private int age ;
9
+ private int shoeSize ;
10
+ private double yearlyIncome ;
11
+ private double yearlyAmountSpendOnShoes ;
12
+ private boolean isMarried ;
13
+
14
+ public static class Builder {
15
+
16
+ private String firstName ="" ;
17
+ private String lastName ="" ;
18
+ private String email ="" ;
19
+ private int age =0 ;
20
+ private int shoeSize =0 ;
21
+ private double yearlyIncome =0 ;
22
+ private double yearlyAmountSpendOnShoes =0.0 ;
23
+ private boolean isMarried =false ;
24
+
25
+ public Builder withFirstName (String firstName ) {
26
+ this .firstName =firstName ;
27
+ return this ;
28
+ }
29
+
30
+ public Builder withLastName (String lastName ) {
31
+ this .lastName =lastName ;
32
+ return this ;
33
+ }
34
+
35
+ public Builder withEmail (String email ) {
36
+ this .email =email ;
37
+ return this ;
38
+ }
39
+ public Builder withAge (int age ) {
40
+ this .age =age ;
41
+ return this ;
42
+
43
+ }
44
+ public Builder withShoeSize (int shoeSize ) {
45
+ this .shoeSize =shoeSize ;
46
+ return this ;
47
+ }
48
+ public Builder withYearlyIncome (int yearlyIncome ) {
49
+ this .yearlyIncome =yearlyIncome ;
50
+ return this ;
51
+ }
52
+ public Builder withYearlyAmountSpendOnShoes (double yearlyAmountSpendOnShoes )
53
+ {
54
+ this .yearlyAmountSpendOnShoes =yearlyAmountSpendOnShoes ;
55
+ return this ;
56
+ }
57
+
58
+ public Builder isMarried (boolean isMarried ){
59
+ this .isMarried =true ;
60
+ return this ;
61
+ }
62
+
63
+ public Customer build () {
64
+ return new Customer (this );
65
+ }
66
+
67
+ }
68
+
69
+
70
+ private Customer (Builder builder ) {
71
+
72
+ this .firstName =builder .firstName ;
73
+ this .lastName =builder .lastName ;
74
+ this .email =builder .email ;
75
+ this .age =builder .age ;
76
+ this .shoeSize =builder .shoeSize ;
77
+ this .yearlyIncome =builder .yearlyIncome ;
78
+ this .yearlyAmountSpendOnShoes =builder .yearlyAmountSpendOnShoes ;
79
+ this .isMarried =builder .isMarried ;
80
+
81
+ }
82
+
83
+
84
+ @ Override
85
+ public String toString () {
86
+ return "Customer [firstName=" + firstName + ", lastName=" + lastName + ", email=" + email + ", age=" + age
87
+ + ", shoeSize=" + shoeSize + ", yearlyIncome=" + yearlyIncome + ", yearlyAmountSpendOnShoes="
88
+ + yearlyAmountSpendOnShoes + ", isMarried=" + isMarried + "]" ;
89
+ }
90
+
91
+
92
+ }
0 commit comments