File tree

3 files changed

+68
-12
lines changed

3 files changed

+68
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,33 @@
55
@title: Design Patterns with Java 9
66
@link: https://premaseem.wordpress.com/category/computers/design-patterns/
77
*/
8-
public class ChocolateIceCream {
9-
String brand = "un branded";
10-
Integer cost = 3;
11-
Integer calories = 200;
8+
public class ChocolateIceCream implements IceCream {
9+
10+
public ChocolateIceCream (Integer cost, Integer calories){
11+
this.cost =cost;
12+
this.calories =calories;
13+
}
14+
15+
String brand = "";
16+
Integer cost = 0;
17+
Integer calories = 0;
1218

13-
@Override
1419
public String toString () {
15-
return this.getClass().getName() + " with " + calories + " and cost: $" + cost;
20+
return this.getClass().getSimpleName() + " with Calories: " + getCalories() + " and cost: $" + getCost();
21+
}
22+
23+
@Override
24+
public Integer getCalories () {
25+
return calories;
26+
}
27+
28+
@Override
29+
public Integer getCost () {
30+
return cost;
31+
}
32+
33+
@Override
34+
public String getIceCreamName () {
35+
return this.getClass().getSimpleName();
1636
}
1737
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.premaseem.icecreams;
2+
3+
/*
4+
@author: Aseem Jain
5+
@title: Design Patterns with Java 9
6+
@link: https://premaseem.wordpress.com/category/computers/design-patterns/
7+
*/
8+
public interface IceCream {
9+
10+
Integer getCalories();
11+
Integer getCost();
12+
String getIceCreamName();
13+
14+
15+
16+
}
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,33 @@
55
@title: Design Patterns with Java 9
66
@link: https://premaseem.wordpress.com/category/computers/design-patterns/
77
*/
8-
public class StrawberryIceCream {
9-
String brand = "un branded";
10-
Integer cost = 2;
11-
Integer calories = 200;
8+
public class StrawberryIceCream implements IceCream {
9+
10+
public StrawberryIceCream(Integer cost,Integer calories){
11+
this.cost =cost;
12+
this.calories =calories;
13+
}
14+
15+
String brand = "";
16+
Integer cost = 0;
17+
Integer calories = 0;
1218

13-
@Override
1419
public String toString () {
15-
return this.getClass().getSimpleName() + " with Calories: " + calories + " and cost: $" + cost;
20+
return this.getClass().getSimpleName() + " with Calories: " + getCalories() + " and cost: $" + getCost();
21+
}
22+
23+
@Override
24+
public Integer getCalories () {
25+
return calories;
26+
}
27+
28+
@Override
29+
public Integer getCost () {
30+
return cost;
31+
}
32+
33+
@Override
34+
public String getIceCreamName () {
35+
return this.getClass().getSimpleName();
1636
}
1737
}

0 commit comments

Comments
 (0)