Commit 852d4779 authored by Ieva's avatar Ieva
Browse files

Boarding Pass Updated

parent d1137160
No preview for this file type
No preview for this file type
......@@ -8,6 +8,7 @@ import enums.Nationality;
import models.Airport;
import models.BoardingPass;
import models.Passenger;
import models.VipPassenger;
import services.AirportService;
public class Main {
......@@ -21,10 +22,14 @@ public class Main {
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);
}
......
......@@ -42,10 +42,6 @@ public class Airport implements INumberGenerator{
}
@Override
public String toString() {
return "Airport [airportNr=" + airportNr + ", capacity=" + capacity + ", airportName=" + airportName + "]";
return "Airport [airportNr: " + airportNr + ", capacity: " + capacity + ", airportName: " + airportName + "]";
}
}
package models;
import java.util.Random;
import ifaces.INumberGenerator;
import services.AirportService;
public class BoardingPass implements INumberGenerator{
private String boardingPassNr;
......@@ -26,20 +29,43 @@ public class BoardingPass implements INumberGenerator{
public BoardingPass(Passenger passenger) {
this.passenger = 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)
this.group = 1;
else
this.group = (short) (rand.nextInt(5 - 2) + 2);
}
}
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);
}
}
}
@Override
public void generateNr() {
StringBuilder sb = new StringBuilder();
sb.append(passenger.getName().charAt(0));
sb.append(passenger.getSurname().charAt(0));
sb.append(seat);
sb.append(group);
sb.append(this.seat);
sb.append(this.group);
this.boardingPassNr = sb.toString();
}
@Override
......
......@@ -13,9 +13,9 @@ import models.Passenger;
import models.VipPassenger;
public class AirportService {
private ArrayList<Passenger> allPassenger = new ArrayList<Passenger>();
private ArrayList<BoardingPass> allBoardingPasses = new ArrayList<BoardingPass>();
private ArrayList<Airport> allAirports = new ArrayList<Airport>();
public static ArrayList<Passenger> allPassenger = new ArrayList<Passenger>();
public static ArrayList<BoardingPass> allBoardingPasses = new ArrayList<BoardingPass>();
public static ArrayList<Airport> allAirports = new ArrayList<Airport>();
public AirportService() {
......@@ -59,8 +59,8 @@ public class AirportService {
else {
for(AirportName names : AirportName.values()) {
if(airportName == names && capacity > 0) {
Airport newA = new Airport(capacity, airportName);
allAirports.add(newA);
//Airport newA = new Airport(capacity, airportName);
//allAirports.add(newA);
return true;
}
}
......
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