You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
3.2 KiB
96 lines
3.2 KiB
package hs.fulda.de.ci.exam.project;
|
|
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
public class Itinerary {
|
|
|
|
private Airport start_airport;
|
|
private Airport final_airport;
|
|
private Date creationDate;
|
|
private FlightReservationRepository flightReservationRepository;
|
|
|
|
public Itinerary(Airport start_airport, Airport final_airport, Date creationDate) {
|
|
this.start_airport = start_airport;
|
|
this.final_airport = final_airport;
|
|
this.creationDate = creationDate;
|
|
}
|
|
|
|
public float makeDiscount(float fare, float discountRate){
|
|
fare = fare - (fare * discountRate/100);
|
|
return fare;
|
|
}
|
|
|
|
public boolean makePayment(FlightReservation flightReservation, String transactionType, Customer customer, float fare){
|
|
if(customer.getItineraries().size() >= 2) {
|
|
fare = makeDiscount(fare, 10);
|
|
if (transactionType == "Credit") {
|
|
fare = makeDiscount(fare, 15);
|
|
System.out.println("Your discount rate is 15%. The total amount of: " + fare + "Euro");
|
|
return true;
|
|
} else if (transactionType == "Cash" || transactionType == "Check") {
|
|
System.out.println("Your discount rate is 10%. The total amount of: " + fare + "Euro");
|
|
return true;
|
|
}
|
|
}
|
|
flightReservation.setStatus(ReservationStatus.Pending);
|
|
return false;
|
|
}
|
|
|
|
public FlightReservation makeReservation(FlightSeat flightSeat, Passenger passenger){
|
|
HashMap<Passenger, FlightSeat> seatHashMap= new HashMap<Passenger, FlightSeat>();
|
|
seatHashMap.put(passenger, flightSeat);
|
|
validatePassengerDetails(passenger);
|
|
FlightReservation flight = new FlightReservation();
|
|
flight.setSeatMap(seatHashMap);
|
|
flight.setStatus(ReservationStatus.Requested);
|
|
return flight;
|
|
}
|
|
|
|
public Airport getFinal_airport() {
|
|
return final_airport;
|
|
}
|
|
|
|
public Airport getStart_airport() {
|
|
return start_airport;
|
|
}
|
|
|
|
public Date getCreationDate() {
|
|
return creationDate;
|
|
}
|
|
|
|
public void setCreationDate(Date creationDate) {
|
|
this.creationDate = creationDate;
|
|
}
|
|
|
|
public void setFinal_airport(Airport final_airport) {
|
|
this.final_airport = final_airport;
|
|
}
|
|
|
|
public void setStart_airport(Airport start_airport) {
|
|
this.start_airport = start_airport;
|
|
}
|
|
|
|
public void validateStartAirport() {
|
|
if(this.start_airport.getName().isBlank())
|
|
throw new RuntimeException(("Starting Airport Cannot be null or empty"));
|
|
}
|
|
|
|
public void validateFinalAirport() {
|
|
if(this.final_airport.getName().isBlank())
|
|
throw new RuntimeException(("Destination Airport Cannot be null or empty"));
|
|
}
|
|
public void validateCreationDate() {
|
|
if(this.creationDate.equals(null))
|
|
throw new RuntimeException(("Creation Date should not be null or empty"));
|
|
}
|
|
|
|
public void validatePassengerDetails(Passenger passenger){
|
|
passenger.validateName();
|
|
passenger.validatePassportNumber();
|
|
passenger.validateDate();
|
|
}
|
|
|
|
|
|
}
|
|
|