我有一个 Event 类,它是由 Concert、Play 和 Meeting 实现的。我处于单独的门票类别中,出售给相应的“活动”。在 Ticket 中,我需要 getPrice(),它从 10 开始,并且在预订活动(具有不同价格因素)时需要乘以价格因素。我尝试简单地调用一个静态 PRICE(即门票的基本价格)并调用 event.getPriceFactor() ,它返回 null,我显然可以在 Ticket 中实例化此事件。public abstract class Event { private String description; protected int ticketsSold; private int eventId; private double priceFactor; private static int counter = 1; private static final int CAPACITY = 5; private ObservableList<Ticket> tickets = FXCollections.observableArrayList(); /** * Stores the description and price factor and assigns a unique id to the event. * The constructor also allocates the array tickets. * * @param description a description of this Play * @param priceFactor the price factor for this Play * */ public Event(String description, double priceFactor) { this.description = description; this.priceFactor = priceFactor; this.eventId = computeSerialNumber(); } /** * Receives the description and stores that and a price factor of 1.0. Besides, * it assigns a unique id to the event. The constructor also allocates the array * tickets. * * @param description a description of this Play * */ public Event(String description) { this(description, 1.0); } public double getPriceFactor() { return priceFactor;}------------------------------------------------------------------------------public class Ticket { private static int counter = 1; private int serialNumber; private double price; private static double PRICE = 10.0; private Event event;我期待 Ticket.PRICE (10.) * event.getPriceFactor() (1.0) 返回 10,但它返回 null。
添加回答
举报
0/150
提交
取消