File tree
Expand file treeCollapse file tree3 files changed
+68
-12
lines changed pattern/src/com/premaseem/icecreams
Expand file treeCollapse file tree3 files changed
+68
-12
lines changed Original file line number | Diff line number | Diff line change |
---|
|
5 | 5 | @title: Design Patterns with Java 9
|
6 | 6 | @link: https://premaseem.wordpress.com/category/computers/design-patterns/
|
7 | 7 | */
|
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; |
12 | 18 |
|
13 |
| -@Override |
14 | 19 | 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(); |
16 | 36 | }
|
17 | 37 | }
|
Original file line number | Diff line number | Diff line change |
---|
|
| 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 number | Diff line number | Diff line change |
---|
|
5 | 5 | @title: Design Patterns with Java 9
|
6 | 6 | @link: https://premaseem.wordpress.com/category/computers/design-patterns/
|
7 | 7 | */
|
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; |
12 | 18 |
|
13 |
| -@Override |
14 | 19 | 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(); |
16 | 36 | }
|
17 | 37 | }
|
You can’t perform that action at this time.
0 commit comments