我有一個 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
提交
取消