У меня есть класс Event, реализуемый Concert, Play и Meeting.Я нахожусь в отдельном классе Ticket для продажи на соответствующее «событие».В Ticket мне нужно получить getPrice (), который начинается с 10 и должен быть умножен на ценовой коэффициент, когда забронировано событие (которое имеет разные ценовые факторы).
Я попытался просто вызвать статическую ЦЕНУ, котораябазовая цена за билет и называется event.getPriceFactor (), которая возвращает ноль, и я, очевидно, могу создать экземпляр этого события в 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;
}
Я ожидаю событие Ticket.PRICE (10.) *.getPriceFactor () (1.0) возвращает 10, но возвращает ноль.