Commit 365a013a authored by Ieva's avatar Ieva
Browse files

.

parent 7fbbc388
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
package main;
import java.util.ArrayList;
import java.util.Date;
import enums.AirportName;
import enums.IdenType;
import enums.Nationality;
import models.Airport;
import models.BoardingPass;
import models.Flight;
import models.Passenger;
import models.VipPassenger;
import services.AirportService;
......@@ -17,69 +19,28 @@ public class Main {
AirportService services = new AirportService();
//System.out.println(services.addNewPassenger("Ieva", "Bekmne", Nationality.ESTONIAN, IdenType.IDCARD, "1234", true, "No"));
/**System.out.println(services.addNewAirport(AirportName.BARSELONA, 100));
System.out.println();
Passenger p = new Passenger("Name", "Surname", "1234", Nationality.ESTONIAN, IdenType.IDCARD, true, "NO");
AirportService.allPassenger.add(p);
BoardingPass b = new BoardingPass(p);
System.out.println(b);
VipPassenger vip = new VipPassenger("Ieva", "Bekmane", "123", Nationality.LATVIAN, IdenType.PASSPORT, true, "No", "123412");
AirportService.allPassenger.add(vip);
BoardingPass b2 = new BoardingPass(vip);
System.out.println(b2);
System.out.println(vip);
Airport a = new Airport(10000, AirportName.BARSELONA);
System.out.println(a);
System.out.println("----------------------------------------");
services.addNewPassenger("Liene", "Kalna", Nationality.ESTONIAN, IdenType.IDCARD, "AS12345", true, "NO");
for(Passenger pass : AirportService.allPassenger) {
System.out.println(pass);
}
System.out.println("-----------------------------------------");
services.deletePassengerByIdentNr("AS12345");
for(Passenger pass2 : AirportService.allPassenger) {
System.out.println(pass2);
}*/
//System.out.println(services.addNewPassenger("Ieva", "Zarina", Nationality.ESTONIAN, IdenType.PASSPORT, "AS12345", true, "No"));
//System.out.println(services.addNewPassenger("Zane", "Zarina", Nationality.ESTONIAN, IdenType.PASSPORT, "AS12345", true, "No"));
//System.out.println(services.addNewVipPassenger("Artis", "Liepins", Nationality.ITALIAN, IdenType.PASSPORT, "SA12345", true, "lol", "ZX1231"));
//System.out.println(services.addNewVipPassenger("Janis", "Kalnins", Nationality.ITALIAN, IdenType.PASSPORT, "DG23143", true, "lol", "ZX1231"));
/*System.out.println("-----------------------------------------");
for(Passenger pass2 : AirportService.allPassenger) {
System.out.println(pass2);
}
System.out.println("-----------------------------------------");
*/
/**System.out.println(services.addNewAirport(AirportName.OSLO, 2000));
for(Airport a : AirportService.allAirports) {
System.out.println(a);
services.addNewPassenger("Janis", "Liepins", Nationality.LATVIAN, IdenType.PASSPORT, "AS12345", true, "No extra needs");
services.addNewPassenger("Liene", "Kalnina", Nationality.ESTONIAN, IdenType.IDCARD, "GH12345", false, "No extra needs");
services.addNewVipPassenger("Baiba", "Jauka", Nationality.ITALIAN, IdenType.PASSPORT, "ER12345", true, "No extra needs", "ZX12345");
services.addNewVipPassenger("Zane", "Berzina", Nationality.LATVIAN, IdenType.PASSPORT, "LM12345", true, "No extra needs", "BN12345");
services.addNewAirport(AirportName.BARSELONA, 2000);
services.addNewAirport(AirportName.OSLO, 3000);
services.addNewAirport(AirportName.RIGA, 4000);
services.addNewAirport(AirportName.TALLINN, 2500);
Date d1 = new Date(2020, 10, 10, 9, 00);
Date d2 = new Date(2020, 11, 12, 10, 00);
Flight f1 = new Flight(d1, (byte) 3, AirportService.allAirports.get(0), AirportService.allAirports.get(1));
AirportService.allFlights.add(f1);
for(Passenger p : AirportService.allPassenger) {
System.out.println(p);
}
System.out.println("-----------------------------------------");*/
services.addNewBoardingPassByObject(f1, AirportService.allPassenger.get(0));
/*System.out.println(services.deleteVipPassengerByVipNr(0));
System.out.println("-----------------------------------------");
for(Passenger pass2 : AirportService.allPassenger) {
System.out.println(pass2);
}
System.out.println("-----------------------------------------");*/
/*System.out.println(services.addNewAirport(AirportName.BARSELONA, 200));
System.out.println(services.addNewAirport(AirportName.RIGA, 300));
System.out.println(services.addNewAirport(AirportName.TALLINN, 500));
for(Airport a : AirportService.allAirports) {
System.out.println(a);
for(BoardingPass bp : AirportService.allBoardingPasses) {
System.out.println(bp);
}
System.out.println(services.deleteAirportByAirportName(AirportName.OSLO));
for(Airport a : AirportService.allAirports) {
System.out.println(a);
}*/
}
}
......@@ -4,32 +4,77 @@ import java.util.Random;
import enums.AirportName;
import ifaces.INumberGenerator;
import utils.Verifiction;
public class Airport implements INumberGenerator{
private String airportNr;
private int capacity;
private AirportName airportName;
/*
* @brief Returns Airports number
*
* @param none
* @return airportNr
*/
public String getAirportNr() {
return airportNr;
}
/*
* @brief Returns Airports name
*
* @param none
* @return airportName
*/
public AirportName getAirportName() {
return airportName;
}
/*
* @brief Allows to set Airports name
*
* @param airportName
* @return none
*/
public void setAirportName(AirportName airportName) {
this.airportName = airportName;
}
/*
* @brief Returns capacity of Airport
*
* @param none
* @return capacity
*/
public int getCapacity() {
return capacity;
}
/*
* @brief Allows to set capacity for Airport
*
* @param capacity
* @return none
*/
public void setCapacity(int capacity) {
this.capacity = capacity;
this.capacity = Verifiction.varifyInt(capacity);
}
/*
* @brief Argument constructor
*
* @param capacity
* @param airportName
* @return none
*/
public Airport(int capacity, AirportName airportName) {
setCapacity(capacity);
setAirportName(airportName);
generateNr();
}
/*
* @brief Creates airport number. Takes first three letters from airport name and random number
* from 10 to 100
*
* @param none
* @return none
*/
@Override
public void generateNr() {
Random rand = new Random();
......@@ -40,6 +85,12 @@ public class Airport implements INumberGenerator{
s.append(rand.nextInt(100 - 10) + 10);
this.airportNr = s.toString();
}
/*
* @brief Prints output
*
* @param none
* @return output
*/
@Override
public String toString() {
return "Airport [airportNr: " + airportNr + ", capacity: " + capacity + ", airportName: " + airportName + "]";
......
......@@ -27,16 +27,16 @@ public class BoardingPass implements INumberGenerator{
return boardingPassNr;
}
public BoardingPass(Passenger passenger) {
this.passenger = passenger;
setPassenger(passenger);
generateNr();
generateGroupByPriority();
generateSeatByPriority();
}
public void generateGroupByPriority() {
Random rand = new Random();
for(int i = 0; i < AirportService.allPassenger.size(); i++) {
Passenger tempPass = AirportService.allPassenger.get(i);
if(tempPass instanceof VipPassenger)
for(Passenger p : AirportService.allPassenger) {
//Passenger tempPass = AirportService.allPassenger.get(i);
if(p instanceof VipPassenger)
this.group = 1;
else
this.group = (short) (rand.nextInt(5 - 2) + 2);
......@@ -45,9 +45,9 @@ public class BoardingPass implements INumberGenerator{
public void generateSeatByPriority() {
Random rand = new Random();
char[] rows = {'a', 'b', 'c', 'd', 'e', 'f'};
for(int i = 0; i < AirportService.allPassenger.size(); i++) {
Passenger tempPass = AirportService.allPassenger.get(i);
if(tempPass instanceof VipPassenger) {
for(Passenger p : AirportService.allPassenger) {
//Passenger tempPass = p;
if(p instanceof VipPassenger) {
char row = rows[rand.nextInt(6 - 1) + 1];
short seat = (short) (rand.nextInt(3 - 1) + 1);
this.seat = new Seat(row, seat);
......
......@@ -67,7 +67,15 @@ public class Flight implements INumberGenerator{
}
public boolean addNewPassengerByBoardingPass(Passenger passenger) {
if(passenger == null)
return false;
else {
for(BoardingPass bp : allPassenger) {
if(bp.getPassenger().equals(passenger))
return false;
}
}
return false;
}
......
......@@ -63,7 +63,7 @@ public class Passenger extends Person {
boolean isAdult, String extraNeeds) {
super(name, surname, idenNr, nationality, idenType);
setAudult(isAdult);
setExtraNeeds(extraNeeds);
setExtraNeeds(getExtraNeeds());
}
/*
......@@ -85,9 +85,14 @@ public class Passenger extends Person {
*/
@Override
public String toString() {
return "Passenger: " + getName() + " " + getSurname() + " isAudult=" + isAdult + ", extraNeeds=" + extraNeeds + "]";
return "Passenger: " + getName() + " " + getSurname() + ", isAudult: " + isAdult + ", extraNeeds: " + extraNeeds;
}
/*
* @brief Generates passengers extra needs
*
* @param none
* @return none
*/
public void generateExtraNeeds() {
if(isAdult == false)
System.out.println("Adult companion requred!");
......
......@@ -151,7 +151,7 @@ public class Person {
*/
@Override
public String toString() {
return "Person [name=" + name + ", surname=" + surname + ", idenNr=" + idenNr + ", nationality=" + nationality
+ ", idenType=" + idenType + "]";
return "Person: " + name + " " + surname + ", idenNr: " + idenNr + ", nationality: " + nationality
+ ", idenType: " + idenType;
}
}
......@@ -14,34 +14,83 @@ public class VipPassenger extends Passenger implements INumberGenerator {
private String loungeCardNr;
private static int vipNrCount = 0;
/*
* @brief Returns lounge cards number
*
* @param none
* @return loungeCardNr
*/
public String getLoungeCardNr() {
return loungeCardNr;
}
/*
* @brief Allows to set lounge cards number
*
* @param loungeCardNr
* @return none
*/
public void setLoungeCardNr(String loungeCardNr) {
this.loungeCardNr = loungeCardNr;
this.loungeCardNr = Verifiction.verifyIdenNr(loungeCardNr);
}
/*
* @brief Returns VIP number
*
* @param none
* @return vipNr
*/
public int getVipNr() {
return vipNr;
}
/*
* @brief Argument constructor
*
* @param loungeCardNr
* @return none
*/
public VipPassenger(String loungeCardNr) {
super();
setLoungeCardNr(loungeCardNr);
generateNr();
}
/*
* @brief Prints output
*
* @param none
* @return output
*/
@Override
public String toString() {
return "VipPassenger [vipNr=" + vipNr + ", loungeCardNr=" + loungeCardNr + "]";
return "VipPassenger: " + getName() + " " + getSurname() + ", vipNr: " + vipNr + ", loungeCardNr: " + loungeCardNr;
}
/*
* Returns passengers extra needs
*
* @param none
* @return string of passengers needs
*/
public void generateExtraNeeds() {
}
/*
* Returns Argument constructor
*
* @param name
* @param surname
* @param idenNr - passport or IDcard number
* @return none
*/
public VipPassenger(String name, String surname, String idenNr, Nationality nationality, IdenType idenType,
boolean isAdult, String extraNeeds, String loungeCardNr) {
super(name, surname, idenNr, nationality, idenType, isAdult, extraNeeds);
setLoungeCardNr(loungeCardNr);
generateNr();
}
/*
* Returns Generates number for vip passenger
*
* @param none
* @return none
*/
@Override
public void generateNr() {
this.vipNr = vipNrCount;
......
......@@ -21,69 +21,133 @@ public class AirportService {
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, String extraNeeds) {
if(name == null && surname == null && nationality == null && idenType == null && idenNr == null && extraNeeds == null)
return false;
else {
for(Passenger p : allPassenger) {
if(p.getIdenNr().equals(idenNr)) {
return false;
}
for(Passenger p : allPassenger) {
if(p.getIdenNr().equals(idenNr)) {
return false;
}
Passenger newPas = new Passenger(name, surname, idenNr, nationality, idenType, isAdult, extraNeeds);
allPassenger.add(newPas);
return true;
}
Passenger newPas = new Passenger(name, surname, idenNr, nationality, idenType, isAdult, extraNeeds);
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 extraNeeds, String laungeCardNr) {
if(name == null && surname == null && nationality == null && idenType == null && idenNr == null && extraNeeds == null && laungeCardNr == null)
return false;
else {
for(Passenger p : allPassenger) {
if(p.getIdenNr().equals(idenNr)) {
return false;
}
for(Passenger p : allPassenger) {
if(p.getIdenNr().equals(idenNr)) {
return false;
}
VipPassenger newVip = new VipPassenger(name, surname, idenNr, nationality, idenType, isAdult, extraNeeds, laungeCardNr);
allPassenger.add(newVip);
return true;
}
VipPassenger newVip = new VipPassenger(name, surname, idenNr, nationality, idenType, isAdult, extraNeeds, laungeCardNr);
allPassenger.add(newVip);
return true;
}
/*
* @brief Adds new airport
*
* @param airportName
* @param capacity - Capacity for airport
* @return true or false
*/
public boolean addNewAirport(AirportName airportName, int capacity) {
if(airportName == null && capacity == 0)
if(capacity > 0) {
Airport newA = new Airport(capacity, airportName);
allAirports.add(newA);
return true;
}
return false;
}
/*
* @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(AirportName names : AirportName.values()) {
if(airportName == names && capacity > 0) {
Airport newA = new Airport(capacity, airportName);
allAirports.add(newA);
return true;
for(Flight f : allFlights) {
if(f.equals(flight)) {
BoardingPass newPass = new BoardingPass(passenger);
allBoardingPasses.add(newPass);
}
}
return false;
}
}
public boolean addNewBoardingPassByObject(Flight flight, Passenger passenger) {
return false;
}
public boolean addNewBoardingPassByNr(AirportName airportName, int capacity, String idenNr) {
/*
* @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) {
return false;
if(duration < 0)
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)
return false;
}
return true;
}
}
/*
*@brief Delete Passenger by Name and Surname
*
*@param name
*@param surname
*@return true or false
*/
public boolean deletePassengerByNameAndSurname(String name, String surname) {
if(allPassenger.isEmpty())
return false;
......@@ -98,6 +162,12 @@ public class AirportService {
}
}
/*
* @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())
return false;
......@@ -112,6 +182,12 @@ public class AirportService {
}
}
/*
* @brief Delete VIP Passenger by VIP number
*
* @param vipNr
* @return true or false
*/
public boolean deleteVipPassengerByVipNr(int vipNr) {
if(allPassenger.isEmpty())
return false;
......@@ -128,6 +204,12 @@ public class AirportService {
}
}
/*
* @brief Delete Airport by Airport number
*
* @param airportNr
* @return true or false
*/
public boolean deleteAirportByAirportNr(String airportNr) {
if(airportNr == null)
return false;
......@@ -142,6 +224,12 @@ public class AirportService {
}
}
/*
* @brief Delete Airport by Airport Name
*
* @param airportName
* @return true or false
*/
public boolean deleteAirportByAirportName(AirportName airportName) {
if(allAirports.isEmpty()) {
return false;
......@@ -157,8 +245,14 @@ public class AirportService {
}
}
/*
* @brief Delete BoardingPass by BoardingPass number
*
* @param boardingPassNr
* @return true of false
*/
public boolean deleteBoardingPassByBoardingPassNr(String boardingPassNr) {
if(boardingPassNr == null || allBoardingPasses.isEmpty())
if(allBoardingPasses.isEmpty())