Skip to content

Commit 42a42d4

Browse files
committed
lesson 032
1 parent 1b41e8d commit 42a42d4

File tree

11 files changed

+291
-0
lines changed

11 files changed

+291
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.bilgeadam.boost.java.lesson032.builder;
2+
3+
public class Adress {
4+
private String street;
5+
private int doorNumber;
6+
private int postalCode;
7+
private String city;
8+
private String country;
9+
10+
public Adress(String street, int doorNumber, int postalCode, String city, String country) {
11+
super();
12+
this.street = street;
13+
this.doorNumber = doorNumber;
14+
this.postalCode = postalCode;
15+
this.city = city;
16+
this.country = country;
17+
}
18+
19+
public String getStreet() {
20+
return this.street;
21+
}
22+
23+
public int getDoorNumber() {
24+
return this.doorNumber;
25+
}
26+
27+
public int getPostalCode() {
28+
return this.postalCode;
29+
}
30+
31+
public String getCity() {
32+
return this.city;
33+
}
34+
35+
public String getCountry() {
36+
return this.country;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return "Adress [street=" + this.street + ", doorNumber=" + this.doorNumber + ", postalCode=" + this.postalCode
42+
+ ", city=" + this.city + ", country=" + this.country + "]";
43+
}
44+
45+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.bilgeadam.boost.java.lesson032.builder;
2+
3+
public class BuilderTest {
4+
public static void main(String[] args) {
5+
House house = new House.HouseBuilder(200, 4, 2, 20, new Adress("cadde", 95, 16135, "Bursa", "Turkiye"))
6+
.areaOfBackGarden(300).areaOfPorch(20).build();
7+
8+
System.out.println(house);
9+
10+
House house2 = new House.HouseBuilder(100, 4, 2, 20, new Adress("sokak", 195, 16250, "Bursa", "Turkiye"))
11+
.areaOfFrontGarden(150).areaOfPorch(20).numOfBalconies(3).build();
12+
13+
System.out.println(house2);
14+
15+
}
16+
17+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.bilgeadam.boost.java.lesson032.builder;
2+
3+
public class House {
4+
private int area; // must have
5+
private int numOfRooms; // must have
6+
private int numOfFloors; // must have
7+
private int numOfBalconies; // optional
8+
private int areaOfFrontGarden; // optional
9+
private int areaOfBackGarden; // optional
10+
private int numOfWindows; // must have
11+
private int numOfOutDoors; // optional
12+
private int areaOfPorch; // optional
13+
private Adress adress; // must have
14+
15+
public House(HouseBuilder houseBuilder) {
16+
this.area = houseBuilder.area;
17+
this.numOfRooms = houseBuilder.numOfRooms;
18+
this.numOfFloors = houseBuilder.numOfFloors;
19+
this.numOfBalconies = houseBuilder.numOfBalconies;
20+
this.areaOfFrontGarden = houseBuilder.areaOfFrontGarden;
21+
this.areaOfBackGarden = houseBuilder.areaOfBackGarden;
22+
this.numOfWindows = houseBuilder.numOfWindows;
23+
this.numOfOutDoors = houseBuilder.numOfOutDoors;
24+
this.areaOfPorch = houseBuilder.areaOfPorch;
25+
this.adress = houseBuilder.adress;
26+
}
27+
28+
@Override
29+
public String toString() {
30+
return "House [area=" + this.area + ", numOfRooms=" + this.numOfRooms + ", numOfFloors=" + this.numOfFloors
31+
+ ", numOfBalconies=" + this.numOfBalconies + ", areaOfFrontGarden=" + this.areaOfFrontGarden
32+
+ ", areaOfBackGarden=" + this.areaOfBackGarden + ", numOfWindows=" + this.numOfWindows
33+
+ ", numOfOutDoors=" + this.numOfOutDoors + ", areaOfPorch=" + this.areaOfPorch + ", adress="
34+
+ this.adress + "]";
35+
}
36+
37+
public static class HouseBuilder {
38+
private int area; // must have
39+
private int numOfRooms; // must have
40+
private int numOfFloors; // must have
41+
private int numOfBalconies; // optional
42+
private int areaOfFrontGarden; // optional
43+
private int areaOfBackGarden; // optional
44+
private int numOfWindows; // must have
45+
private int numOfOutDoors; // optional
46+
private int areaOfPorch; // optional
47+
private Adress adress; // must have
48+
49+
public HouseBuilder(int area, int numOfRooms, int numOfFloors, int numOfWindows, Adress adress) {
50+
super();
51+
this.area = area;
52+
this.numOfRooms = numOfRooms;
53+
this.numOfFloors = numOfFloors;
54+
this.numOfWindows = numOfWindows;
55+
this.adress = adress;
56+
}
57+
58+
public HouseBuilder numOfBalconies(int numOfBalconies) {
59+
this.numOfBalconies = numOfBalconies;
60+
return this;
61+
}
62+
63+
public HouseBuilder areaOfFrontGarden(int areaOfFrontGarden) {
64+
this.areaOfFrontGarden = areaOfFrontGarden;
65+
return this;
66+
}
67+
68+
public HouseBuilder areaOfBackGarden(int areaOfBackGarden) {
69+
this.areaOfBackGarden = areaOfBackGarden;
70+
return this;
71+
}
72+
73+
public HouseBuilder numOfOutDoors(int numOfOutDoors) {
74+
this.numOfOutDoors = numOfOutDoors;
75+
return this;
76+
}
77+
78+
public HouseBuilder areaOfPorch(int areaOfPorch) {
79+
this.areaOfPorch = areaOfPorch;
80+
return this;
81+
}
82+
83+
public House build() {
84+
House house = new House(this);
85+
return house;
86+
}
87+
88+
}
89+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.bilgeadam.boost.java.lesson032.factory;
2+
3+
public class CommercialPlan extends Plan {
4+
5+
@Override
6+
void getRate() {
7+
8+
rate = 7.50;
9+
}
10+
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.bilgeadam.boost.java.lesson032.factory;
2+
3+
public class DomesticPlan extends Plan {
4+
5+
@Override
6+
void getRate() {
7+
8+
rate = 3.50;
9+
}
10+
11+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.bilgeadam.boost.java.lesson032.factory;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
7+
public class GenerateBill {
8+
9+
public static void main(String[] args) throws IOException {
10+
11+
PlanFactory planFactory = new PlanFactory();
12+
System.out.println("Enter the name of plan : ");
13+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
14+
15+
16+
String planName = br.readLine();
17+
System.out.println("Enter the number of units : ");
18+
int units =Integer.parseInt( br.readLine()) ;
19+
20+
Plan p = planFactory.getPlan(planName);
21+
System.out.println("Bill amount for "+planName+" of "+units+" units is : ");
22+
p.getRate();
23+
p.calculateBill(units);
24+
25+
}
26+
27+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.bilgeadam.boost.java.lesson032.factory;
2+
3+
public class InstituionalPlan extends Plan {
4+
5+
@Override
6+
void getRate() {
7+
8+
rate = 5.50;
9+
}
10+
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.bilgeadam.boost.java.lesson032.factory;
2+
3+
public abstract class Plan {
4+
5+
double rate;
6+
abstract void getRate();
7+
8+
public void calculateBill(int units) {
9+
System.out.println(units*rate);
10+
}
11+
12+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.bilgeadam.boost.java.lesson032.factory;
2+
3+
public class PlanFactory {
4+
5+
public Plan getPlan(String planType) {
6+
if(planType == null) {
7+
return null;
8+
}
9+
if (planType.equalsIgnoreCase("Domestic")) {
10+
return new DomesticPlan();
11+
}
12+
else if (planType.equalsIgnoreCase("Commercial")) {
13+
return new CommercialPlan();
14+
}
15+
else if (planType.equalsIgnoreCase("Instituional")) {
16+
return new InstituionalPlan();
17+
}
18+
return null;
19+
}
20+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.bilgeadam.boost.java.lesson032.singleton;
2+
3+
import java.util.logging.Logger;
4+
5+
public class Commons {
6+
7+
private static Commons instance = null ;
8+
private Logger logger;
9+
private String something;
10+
11+
private Commons() { // ilk adım. sınıfın yapıcı yöntemi private olmalı.
12+
super(); // Bu şekilde başka bir yerden sınıf örneği oluşturulamaz.
13+
this.logger= Logger.getLogger("bla bla");
14+
this.something = "";
15+
}
16+
17+
public static Commons getInstance() { // ikinci adım: bir static metod üzerinden sınıf örneğine erişebilmek gerekli.
18+
if(Commons.instance==null) { // lazy initialization
19+
Commons.instance = new Commons();
20+
}
21+
return Commons.instance;
22+
}
23+
24+
public Logger getLogger() {
25+
return this.logger;
26+
}
27+
public String getSomething() {
28+
return this.something;
29+
}
30+
public void setSomething(String something) {
31+
this.something=something;
32+
}
33+
34+
}

0 commit comments

Comments
 (0)