JAVA每日学习
package com.learn.study;
import java.util.Scanner;
public class Service {
public static void main(String[] args){
Scanner s1 = new Scanner(System.in);
String name;
name=s1.nextLine();
Coffee S1 = new Coffee();
CoffeeFactary S2 = new CoffeeFactary();
S1 = S2.getCoffee(name);
System.out.println(S1.getCoffee());
}
}
package com.learn.study;
public class LatteCoffee extends Coffee{
@Override
public String getCoffee() {
return "拿铁咖啡";package com.learn.study;
public class CoffeeStore {
public Coffee getCoffee(String name){
Coffee s2 = null;
CoffeeFactary s1 = new CoffeeFactary();
s2=s1.getCoffee(name);
return s2;
}
}
}
}
package com.learn.study;
public class CoffeeStore {
public Coffee getCoffee(String name){
Coffee s2 = null;
CoffeeFactary s1 = new CoffeeFactary();
s2=s1.getCoffee(name);
return s2;
}
}
package com.learn.study;
public class CoffeeFactary {
public Coffee getCoffee(String name){
Coffee coffee = null;
if(name.equals("拿铁")){
coffee = new LatteCoffee();
}
else if(name.equals("美式")){
coffee = new AmericaCoffee();
}
return coffee;
}
}
package com.learn.study;
public class Coffee {
public String getCoffee(){
return "咖啡";
}
}
package com.learn.study;
public class AmericaCoffee extends Coffee{
@Override
public String getCoffee() {
return "美式咖啡";
}
}