-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSports.java
67 lines (60 loc) · 2.01 KB
/
Sports.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* Handles tickets to sporting events
*/
public class Sports extends Ticket {
// Indicates if the ticket is for an on-field spot
private boolean onField;
// Stores the type of sport
private String sport;
// Constructor with seat information
public Sports(String venue, char row, int seat, String sectionRow, boolean onField, String sport) {
super(venue, row, seat, sectionRow);
this.onField = onField;
this.sport = sport;
}
// Constructor without seat information (for on-field tickets)
public Sports(String venue, boolean onField, String sport) {
super(venue);
this.onField = onField;
this.sport = sport;
}
@Override
public void adjustPrice() {
double tempPrice = this.getPrice();
if (onField) {
tempPrice *= 3; // Increase for on-field tickets
}
this.setPrice(tempPrice);
}
// Returns the type of sport
public String getSport() {
return sport;
}
// Returns if the ticket is for an on-field spot
public boolean isOnField() {
return onField;
}
@Override
public void getTicket() {
System.out.println("Price: " + this.getPrice());
System.out.println("Venue: " + this.getVenue());
if (!onField) {
System.out.println("Seat: " + this.getSectionRow());
} else {
System.out.println("On-Field Ticket");
}
System.out.println("Sport Type: " + sport);
}
@Override
public String getTicketDetails() {
StringBuilder details = new StringBuilder(super.getTicketDetails());
details.append("Event Type: Sports\n");
if (onField) {
details.append("On-Field Ticket\n");
} else {
details.append("Seat: ").append(this.getSectionRow()).append("\n");
}
details.append("Sport Type: ").append(sport).append("\n");
return details.toString();
}
}