Commit 7c9f817b authored by 9531304's avatar 9531304

managing tickets and passengers

parents
Pipeline #678 failed with stages
package com.ticketSystem;
import java.util.ArrayList;
/**
* This Class is about Flight that airline has.
*
* @author Soroush Mehraban
* @version 1.0.0
*/
public class Airline {
private ArrayList<Flight> flights;
/**
* Class Constructor.
*/
public Airline(){
flights = new ArrayList<Flight>();
}
/**
* Adding flight to airline.
*
* @param flight Flight object.
*/
public void addFlight(Flight flight){
flights.add(flight);
}
/**
* removing flight from airline.
*
* @param flight Flight object.
*/
public void removeFlight(Flight flight){
flights.remove(flight);
}
/**
* Getting flights of airline.
*
* @return flights ArrayList.
*/
public ArrayList<Flight> getFlights() {
return flights;
}
}
package com.ticketSystem;
import java.util.ArrayList;
/**
* This class is about each Airplane.
* every airplane has a type and chairs in general, and belongs to a airline.
* We have 2 kind of list:
* -allChairs: this list shows all chairs of this airplane, no matter it is reserved or not.
* -freeChairs: this list shows chairs which they're not reserved and available.
*
* @author Soroush Mehraban
* @version 1.0.0
*/
public class Airplane {
private ArrayList<Chair> freeChairs;
private ArrayList<Chair> allChairs;
private String type;
private String airline;
/**
* Constructor of this class.
*it creates an empty airplane without any chair and we've just it's type.
*
* @param type type of airplane as String.
*/
public Airplane(String type, String airline){
this.type = type;
this.airline = airline;
allChairs = new ArrayList<Chair>();
freeChairs = new ArrayList<Chair>();
}
/**
* this method add a chair to this airplane.
* at first it is in both lists.
*
* @param chair the chair we want to add.
*/
public void addChair(Chair chair){
allChairs.add(chair);
freeChairs.add(chair);
}
/**
* this method gives us list of all chairs, no matter if they're reserved or not.
*
* @return allChairs Arraylist.
*/
public ArrayList<Chair> getAllChairs(){
return allChairs;
}
/**
* this method gives us list of chairs which they're available and ready to be reserved.
* if anyone wants reserve a chair, simply remove that chair from this list which is giving to.
*
* @return freeChairs ArrayList.
*/
public ArrayList<Chair> getFreeChairs() {
return freeChairs;
}
/**
* Getting type of this Airplane.
*
* @return type as a String.
*/
public String getType() {
return type;
}
/**
* Getting airline which airplane belongs to.
*
* @return airline as Stirng.
*/
public String getAirline() {
return airline;
}
}
package com.ticketSystem;
/**
* This class is about chair of each Airplane
* every chair has a number and a type to be unique
*
* @author Soroush Mehraban
* @version 1.0.0
*/
public class Chair {
private int chairNumber;
private String chairType;
/**
* Class Constructor
*
* @param chairNumber the number of chair
* @param chairType Type of chair
*/
public Chair(int chairNumber,String chairType ){
this.chairNumber = chairNumber;
this.chairType = chairType;
}
/**
* Getting number of chair.
*
* @return chairNumber as a int.
*/
public int getChairNumber() {
return chairNumber;
}
/**
* Getting Type of chair.
*
* @return chairType as a String.
*/
public String getChairType() {
return chairType;
}
}
package com.ticketSystem;
import java.util.ArrayList;
/**
* This class is about customer who wants to reserve a flight and own a ticket.
* it has 6 fields:
* -firstname: first name of customer
* -lastname: last name of customer
* -ID: ID of customer
* -tickets: a list of tickets that customer booked.
* -userflights: flights which user added to his/her flights.
* -airline: airline which has available flights.
*
* @author Soroush Mehraban
* @version 1.0.0
*/
public class Customer {
private String firstName;
private String lastName;
private int ID;
private ArrayList<Ticket> tickets;
private ArrayList<Flight> userFlights;
private Airline airline;
/**
* Class Constructor.
*
* @param firstName Customer FirstName
* @param lastName Customer LastName
* @param ID Customer ID
* @param airline airline which has available flights
*/
public Customer(String firstName, String lastName, int ID, Airline airline){
this.firstName = firstName;
this.lastName = lastName;
this.ID = ID;
userFlights = new ArrayList<Flight>();
this.airline = airline;
tickets = new ArrayList<Ticket>();
}
/**
* Adding flight to user flights, if airline has that flight(it's available)
*
* @param flight Flight Object.
* */
public void addFlight(Flight flight){
if(airline.getFlights().contains(flight))
userFlights.add(flight);
}
/**
* Removing flight from user flights.
*
* @param flight Flight object.
*/
public void removeFlight(Flight flight){
userFlights.remove(flight);
}
/**
* Getting user flights.
*
* @return ArrayList of userFlights.
*/
public ArrayList<Flight> getUserFlights() {
return userFlights;
}
/**
* Adding ticket after customer added flight to userFlights.
*
* @param flight Flight object
* @param chairNumber ChairNumber in airplane(If it's a freeChair)
* @param amountOfBsggage how many baggage that customer has.
* @param foodReserve does customer wants food or not.
* @return True if process succeed.
*/
public void addTicket(Flight flight, int chairNumber, int amountOfBsggage, boolean foodReserve){
if(userFlights.contains(flight)) {
Ticket ticket = flight.createTicket(chairNumber, amountOfBsggage,foodReserve);
if(ticket != null)
tickets.add(ticket);
}
}
/**
* showing tickets which Customer booked it before.
*
* @return tickets as ArrayList
*/
public ArrayList<Ticket> getTickets() {
return tickets;
}
}
package com.ticketSystem;
/**
* This class shows date and time for each flight.
*
* @author Soroush Mehraban
* @version 1.0.0
*/
public class Date {
private String date;
private String time;
/**
* Class Constructor.
*
* @param date date of flight.
* @param time time of flight.
*/
public Date(String date,String time){
this.date = date;
this.time = time;
}
/**
* getting date of flight.
*
* @return date as String.
*/
public String getDate() {
return date;
}
/**
* gtting time of flight.
*
* @return time as String.
*/
public String getTime() {
return time;
}
}
package com.ticketSystem;
public class Flight {
private Date dateAndTime;
private String origin;
private String destination;
private Airplane airplane;
private int flightNumber;
/**
* Class Constructor
*
* @param date date of flight.
* @param origin origin of flight.
* @param destination destination of flight.
* @param airplane which airplane this flight is going with it.
* @param flightNumber number of this flight.
*/
public Flight(Date date, String origin, String destination, Airplane airplane, int flightNumber){
this.dateAndTime = date;
this.origin = origin;
this.destination = destination;
this.airplane = airplane;
this.flightNumber = flightNumber;
}
/**
* Getting date and time of flight.
*
* @return Date object.
*/
public Date getDateAndTime() {
return dateAndTime;
}
/**
* Getting origin of flight.
*
* @return origin as String.
*/
public String getOrigin() {
return origin;
}
/**
* Getting destination of flight.
*
* @return destination as String.
*/
public String getDestination() {
return destination;
}
/**
* Getting type of airplane.
* @return airplaneType as String.
*/
public String getAirplaneType(){
return airplane.getType();
}
/**
* Getting airplane's airline.
* @return airline as string.
*/
public String getAirplaneAirline(){
return airplane.getAirline();
}
/**
* Getting flight Number.
* @return int
*/
public int getFlightNumber() {
return flightNumber;
}
/**
* Creating ticket if customer wants to add a ticket.
*
* @param chairNumber Chairnumber in airplane
* @param amountOfBsggage how many baggage customer has
* @param foodReserve is customer wants to reserver food or not.
* @return Ticket object if process succeed or null if it's not.
*/
public Ticket createTicket(int chairNumber, int amountOfBsggage, boolean foodReserve){
for (Chair chair : getAirplane().getFreeChairs())
if (chair.getChairNumber() == chairNumber) {
Ticket ticket = new Ticket(chairNumber, getFlightNumber(), amountOfBsggage, foodReserve);
getAirplane().getFreeChairs().remove(chair);
return ticket;
}
return null;
}
/**
* Getting airplane object.
*
* @return Airplane Object.
*/
private Airplane getAirplane() {
return airplane;
}
}
package com.ticketSystem;
/**
* this Class represent ticket of flight which passenger booked it.
* it has 4 fields:
* -chairNumber: it shows that which chair passenger should seat on it.
* -flightNumber: a specific number differentiate this flight to others.
* -amountOfBaggage: how many baggage does passenger has?
* -foodReserve: does passenger wants to reserve food or not?
*
* @author Soroush Mehraban
* @version 1.0.0
*/
public class Ticket {
private int chairNumber;
private int flightNumber;
private int amountOfBaggage;
private boolean foodReserve;
/**
* constructor of this class.
*
* @param chairNumber chair number for reservation.
* @param flightNumber a specific number for flight.
* @param amountOfBaggage how many baggage does passenger has.
* @param foodReserve does passenger wants food or not.
*/
public Ticket(int chairNumber,int flightNumber, int amountOfBaggage, boolean foodReserve){
this.chairNumber = chairNumber;
this.flightNumber = flightNumber;
this.amountOfBaggage = amountOfBaggage;
this.foodReserve = foodReserve;
}
/**
* getting Flight number.
*
* @return flight number as int.
*/
public int getFlightNumber() {
return flightNumber;
}
/**
* getting chair number.
*
* @return chair number as int.
*/
public int getChairNumber() {
return chairNumber;
}
/**
* getting amount of baggage.
*
* @return amount of baggage as int.
*/
public int getAmountOfBaggage() {
return amountOfBaggage;
}
/**
* demonstrate that passenger wants food or not.
*
* @return boolean.
*/
public boolean isFoodReserve() {
return foodReserve;
}
}
package test;
import com.ticketSystem.Airplane;
import com.ticketSystem.Chair;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* this class test usage of Airplane Class
*
* @author Soroush Mehraban
* @version 1.0.0
*
*/
public class AirplaneTest {
static Airplane airplane;
static Chair chair;
static Chair chair2;
static Chair chair3;
@BeforeAll
public static void createAirplane(){
airplane = new Airplane("Boeing-757","IranAir");
chair = new Chair(23,"First Class");
chair2 = new Chair(31,"Economic Class");
chair3 = new Chair(42,"Business Class");
airplane.addChair(chair);
airplane.addChair(chair2);
airplane.addChair(chair3);
}
@Test
@DisplayName("Test getAllChairs")
public void getAllchairsTest(){
ArrayList<Chair> testChairs = new ArrayList<Chair>();
testChairs.add(chair);
testChairs.add(chair2);
testChairs.add(chair3);
Chair[] expectedArr = testChairs.toArray(new Chair[testChairs.size()]);
Chair[] realArr = airplane.getAllChairs().toArray(new Chair[airplane.getAllChairs().size()]);
assertArrayEquals(expectedArr,realArr);
}
@Test
@DisplayName("Test Airplane Type")
public void getAirplaneTypeTest(){
assertEquals("Boeing-757",airplane.getType());
}
@Test
@DisplayName("Test Airplane Airline")
public void getAirplaneAirlineTest(){
assertEquals("IranAir",airplane.getAirline());
}
}
package test;
import com.ticketSystem.Chair;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* this class test usage of Chair Class
*
* @author Soroush Mehraban
* @version 1.0.0
*
*/
public class ChairTest {
static Chair chair;
static Chair chair2;
static Chair chair3;
@BeforeAll
public static void createChair(){
chair = new Chair(23,"First Class");
chair2 = new Chair(31,"Economic Class");
chair3 = new Chair(42,"Business Class");
}
@Test
@DisplayName("Check Chair Number")
public void checkGetChairNumber(){
assertEquals(23,chair.getChairNumber());
assertEquals(31,chair2.getChairNumber());
assertEquals(42,chair3.getChairNumber());
}
@Test
@DisplayName("Check Chair Type")
public void checkGetChairType(){
assertEquals("First Class",chair.getChairType());
assertEquals("Economic Class",chair2.getChairType());
assertEquals("Business Class",chair3.getChairType());
}
}
package test;
import com.ticketSystem.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class CustomerTest {
static Customer customer;
static Airline airline;
private static Flight flight;
private static Date date;
private static Airplane airplane;
static Chair chair;
@BeforeAll
static void createCustomer(){
airline = new Airline();
date = new Date("4.23.2019","7:30PM");
airplane = new Airplane("Boeing-757","IranAir");
chair = new Chair(23,"First Class");
airplane.addChair(chair);
flight = new Flight(date,"Tehran","Mashhad",airplane,3);
airline.addFlight(flight);
customer = new Customer("Soroush","Mehraban",123, airline);
}
@Test
@DisplayName("Adding ticket test")
void addingTicketTest(){
customer.addFlight(flight);
customer.addTicket(flight,23,4,true);
Ticket ticket = new Ticket(23,flight.getFlightNumber(), 4,true);
Ticket[] customerTickets = customer.getTickets().toArray(new Ticket[customer.getTickets().size()]);
assertEquals(customerTickets[0].getAmountOfBaggage(), ticket.getAmountOfBaggage());
assertEquals(customerTickets[0].isFoodReserve(), ticket.isFoodReserve());
assertEquals(customerTickets[0].getFlightNumber(), ticket.getFlightNumber());
assertEquals(customerTickets[0].getChairNumber(), ticket.getChairNumber());
}
}
package test;
import com.ticketSystem.Airplane;
import com.ticketSystem.Date;
import com.ticketSystem.Flight;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* this class test usage of Flight Class
*
* @author Soroush Mehraban
* @version 1.0.0
*
*/
public class FlightTest {
private static Flight flight;
private static Date date;
private static Airplane airplane;
@BeforeAll
static void createFlight(){
date = new Date("4.23.2019","7:30PM");
airplane = new Airplane("Boeing-757","IranAir");
flight = new Flight(date,"Tehran","Mashhad",airplane,3);
}
@Test
@DisplayName("Test Date and Time")
void getDateTest(){
assertEquals("4.23.2019",flight.getDateAndTime().getDate());
assertEquals("7:30PM",flight.getDateAndTime().getTime());
}
@Test
@DisplayName("Origin and destination test")
void getOriginAndDestinationTest(){
assertEquals("Tehran",flight.getOrigin());
assertEquals("Mashhad",flight.getDestination());
}
@Test
@DisplayName("Type and Airline and flight number test")
void getTypeAndAirlineAndFlightNumberTest(){
assertEquals("Boeing-757",flight.getAirplaneType());
assertEquals("IranAir",flight.getAirplaneAirline());
assertEquals(3,flight.getFlightNumber());
}
}
package test;
import com.ticketSystem.Ticket;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TicketTest {
private static Ticket ticket;
@BeforeAll
public static void createTicket(){
ticket = new Ticket(32,3,1,true);
}
@Test
@DisplayName("Test method getters")
void getterMethodTest(){
assertEquals(32,ticket.getChairNumber());
assertEquals(3,ticket.getFlightNumber());
assertEquals(1,ticket.getAmountOfBaggage());
assertEquals(true,ticket.isFoodReserve());
}
}
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