Last active
December 24, 2015 00:09
-
-
Save CaglarGonul/6715062 to your computer and use it in GitHub Desktop.
Beverage class which holds the abstract information of a beverage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.v1; | |
import java.util.ArrayList; | |
import java.util.List; | |
public abstract class Beverage { | |
String description ; | |
List<ICondiment> condiments = new ArrayList<ICondiment>(); | |
public void addCondiment(ICondiment condiment){ | |
condiments.add(condiment); | |
} | |
public int getCondimentCost(){ | |
int cost = 0; | |
for (ICondiment condCB : condiments) { | |
cost += condCB.cost(); | |
} | |
return cost; | |
} | |
public String getDescription() { | |
return description; | |
} | |
public abstract int cost(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.v1; | |
public class HouseBlend extends Beverage { | |
public HouseBlend() { | |
super(); | |
this.description = "This is house blend..."; | |
} | |
@Override | |
public int cost() { | |
return 6 + getCondimentCost(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.v1; | |
public class DarkRoast extends Beverage { | |
public DarkRoast() { | |
super(); | |
this.description = "This is dark roast..."; | |
} | |
@Override | |
public int cost() { | |
return 7 + getCondimentCost(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.v1; | |
public class Decaf extends Beverage { | |
public Decaf() { | |
super(); | |
this.description = "This is decaf. It is decafed..."; | |
} | |
@Override | |
public int cost() { | |
return 8 + getCondimentCost(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.v1; | |
public class Espresso extends Beverage { | |
public Espresso() { | |
super(); | |
this.description = "This is espresso. It is the most expensive..."; | |
} | |
@Override | |
public int cost() { | |
return 10 + getCondimentCost(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.v1; | |
public interface ICondiment { | |
int cost(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.v1.condiments; | |
import com.v1.ICondiment; | |
public class Milk implements ICondiment { | |
@Override | |
public int cost() { | |
return 1; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.v1.condiments; | |
import com.v1.ICondiment; | |
public class Mocha implements ICondiment{ | |
@Override | |
public int cost() { | |
return 3; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.v1.condiments; | |
import com.v1.ICondiment; | |
public class Soy implements ICondiment { | |
@Override | |
public int cost() { | |
return 2; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.v1; | |
import com.v1.condiments.Milk; | |
import com.v1.condiments.Mocha; | |
public class Impl { | |
public static void main(String[] args) { | |
HouseBlend hb = new HouseBlend(); | |
System.out.println("Add three unit of milk and mocha."); | |
hb.addCondiment(new Milk()); | |
hb.addCondiment(new Milk()); | |
hb.addCondiment(new Milk()); | |
hb.addCondiment(new Mocha()); | |
System.out.println("House Blend : " + hb.getDescription() + " Cost : " + hb.cost() ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment