ahmedanwaraliitilab3
Version:
115 lines (100 loc) • 2.9 kB
JavaScript
class FlightTicket {
static usersTickets = []
constructor(obj = {seatNum: 0, flightNum: 0, departureAirport: "", arrivalAirport: "", travellingDate: ""}) {
this.
this.
this.
this.
this.
FlightTicket.usersTickets.push(obj)
}
set seatNumber(seatNum) {
if (!isNaN(seatNum)) {
this.
} else {
throw new TypeError("Value must be a NUMBER")
}
}
set flightNum(flightNum) {
if (!isNaN(flightNum)) {
this.
} else {
throw new TypeError("Value must be a NUMBER")
}
}
set departureAirport(departureAirport) {
if (typeof departureAirport === "string") {
this.
} else {
throw new TypeError("Value must be a String")
}
}
set arrivalAirport(arrivalAirport) {
if (typeof arrivalAirport === "string") {
this.
} else {
throw new TypeError("Value must be a String")
}
}
set travellingDate(travellingDate) {
if (typeof travellingDate === "string") {
this.
} else {
throw new TypeError("Value must be a String")
}
}
get seatNumber() {
return this.
}
get flightNum() {
return this.
}
get departureAirport() {
return this.
}
get arrivalAirport() {
return this.
}
get travellingDate() {
return this.
}
displayTicket() {
let ticket = {
seatNumber: this.
flightNumber: this.
departureAirport: this.
arrivalAirport: this.
travellingDate: this.
}
console.log(ticket)
}
static getAllTickets() {
return FlightTicket.usersTickets
}
}
// let ticket1 = {
// seatNum : 5,
// flightNum : 6,
// departureAirport : "Alexandria",
// arrivalAirport : "Cairo",
// travellingDate : "15/6/2022"
// }
//
// let ticket2 = {
// seatNum : 1,
// flightNum : 2,
// departureAirport : "San Francisco",
// arrivalAirport : "New york",
// travellingDate : "26/8/2021"
// }
//
// let user1 = new FlightTicket(ticket1)
// let user2 = new FlightTicket(ticket2)
// user1.displayTicket()
// user2.displayTicket()
module.exports = FlightTicket;