在学习简单工程方法,遇到了一点疑问,创建测试类中的第4行代码是什么变量的创建格式,为什么是 “类型 变量名=方法名.方法名()”,等待指点
double stu1 = studentCalculator.studentCalculator(15);
想请教一下这是哪一块的内容,感谢
public class Student implements MovieTicket {
public double studentCalculator(double price){
return price * 0.8;
}
public double vipCalculator(double price){
throw new UnsupportedOperationException();
}
public double childCalculator(double price){
throw new UnsupportedOperationException();
}
public double adultCalculator(double price){
throw new UnsupportedOperationException();
}
}
public class TicketFactory {
public static MovieTicket createTicket(String operator){
switch(operator){
case "student":
return new Student();
case "vip":
return new Vip();
case "child":
return new Child();
case "adult":
return new Adult();
default:
throw new IllegalArgumentException("Invalid operator: " +operator);
}
}
}
public class Test {
public static void main(String[] args){
MovieTicket studentCalculator = TicketFactory.createTicket("student");
double stu1 = studentCalculator.studentCalculator(15);
System.out.println("\n学生票价格:"+stu1);
}
}