Question: Answer the following sections a,b and c Name two (2) class attributes that will exist on an EconomyClassTicket object. [1 mark] __________________________________________________________________ Write the java

 Answer the following sections a,b and c Name two (2) class

Answer the following sections a,b and c

  1. Name two (2) class attributes that will exist on an EconomyClassTicket object. [1 mark]

__________________________________________________________________

  1. Write the java code for the constructor FirstClassTicket(TrainService _theService, TicketType _theTicketType, Date _travelDate) in the FirstClassTicket class. [7 marks]

This constructor will accept three objects as arguments containing the train service, ticket type and travel date for this ticket. Use set methods and the super constructor where appropriate.

The constructor will ensure that the seat number is issued based on the next available first class seat. A static private method named assignNextAvailSeat() on the Booking class (not shown) will do this for a particular service and date as follows: Booking.assignNextAvailSeat(_theService, _travelDate);

The constructor should ensure that the current date is stored for the dateIssued and the expiry date is 7 days later than the issue date. There are existing private methods in the class named assignIssueDate() that will set the Date object, dateIssued to be equal to todays date and there is an existing method assignExpiryDate that will set the expiry date for the ticket in dateExpiry. These are called in the constructor defined in the Ticket class.

The constructor in Ticket is as follows:

public Ticket (TrainService _theService, TicketType _theTicketType) {

this.setService(_theService);

this.setTicketType(_theTicketType);

assignIssueDate ();

assignExpiryDate();

c)

  1. The method assignNextAvailSeat() in the Booking class (not shown in the UML class diagram) uses a static class attribute nextAvailSeatNumber to get the next available seatNumber for a particular Service, declared as follows:

private static int nextAvailSeatNumber = 1;

The method assignNextAvailSeat from the Booking class is as follows:

private void assignNextAvailSeat(){

// get the next available seat number

String numString ="";

int seatNum = nextAvailSeatNumber++; // get next seat num // convert num to a string object

if (seatNum

numString = "SEAT" + String.valueOf(seatNum);

else

numString = "NO SEATS AVAILABLE"

return numString;

}

Explain where a static class attribute is stored and the consequences of that. [1 mark]

Ticket date Expiry: Date datelssued: Date service: Train Service ticketPrice: double ticketType: TicketType + getService(): TrainService + getTicketPrice(): double + issue Concession Ticket(): double + issue FullPrice Ticket(): double + issue Ticket(): double + print(): void setService (TrainService): void setTicketTypeTicketType): void + Ticket(TrainService, TicketType) + toString(): String Economy ClassTicket Economy ClassTicket(Train Service, TicketTyp + getTicketPrice(): double + toString(): String FirstClassTicket seatNumber: String SURCHARGE: double = 0.25 travelDate: Date + FirstClassTicket(TrainService, TicketType, Date + getTicketPrice(): double setSeatNumber(String): void setTravelDate(Date): void + toString(): String

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!