亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從我的“活動”中獲取價格因素來計算我的門票價格

如何從我的“活動”中獲取價格因素來計算我的門票價格

RISEBY 2023-08-16 16:39:23
我有一個 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。
查看完整描述

1 回答

?
智慧大石

TA貢獻1946條經驗 獲得超3個贊

看起來您從未將事件分配給票證構造函數中的票證屬性,因此為空值并且無法返回價格因素。嘗試分配它并看看是否有效



查看完整回答
反對 回復 2023-08-16
  • 1 回答
  • 0 關注
  • 125 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號