Commit ee4ad081 authored by s7_bekman_i's avatar s7_bekman_i
Browse files

..

parent 75fc06f9
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -23,16 +23,17 @@ public class Main {
AirportService services = new AirportService();
/*====================================PASSENGERS======================================*/
Passenger p1 = new Passenger("Janis", "Liepins", "AS12345", Nationality.LATVIAN, IdenType.PASSPORT, true, "No extra needs");
/*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("Katrina", "Zarina", Nationality.LATVIAN, IdenType.IDCARD, "DF12345", false, "No extra needs");
services.addNewVipPassenger("Juris", "Pakalns", Nationality.ITALIAN, IdenType.IDCARD, "DE12345", true, "No extra needs", "VZ12345");
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.addNewVipPassenger("Juris", "Pakalns", Nationality.ITALIAN, IdenType.IDCARD, "DE12345", true, "VZ12345");
System.out.println("---------------------Passengers-------------------------");
for(Passenger p : AirportService.allPassenger) {
......@@ -91,37 +92,55 @@ public class Main {
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, 0));
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);
}
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);
BoardingPass b1 = new BoardingPass(p1);
BoardingPass b2 = new BoardingPass(p2);
BoardingPass b3 = new BoardingPass(vip1);
BoardingPass b4 = new BoardingPass(vip2);
AirportService.allBoardingPasses.add(b1);
AirportService.allBoardingPasses.add(b2);
AirportService.allBoardingPasses.add(b3);
AirportService.allBoardingPasses.add(b4);
//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(1).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("--------------------------------------------------------");
services.showAppFlightsFromAirport(AirportName.OSLO);
System.out.println("--------------------------------------------------------");
System.out.println(services.addNewBoardingPassByObject(f1, AirportService.allPassenger.get(2)));
System.out.println("--------------------------------------------------------");
for(BoardingPass b : AirportService.allBoardingPasses) {
System.out.println(b);
}
}
}
......@@ -79,13 +79,10 @@ public class BoardingPass implements INumberGenerator{
*/
public void generateGroupByPriority() {
Random rand = new Random();
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);
}
if(passenger instanceof VipPassenger)
this.group = 1;
else
this.group = (short) (rand.nextInt(5 - 2) + 2);
}
/*
* @brief Seat is generated by priority. Seats of VIP passengers are from 1 to 3 in every column (a, b, c, d, e, f).
......@@ -96,19 +93,16 @@ 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) {
char row = rows[rand.nextInt(6 - 1) + 1];
short seat = (short) (rand.nextInt(3 - 1) + 1);
this.seat = new Seat(row, seat);
}
else {
char row = rows[rand.nextInt(6 - 1) + 1];
short seat = (short) (rand.nextInt(200 - 3) + 3);
this.seat = new Seat(row, seat);
}
char[] rows = {'A', 'B', 'C', 'D', 'E', 'F'};
if(passenger instanceof VipPassenger) {
char row = rows[rand.nextInt(6 - 1) + 1];
short seat = (short) (rand.nextInt(3 - 1) + 1);
this.seat = new Seat(row, seat);
}
else {
char row = rows[rand.nextInt(6 - 1) + 1];
short seat = (short) (rand.nextInt(200 - 3) + 3);
this.seat = new Seat(row, seat);
}
}
/*
......@@ -123,8 +117,7 @@ public class BoardingPass implements INumberGenerator{
StringBuilder sb = new StringBuilder();
sb.append(passenger.getName().charAt(0));
sb.append(passenger.getSurname().charAt(0));
sb.append(this.seat);
sb.append(this.group);
this.boardingPassNr = sb.toString();
}
/*
......@@ -135,8 +128,8 @@ public class BoardingPass implements INumberGenerator{
*/
@Override
public String toString() {
return "BoardingPass [boardingPassNr=" + boardingPassNr + ", group=" + group + ", passenger=" + passenger
+ ", seat=" + seat + "]";
return "BoardingPass Nr: " + boardingPassNr + ", group: " + group + ", " + passenger
+ ", " + seat;
}
}
......@@ -12,7 +12,7 @@ public class Flight implements INumberGenerator{
private int flightNr;
private Date dateAndTime;
private byte duration;
private PriorityQueue<BoardingPass> allPassenger;
private PriorityQueue<BoardingPass> allPassenger = new PriorityQueue<BoardingPass>();
private Airport airportFrom;
private Airport airportTo;
private static int flightNrCount = 0;
......@@ -131,7 +131,6 @@ public class Flight implements INumberGenerator{
setAirportFrom(airportFrom);
setAirportTo(airportTo);
generateNr();
}
/*
* @brief Prints output
......
......@@ -44,9 +44,9 @@ public class Passenger extends Person {
* @param extraNeeds - describes passengers extra needs
* @return none
*/
public void setExtraNeeds(String extraNeeds) {
this.extraNeeds = extraNeeds;
}
//public void setExtraNeeds(String extraNeeds) {
//this.extraNeeds = extraNeeds;
//}
/*
* @brief Argument constructor
*
......@@ -60,10 +60,10 @@ public class Passenger extends Person {
* @return none
*/
public Passenger(String name, String surname, String idenNr, Nationality nationality, IdenType idenType,
boolean isAdult, String extraNeeds) {
boolean isAdult) {
super(name, surname, idenNr, nationality, idenType);
setAudult(isAdult);
setExtraNeeds(extraNeeds);
generateExtraNeeds();
}
/*
......@@ -75,7 +75,7 @@ public class Passenger extends Person {
public Passenger() {
super();
this.isAdult = false;
this.extraNeeds = "";
generateExtraNeeds();
}
/*
* @brief Function helps print output
......@@ -85,7 +85,7 @@ 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
......@@ -94,6 +94,11 @@ public class Passenger extends Person {
* @return none
*/
public void generateExtraNeeds() {
if(isAdult == false) {
this.extraNeeds = "Underage, need adult companion!";
}
else {
this.extraNeeds = "No extra needs!";
}
}
}
......@@ -67,7 +67,7 @@ public class Person {
* @return none
*/
public void setIdenNr(String idenNr) {
this.idenNr = Verifiction.verifyIdenNr(idenNr);
this.idenNr = Verifiction.verifyNumberAndChar(idenNr);
}
/*
* @brief Returns persons nationality
......
package models;
import utils.Verifiction;
/*
* @author Ieva Bekmane 3ITB
*/
......@@ -43,9 +45,7 @@ public class Seat {
* @return none
*/
public void setSeat(short seat) {
if(seat > 0) {
this.seat = seat;
}
this.seat =(short) Verifiction.varifyInt(seat);
}
/*
* @brief Argument constructor
......@@ -66,6 +66,6 @@ public class Seat {
*/
@Override
public String toString() {
return "Seat [row=" + row + ", seat=" + seat + "]";
return "Seat: " + seat + row;
}
}
......@@ -13,6 +13,7 @@ public class VipPassenger extends Passenger implements INumberGenerator {
private int vipNr;
private String loungeCardNr;
private static int vipNrCount = 0;
private String extraNeeds;
/*
* @brief Returns lounge cards number
......@@ -30,7 +31,7 @@ public class VipPassenger extends Passenger implements INumberGenerator {
* @return none
*/
public void setLoungeCardNr(String loungeCardNr) {
this.loungeCardNr = Verifiction.verifyIdenNr(loungeCardNr);
this.loungeCardNr = Verifiction.verifyNumberAndChar(loungeCardNr);
}
/*
* @brief Returns VIP number
......@@ -60,7 +61,7 @@ public class VipPassenger extends Passenger implements INumberGenerator {
*/
@Override
public String toString() {
return "VipPassenger: " + getName() + " " + getSurname() + ", vipNr: " + vipNr + ", loungeCardNr: " + loungeCardNr;
return "VipPassenger: " + getName() + " " + getSurname() + ", VipNr: " + vipNr + ", LoungeCardNr: " + loungeCardNr + ", Extra needs: " + extraNeeds;
}
/*
* Returns passengers extra needs
......@@ -69,7 +70,12 @@ public class VipPassenger extends Passenger implements INumberGenerator {
* @return string of passengers needs
*/
public void generateExtraNeeds() {
if(isAudult() == false) {
this.extraNeeds = "Underage, need adult companion!";
}
else {
this.extraNeeds = "No extra needs!";
}
}
/*
* Returns Argument constructor
......@@ -80,10 +86,11 @@ public class VipPassenger extends Passenger implements INumberGenerator {
* @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);
boolean isAdult, String loungeCardNr) {
super(name, surname, idenNr, nationality, idenType, isAdult);
setLoungeCardNr(loungeCardNr);
generateNr();
generateExtraNeeds();
}
/*
* Returns Generates number for vip passenger
......
......@@ -37,15 +37,20 @@ public class AirportService {
* @return true of false
*/
public boolean addNewPassenger(String name, String surname, Nationality nationality, IdenType idenType,
String idenNr, boolean isAdult, String extraNeeds) {
for(Passenger p : allPassenger) {
if(p.getIdenNr().equals(idenNr)) {
return false;
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;
}
Passenger newPas = new Passenger(name, surname, idenNr, nationality, idenType, isAdult, extraNeeds);
allPassenger.add(newPas);
return true;
}
/*
......@@ -62,15 +67,20 @@ public class AirportService {
* @return true or false
*/
public boolean addNewVipPassenger(String name, String surname, Nationality nationality, IdenType idenType,
String idenNr, boolean isAdult, String extraNeeds, String laungeCardNr) {
for(Passenger p : allPassenger) {
if(p.getIdenNr().equals(idenNr)) {
return false;
String idenNr, boolean isAdult, String laungeCardNr) {
if(idenNr == null)
return false;
else {
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, extraNeeds, laungeCardNr);
allPassenger.add(newVip);
return true;
}
/*
......@@ -390,7 +400,7 @@ public class AirportService {
* @param none
* @return none
*/
public void showAllArrivalsByTimeInAirport(AirportName aiirpoerName) {
public void showAllArrivalsByTimeInAirport(AirportName airportName) {
}
......
......@@ -26,7 +26,7 @@ public class Verifiction {
* @param text - users input text
* @return verified string that only contains only letters and digits
*/
public static String verifyIdenNr(String text) {
public static String verifyNumberAndChar(String text) {
String result = "";
for(int i = 0; i < text.length(); i++) {
if(Character.isLetter(text.charAt(i)) || Character.isDigit(text.charAt(i))) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment