java如何从我的“活动”中获取价格因子来计算我的门票价格
我有一个活动课程,通过音乐会、戏剧和会议来实施。我在一个单独的票舱里,为一个单独的“活动”出售在Ticket中,我需要获取price(),它从10开始,在预订活动(具有不同的价格因素)时需要乘以价格因素
我试着简单地调用一个静态价格,这是一张票的基本价格,并调用事件。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;
/**
* Creates a ticket for an event. An exception is thrown if there is no space.
*
* @param event the event for which the ticket is being created.
* @throws NoSpaceException
*/
public Ticket(Event event) throws NoSpaceException, UnsupportedOperationException {
event.addTicket(this);
this.serialNumber = computeSerialNumber();
}
/**
* Returns the price of the ticket
*
* @return ticket price
*/
``public double getPrice() {
price = Ticket.PRICE * event.getPriceFactor();
return price;
}
我在等票。价格(10)*事件getPriceFactor()(1.0)返回10,但返回null
共 (0) 个答案