Instantly share code, notes, and snippets.
Created
November 16, 2015 14:05
Star
You must be signed in to star a gist
This file contains 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 Lesson6.ElectronicMenu; | |
/** | |
* Created by Алекс on 16.11.2015. | |
*/ | |
public class Americano extends Coffee { | |
public Americano () { | |
} | |
@Override | |
public Drink createDrink () { | |
Americano a = new Americano(); | |
a.setName("Americano"); | |
a.setCoffeCount(3); | |
a.setWater(220); | |
a.setSugar(2); | |
a.setPrice(a.getCoffeCount()*getCoffePrice()+a.getSugar()*getSugerPrice()); | |
return a; | |
} | |
@Override | |
public void printIngredients () { | |
super.printIngredients(); | |
} | |
} |
This file contains 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 Lesson6.ElectronicMenu; | |
public class BlackCoffee extends Coffee { | |
public BlackCoffee () { | |
} | |
@Override | |
public Drink createDrink () { | |
BlackCoffee bc = new BlackCoffee(); | |
bc.setName("Espresso"); | |
bc.setCoffeCount(2); | |
bc.setWater(100); | |
bc.setSugar(2); | |
bc.setPrice(bc.getCoffeCount()*getCoffePrice()+bc.getSugar()*getSugerPrice()); | |
return bc; | |
} | |
@Override | |
public void printIngredients () { | |
super.printIngredients(); | |
} | |
} |
This file contains 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 Lesson6.ElectronicMenu; | |
/** | |
* Created by Алекс on 16.11.2015. | |
*/ | |
public class BlackTea extends Tea { | |
@Override | |
public Drink createDrink() { | |
BlackTea blackTea= new BlackTea(); | |
blackTea.setName("Black Tea"); | |
blackTea.setKindTea(KindTea.BLACK); | |
blackTea.setSugar(2); | |
blackTea.setTeaCount(3); | |
blackTea.setPrice(blackTea.getTeaCount()*getTeaPrice()+blackTea.getSugar()*getSugerPrice()); | |
return blackTea; | |
} | |
@Override | |
public void printIngredients () { | |
super.printIngredients(); | |
} | |
} |
This file contains 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 Lesson6.ElectronicMenu; | |
/** | |
* Created by Алекс on 16.11.2015. | |
*/ | |
public class Cappuchino extends Coffee { | |
public Cappuchino () { | |
} | |
@Override | |
public Drink createDrink() { | |
Cappuchino cap = new Cappuchino(); | |
cap.setName("Cappuchino"); | |
cap.setCoffeCount(1); | |
cap.setWater(100); | |
cap.setSugar(2); | |
cap.setMilkCount(50); | |
cap.setIndexPreparing(1.2); | |
cap.setPrice(cap.getCoffeCount()*getCoffePrice()+cap.getSugar()*getSugerPrice()+cap.getMilkCount()*getMilkPrice()); | |
return cap; | |
} | |
@Override | |
public void printIngredients () { | |
super.printIngredients(); | |
} | |
} |
This file contains 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 Lesson6.ElectronicMenu; | |
public abstract class Coffee extends Drink { | |
private int coffeCount; | |
private double coffePrice = 1; | |
private int chocholateCount; | |
private double chocolatePrice = 0.1; | |
public Coffee () { | |
} | |
public int getCoffeCount() { | |
return coffeCount; | |
} | |
public void setCoffeCount(int coffeCount) { | |
this.coffeCount = coffeCount; | |
} | |
public double getCoffePrice() { | |
return coffePrice; | |
} | |
public int getChocholateCount() { | |
return chocholateCount; | |
} | |
public void setChocholateCount(int chocholateCount) { | |
this.chocholateCount = chocholateCount; | |
} | |
public double getChocolatePrice() { | |
return chocolatePrice; | |
} | |
@Override | |
public void printIngredients () { | |
System.out.printf( "%s%5d%s%n", "Coffee:", getCoffeCount(), " mg"); | |
System.out.printf("%37s%7s%s%n","Water: ", getWater(), " ml"); | |
if (getMilkCount()>0) { | |
System.out.printf("%36s%7s%s%n", "Milk: ", getMilkCount()," ml"); | |
} | |
if (getChocholateCount()>0) { | |
System.out.printf("%41s%1s%s%n", "Chocolate: ", getChocholateCount(), " mg"); | |
} | |
} | |
} |
This file contains 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 Lesson6.ElectronicMenu; | |
/** | |
* Created by Алекс on 16.11.2015. | |
*/ | |
public class Demo { | |
public static void main(String[] args) { | |
Menu menu = new Menu(); | |
menu.printMenu(menu.drinks); | |
} | |
} |
This file contains 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 Lesson6.ElectronicMenu; | |
/** | |
* Created by Алекс on 16.11.2015. | |
*/ | |
public abstract class Drink extends Food { | |
private int waterCount; | |
private int milkCount; | |
private int sugar; | |
private double milkPrice = 0.05; | |
private double sugerPrice = 0.1; | |
public Drink () { | |
} | |
public int getWater() { | |
return waterCount; | |
} | |
public void setWater(int water) { | |
this.waterCount = water; | |
} | |
public int getMilkCount() { | |
return milkCount; | |
} | |
public void setMilkCount(int milkCount) { | |
this.milkCount = milkCount; | |
} | |
public int getSugar() { | |
return sugar; | |
} | |
public void setSugar(int sugar) { | |
this.sugar = sugar; | |
} | |
public double getMilkPrice() { | |
return milkPrice; | |
} | |
public double getSugerPrice() { | |
return sugerPrice; | |
} | |
public abstract Drink createDrink(); | |
} |
This file contains 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 Lesson6.ElectronicMenu; | |
/** | |
* Created by Алекс on 16.11.2015. | |
*/ | |
public abstract class Food { | |
private String name; | |
private double price; | |
private double indexPreparing=1; | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public double getPrice() { | |
return price; | |
} | |
public void setPrice(double price) { | |
this.price = price*indexPreparing; | |
} | |
public double getIndexPreparing() { | |
return indexPreparing; | |
} | |
public void setIndexPreparing(double indexPreparing) { | |
this.indexPreparing = indexPreparing; | |
} | |
public abstract void printIngredients (); | |
} |
This file contains 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 Lesson6.ElectronicMenu; | |
/** | |
* Created by Алекс on 16.11.2015. | |
*/ | |
public class GreenTea extends Tea { | |
public GreenTea () { | |
} | |
@Override | |
public Drink createDrink() { | |
GreenTea gt= new GreenTea(); | |
gt.setName("Green Tea"); | |
gt.setKindTea(KindTea.GREEN); | |
gt.setSugar(2); | |
gt.setTeaCount(3); | |
gt.setPrice(gt.getTeaCount()*getTeaPrice()+gt.getSugar()*getSugerPrice()); | |
return gt; | |
} | |
@Override | |
public void printIngredients () { | |
super.printIngredients(); | |
} | |
} |
This file contains 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 Lesson6.ElectronicMenu; | |
/** | |
* Created by Алекс on 16.11.2015. | |
*/ | |
public enum KindTea { | |
BLACK, GREEN, BERGAMOT; | |
} |
This file contains 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 Lesson6.ElectronicMenu; | |
/** | |
* Created by Алекс on 16.11.2015. | |
*/ | |
public class Menu { | |
public Food [] drinks = new Drink[10]; | |
public Menu () { | |
createMenu(); | |
} | |
public void createMenu () { | |
Cappuchino cap = new Cappuchino(); | |
addToMenu(cap.createDrink()); | |
BlackCoffee bc = new BlackCoffee(); | |
addToMenu(bc.createDrink()); | |
Americano amer = new Americano(); | |
addToMenu(amer.createDrink()); | |
Moccacino moc = new Moccacino(); | |
addToMenu(moc.createDrink()); | |
BlackTea blackTea = new BlackTea(); | |
addToMenu(blackTea.createDrink()); | |
GreenTea greenTea = new GreenTea(); | |
addToMenu(greenTea.createDrink()); | |
} | |
public void printMenu (Food[]dishes) { | |
System.out.printf("%6s%15s%20s%n", "Drink", "Price", "Ingridients"); | |
for (int i = 0; i< dishes.length; i++) { | |
if (dishes[i]==null) { | |
return; | |
} else { | |
System.out.println("-------------------------------------------------"); | |
System.out.printf("%-15s%s", dishes[i].getName()," "); | |
System.out.printf("%.1f%-10s", dishes[i].getPrice(),"$" ); | |
dishes[i].printIngredients(); | |
} | |
} | |
} | |
private void addToMenu (Food food) { | |
for (int i = 0; i< drinks.length; i++) { | |
if (drinks[i]==null) { | |
drinks[i]=food; | |
return; | |
} | |
} | |
} | |
} |
This file contains 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 Lesson6.ElectronicMenu; | |
/** | |
* Created by Алекс on 16.11.2015. | |
*/ | |
public class Moccacino extends Coffee { | |
public Moccacino () { | |
} | |
@Override | |
public Drink createDrink () { | |
Moccacino m = new Moccacino(); | |
m.setName("Moccacino"); | |
m.setChocholateCount(2); | |
m.setCoffeCount(2); | |
m.setChocholateCount(2); | |
m.setWater(150); | |
m.setSugar(1); | |
m.setMilkCount(50); | |
m.setIndexPreparing(1.3); | |
m.setPrice(m.getCoffeCount()*getCoffePrice()+m.getSugar()*getSugerPrice()+m.getChocholateCount()*getChocolatePrice()+m.getMilkCount()*getMilkPrice()); | |
return m; | |
} | |
@Override | |
public void printIngredients () { | |
super.printIngredients(); | |
} | |
} | |
This file contains 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 Lesson6.ElectronicMenu; | |
/** | |
* Created by Алекс on 16.11.2015. | |
*/ | |
public abstract class Tea extends Drink { | |
private KindTea kindTea; | |
private int teaCount; | |
private double teaPrice = 0.3; | |
public KindTea getKindTea() { | |
return kindTea; | |
} | |
public void setKindTea(KindTea kindTea) { | |
this.kindTea = kindTea; | |
} | |
public int getTeaCount() { | |
return teaCount; | |
} | |
public double getTeaPrice() { | |
return teaPrice; | |
} | |
public void setTeaCount(int teaCount) { | |
this.teaCount = teaCount; | |
} | |
public void printIngredients () { | |
System.out.printf( "%s%5s%2s%s%n", getKindTea(), "tea:", getTeaCount()," mg"); | |
System.out.printf("%37s%7s%s%n","Water: ", 250, " ml"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment