Commit a2376041 authored by s7_bekman_i's avatar s7_bekman_i
Browse files

Commit

parent ee4ad081
Pipeline #836 failed with stages
No preview for this file type
No preview for this file type
......@@ -17,23 +17,17 @@ import services.AirportService;
* @author Ieva Bekmane 3ITB
*/
public class Main {
public static void main(String[] args) {
AirportService services = new AirportService();
/*====================================PASSENGERS======================================*/
/*Passenger p1 = new Passenger("Janis", "Liepins", "AS12345", Nationality.LATVIAN, IdenType.PASSPORT, true, "No extra needs");
Passenger p2 = new Passenger("Liene", "Kalnina", "GH12345", Nationality.ESTONIAN, IdenType.IDCARD, false, "No extra needs");
VipPassenger vip1 = new VipPassenger("Baiba", "Jauka", "ER12345", Nationality.ITALIAN, IdenType.PASSPORT, true, "No extra needs", "ZX12345");
VipPassenger vip2 = new VipPassenger("Zane", "Berzina", "LM12345", Nationality.LATVIAN, IdenType.PASSPORT, true, "No extra needs", "BN12345");
AirportService.allPassenger.add(p1);
AirportService.allPassenger.add(p2);
AirportService.allPassenger.add(vip1);
AirportService.allPassenger.add(vip2);*/
services.addNewPassenger("Janis", "Liepins", Nationality.LATVIAN, IdenType.PASSPORT, "AS12345", true);
services.addNewPassenger("Katrina", "Zarina", Nationality.LATVIAN, IdenType.IDCARD, "DF12345", false);
services.addNewPassenger("Baiba", "Jauka", Nationality.ESTONIAN, IdenType.PASSPORT, "IS43251", false);
services.addNewVipPassenger("Juris", "Pakalns", Nationality.ITALIAN, IdenType.IDCARD, "DE12345", true, "VZ12345");
services.addNewVipPassenger("Karlis", "Berzins", Nationality.ITALIAN, IdenType.PASSPORT, "NJ12345", true, "FD90324");
System.out.println("---------------------Passengers-------------------------");
for(Passenger p : AirportService.allPassenger) {
......@@ -43,20 +37,17 @@ public class Main {
System.out.println("Delete passenger by name and surname: " + services.deletePassengerByNameAndSurname("Baiba", "Jauka"));
System.out.println("Delete passenger by number: " + services.deletePassengerByIdentNr("AS12345"));
System.out.println("Delete VipPassenger by vipNr: " + services.deleteVipPassengerByVipNr(2));
System.out.println("Delete VipPassenger by vipNr: " + services.deleteVipPassengerByVipNr(1));
System.out.println("---------------Passengers after delete------------------");
for(Passenger p : AirportService.allPassenger) {
System.out.println(p);
}
System.out.println("--------------------------------------------------------");
/* =======================AIRPORTS======================*/
Airport a1 = new Airport(2000, AirportName.BARSELONA);
Airport a2 = new Airport(3000, AirportName.OSLO);
AirportService.allAirports.add(a1);
AirportService.allAirports.add(a2);
services.addNewAirport(AirportName.OSLO, 3214);
services.addNewAirport(AirportName.BARSELONA, -2451);
services.addNewAirport(AirportName.RIGA, 4000);
services.addNewAirport(AirportName.TALLINN, 2500);
......@@ -77,70 +68,69 @@ public class Main {
/*=============================FLIGHTS=======================================*/
AirportService.allAirports.add(a1);
services.addNewAirport(AirportName.OSLO, 3214);
services.addNewAirport(AirportName.RIGA, 4000);
Date d1 = new Date(2020, 10, 10, 9, 00);
Date d2 = new Date(2020, 11, 12, 10, 00);
System.out.println("Add new flight: " + services.addNewFlight(AirportName.BARSELONA, AirportName.RIGA, new Date(2020, 10, 10, 9, 00), (byte) 2));
System.out.println("Add new flight: " + services.addNewFlight(AirportName.OSLO, AirportName.BARSELONA, new Date(2020, 11, 12, 10, 00), (byte) 3));
System.out.println("Add new flight: " + services.addNewFlight(AirportName.TALLINN, AirportName.RIGA, new Date(2020, 6, 3, 3, 25), (byte) 1));
System.out.println("Add new flight: " + services.addNewFlight(AirportName.RIGA, AirportName.OSLO, new Date(2020, 6, 5, 2, 15), (byte) 3));
System.out.println("Add new flight: " + services.addNewFlight(AirportName.BARSELONA, AirportName.TALLINN, new Date(2020, 6, 7, 12, 20), (byte)1));
System.out.println("Add new flight: " + services.addNewFlight(AirportName.TALLINN, AirportName.OSLO, new Date(2020, 6, 14, 5, 35), (byte)3));
Flight f1 = new Flight(d1, (byte) 3, AirportService.allAirports.get(0), AirportService.allAirports.get(1));
Flight f2 = new Flight(d2, (byte) 3, AirportService.allAirports.get(0), AirportService.allAirports.get(2));
AirportService.allFlights.add(f1);
AirportService.allFlights.add(f2);
System.out.println("------------------Flights------------------------------");
for(Flight f : AirportService.allFlights) {
System.out.println(f);
}
System.out.println("--------------------------------------------------------");
//System.out.println("Delete Flight by flight number and airport name: " + services.deleteFlightInAirportByNr(AirportName.OSLO, 0));
System.out.println("Delete Flight by flight number and airport name: " + services.deleteFlightInAirportByNr(AirportName.OSLO, 1));
System.out.println("------------Flights after delete-----------------------");
for(Flight f : AirportService.allFlights) {
System.out.println(f);
}
System.out.println("--------------------------------------------------------");
/*============================BOARDING PASSES===================================*/
services.addNewPassenger("Janis", "Liepins", Nationality.LATVIAN, IdenType.PASSPORT, "AS12345", true);
services.addNewVipPassenger("Juris", "Pakalns", Nationality.ITALIAN, IdenType.IDCARD, "DE12345", true, "VZ12345");
for(Passenger p : AirportService.allPassenger) {
System.out.println(p);
}
services.addNewPassenger("Baiba", "Jauka", Nationality.ESTONIAN, IdenType.PASSPORT, "IS43251", false);
BoardingPass b1 = new BoardingPass(AirportService.allPassenger.get(0));
BoardingPass b2 = new BoardingPass(AirportService.allPassenger.get(1));
BoardingPass b3 = new BoardingPass(AirportService.allPassenger.get(2));
//BoardingPass b4 = new BoardingPass(vip2);
AirportService.allBoardingPasses.add(b1);
AirportService.allBoardingPasses.add(b2);
AirportService.allBoardingPasses.add(b3);
//AirportService.allBoardingPasses.add(b4);
b2.generateSeatByPriority();
System.out.println("-------------------Boarding passes---------------------");
for(BoardingPass b : AirportService.allBoardingPasses) {
System.out.println(b);
}
System.out.println("--------------------------------------------------------");
//System.out.println("Delete bording pass by number: " + services.deleteBoardingPassByBoardingPassNr(AirportService.allBoardingPasses.get(1).getBoardingPassNr()));
System.out.println("Delete bording pass by number: " + services.deleteBoardingPassByBoardingPassNr(AirportService.allBoardingPasses.get(2).getBoardingPassNr()));
System.out.println("--------------Boarding passes after delete---------------");
for(BoardingPass b : AirportService.allBoardingPasses) {
System.out.println(b);
}
System.out.println("--------------------------------------------------------");
for(Airport a : AirportService.allAirports) {
System.out.println(a);
}
System.out.println("-----------All flights in Airport Barselona-------------");
services.showAppFlightsFromAirport(AirportName.BARSELONA);
System.out.println("--------------------------------------------------------");
services.showAppFlightsFromAirport(AirportName.OSLO);
System.out.println("-----------All flights in Airport Tallinn-------------");
services.showAppFlightsFromAirport(AirportName.TALLINN);
System.out.println("--------------------------------------------------------");
System.out.println(services.addNewBoardingPassByObject(f1, AirportService.allPassenger.get(2)));
System.out.println("------------Sort all airport by capacity----------------");
services.sortAllAirportsByCapacity();
System.out.println("--------------------------------------------------------");
for(BoardingPass b : AirportService.allBoardingPasses) {
System.out.println(b);
}
services.sortAllFlightsInDay();
}
}
......@@ -10,7 +10,7 @@ import services.AirportService;
*/
public class BoardingPass implements INumberGenerator{
private String boardingPassNr;
private short group;
private int group;
private Passenger passenger;
private Seat seat;
......@@ -105,6 +105,7 @@ public class BoardingPass implements INumberGenerator{
this.seat = new Seat(row, seat);
}
}
/*
* @brief Boarding pass number is created as follows: the first letter from passenger name +
* the first letter from surname + seat + group
......@@ -117,6 +118,8 @@ public class BoardingPass implements INumberGenerator{
StringBuilder sb = new StringBuilder();
sb.append(passenger.getName().charAt(0));
sb.append(passenger.getSurname().charAt(0));
//sb.append(seat);
//sb.append(group);
this.boardingPassNr = sb.toString();
}
......
......@@ -12,7 +12,7 @@ public class Flight implements INumberGenerator{
private int flightNr;
private Date dateAndTime;
private byte duration;
private PriorityQueue<BoardingPass> allPassenger = new PriorityQueue<BoardingPass>();
public static PriorityQueue<BoardingPass> allPassenger = new PriorityQueue<BoardingPass>();
private Airport airportFrom;
private Airport airportTo;
private static int flightNrCount = 0;
......@@ -96,7 +96,8 @@ public class Flight implements INumberGenerator{
* @return none
*/
public void setDuration(byte duration) {
this.duration = duration;
if(duration > 0)
this.duration = duration;
}
/*
* @brief Returns passengers in flight
......@@ -114,7 +115,8 @@ public class Flight implements INumberGenerator{
* @return none
*/
public void setAllPassenger(PriorityQueue<BoardingPass> allPassenger) {
this.allPassenger = allPassenger;
if(allPassenger != null)
this.allPassenger = allPassenger;
}
/*
* @brief Argument constructor
......@@ -140,8 +142,8 @@ public class Flight implements INumberGenerator{
*/
@Override
public String toString() {
return "Flight [flightNr=" + flightNr + ", dateAndTime=" + dateAndTime + ", duration=" + duration
+ ", allPassenger=" + allPassenger + ", airportFrom=" + airportFrom + ", airportTo=" + airportTo + "]";
return "Flight: " + flightNr + ", Date: " + dateAndTime + ", duration: " + duration
+ ", allPassenger: " + allPassenger + ", From: " + airportFrom + ", To: " + airportTo;
}
/*
* @brief Generates number for Flight
......@@ -168,11 +170,4 @@ public class Flight implements INumberGenerator{
return true;
}
}
}
package services;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import enums.AirportName;
......@@ -20,154 +22,173 @@ public class AirportService {
public static ArrayList<BoardingPass> allBoardingPasses = new ArrayList<BoardingPass>();
public static ArrayList<Airport> allAirports = new ArrayList<Airport>();
public static ArrayList<Flight> allFlights = new ArrayList<Flight>();
public AirportService() {
}
/*
* @brief Adds new regular passenger
*
* @param name
*
* @param surname
*
* @param nationality
*
* @param idenType - Passport or IDcard
*
* @param idenNr - Passports or IDcards number
*
* @param isAudult
*
* @param extraNeeds
*
* @return true of false
*/
public boolean addNewPassenger(String name, String surname, Nationality nationality, IdenType idenType,
String idenNr, boolean isAdult) {
if(idenNr == null)
return false;
else {
for(Passenger p : allPassenger) {
if(p.getIdenNr().equals(idenNr)) {
return false;
}
}
Passenger newPas = new Passenger(name, surname, idenNr, nationality, idenType, isAdult);
allPassenger.add(newPas);
return true;
public boolean addNewPassenger(String name, String surname, Nationality nationality, IdenType idenType,
String idenNr, boolean isAdult) {
for (Passenger p : allPassenger) {
if (p.getIdenNr().equals(idenNr))
return false;
}
Passenger newPas = new Passenger(name, surname, idenNr, nationality, idenType, isAdult);
allPassenger.add(newPas);
return true;
}
/*
* @brief Adds new VIP passenger
*
* @param name
*
* @param surname
*
* @param nationality
*
* @param idenType - Passport or IDcard
*
* @param idenNr - Passports or IDcards number
*
* @param isAdult
*
* @param extraNeeds
*
* @param laungeCardNr
*
* @return true or false
*/
public boolean addNewVipPassenger(String name, String surname, Nationality nationality, IdenType idenType,
String idenNr, boolean isAdult, String laungeCardNr) {
if(idenNr == null)
return false;
else {
for(Passenger p : allPassenger) {
if(p.getIdenNr().equals(idenNr)) {
return false;
}
public boolean addNewVipPassenger(String name, String surname, Nationality nationality, IdenType idenType,
String idenNr, boolean isAdult, String laungeCardNr) {
for (Passenger p : allPassenger) {
if (p.getIdenNr().equals(idenNr)) {
return false;
}
VipPassenger newVip = new VipPassenger(name, surname, idenNr, nationality, idenType, isAdult, laungeCardNr);
allPassenger.add(newVip);
return true;
}
VipPassenger newVip = new VipPassenger(name, surname, idenNr, nationality, idenType, isAdult, laungeCardNr);
allPassenger.add(newVip);
return true;
}
/*
* @brief Adds new airport
*
* @param airportName
* @param airportName
*
* @param capacity - Capacity for airport
*
* @return true or false
*/
public boolean addNewAirport(AirportName airportName, int capacity) {
if(capacity > 0) {
Airport newA = new Airport(capacity, airportName);
allAirports.add(newA);
return true;
}
return false;
Airport newA = new Airport(capacity, airportName);
allAirports.add(newA);
return true;
}
/*
* @brief Adds new BoardingPass if Flight and Passenger object are as input parameters
* @brief Adds new BoardingPass if Flight and Passenger object are as input
* parameters
*
* @param flight
*
* @param passanger
*
* @return true or false
*/
public boolean addNewBoardingPassByObject(Flight flight, Passenger passenger) {
if(flight == null || passenger == null)
return false;
else {
for(Flight f : allFlights) {
if(f.equals(flight)) {
BoardingPass newPass = new BoardingPass(passenger);
allBoardingPasses.add(newPass);
return true;
}
}
return false;
}
return false;
}
/*
* @brief Adds new BoardingPass if AirportName, Flight number and Passenger identificator (IDcard number
* or passport number) are as input parameters
* @brief Adds new BoardingPass if AirportName, Flight number and Passenger
* identificator (IDcard number or passport number) are as input parameters
*
* @param airportName
*
* @param flightNr - Flight number
*
* @param idenNr - Passprots or IDcards number
*
* @return true or false
*/
public boolean addNewBoardingPassByNr(AirportName airportName, int flightNr, String idenNr) {
return false;
}
/*
* @brief Adds new Flight
*
* @param airportNameFrom - Name of Airport where flight begins
*
* @param airportNameTo - Name of Airport where flight ends
*
* @param duration - Duration of Flight
*
* @return true or false
*/
public boolean addNewFlight(AirportName airportNameFrom, AirportName airportNameTo, Date date, byte duration) {
if(duration < 0)
if (airportNameFrom == airportNameTo)
return false;
else {
for(Flight f : allFlights) {
if(f.getAirportFrom().getAirportName().equals(airportNameFrom) && f.getAirportTo().getAirportName().equals(airportNameTo) && f.getDateAndTime().equals(date) && f.getDuration() == duration)
for (Flight f : allFlights) {
if (f.getAirportFrom().getAirportName().equals(airportNameFrom)
&& f.getAirportTo().getAirportName().equals(airportNameTo) && f.getDateAndTime().equals(date)
&& f.getDuration() == duration) {
return false;
}
}
for (Airport a : allAirports) {
if (a.getAirportName().equals(airportNameFrom)) {
for (Airport a1 : allAirports) {
if (a1.getAirportName().equals(airportNameTo)) {
Flight newF = new Flight(date, duration, a, a1);
allFlights.add(newF);
return true;
}
}
}
}
return true;
return false;
}
}
/*
*@brief Delete Passenger by Name and Surname
* @brief Delete Passenger by Name and Surname
*
*@param name
*@param surname
*@return true or false
* @param name
*
* @param surname
*
* @return true or false
*/
public boolean deletePassengerByNameAndSurname(String name, String surname) {
if(allPassenger.isEmpty())
if (allPassenger.isEmpty())
return false;
else {
for(Passenger p : allPassenger) {
if(p.getName().equals(name) && p.getSurname().equals(surname)) {
for (Passenger p : allPassenger) {
if (p.getName().equals(name) && p.getSurname().equals(surname)) {
allPassenger.remove(p);
return true;
}
......@@ -175,19 +196,20 @@ public class AirportService {
return false;
}
}
/*
* @brief Delete Passenger by identificator (IDcard number or passport number)
* @brief Delete Passenger by identificator (IDcard number or passport number)
*
* @param idenNr - IDcard number or passport number
*
* @return true or false
*/
public boolean deletePassengerByIdentNr(String idenNr) {
if(idenNr == null || allPassenger.isEmpty())
if (idenNr == null || allPassenger.isEmpty())
return false;
else {
for(Passenger p : allPassenger) {
if(p.getIdenNr().equals(idenNr)) {
for (Passenger p : allPassenger) {
if (p.getIdenNr().equals(idenNr)) {
allPassenger.remove(p);
return true;
}
......@@ -195,20 +217,21 @@ public class AirportService {
return false;
}
}
/*
* @brief Delete VIP Passenger by VIP number
*
* @param vipNr
*
* @return true or false
*/
public boolean deleteVipPassengerByVipNr(int vipNr) {
if(allPassenger.isEmpty())
if (allPassenger.isEmpty())
return false;
else {
for(Passenger p : allPassenger) {
if(p instanceof VipPassenger) {
if(((VipPassenger) p).getVipNr() == vipNr) {
for (Passenger p : allPassenger) {
if (p instanceof VipPassenger) {
if (((VipPassenger) p).getVipNr() == vipNr) {
allPassenger.remove(p);
return true;
}
......@@ -217,19 +240,20 @@ public class AirportService {
return false;
}
}
/*
* @brief Delete Airport by Airport number
*
* @param airportNr
*
* @return true or false
*/
public boolean deleteAirportByAirportNr(String airportNr) {
if(airportNr == null)
if (airportNr == null)
return false;
else {
for(Airport a : allAirports){
if(a.getAirportNr().equals(airportNr)){
for (Airport a : allAirports) {
if (a.getAirportNr().equals(airportNr)) {
allAirports.remove(a);
return true;
}
......@@ -237,20 +261,20 @@ public class AirportService {
return false;
}
}
/*
* @brief Delete Airport by Airport Name
*
* @param airportName
*
* @return true or false
*/
public boolean deleteAirportByAirportName(AirportName airportName) {
if(allAirports.isEmpty()) {
if (allAirports.isEmpty()) {
return false;
}
else {
for(Airport a : allAirports) {
if(a.getAirportName().equals(airportName)) {
} else {
for (Airport a : allAirports) {
if (a.getAirportName().equals(airportName)) {
allAirports.remove(a);
return true;
}
......@@ -258,19 +282,20 @@ public class AirportService {
return false;
}
}
/*
* @brief Delete BoardingPass by BoardingPass number
*
* @param boardingPassNr
*
* @return true of false
*/
public boolean deleteBoardingPassByBoardingPassNr(String boardingPassNr) {
if(allBoardingPasses.isEmpty())
if (allBoardingPasses.isEmpty())
return false;
else {
for(BoardingPass bp : allBoardingPasses) {
if(bp.getBoardingPassNr().equals(boardingPassNr)) {
for (BoardingPass bp : allBoardingPasses) {
if (bp.getBoardingPassNr().equals(boardingPassNr)) {
allBoardingPasses.remove(bp);
return true;
}
......@@ -278,20 +303,22 @@ public class AirportService {
return false;