Commit 74571c03 authored by Roham's avatar Roham

LAB7 PROJECT

parent 0783b80d
package Test;
import com.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class AirplaneTest {
static Airplane a;
static Flight f;
static Passenger p;
static Ticket t;
@BeforeAll
public static void createFlight() {
a = new Airplane("FC001");
f = new Flight(1, "Tehran", "Esfehan", "5/3/2019", 10, 2, "Roham Air", a);
t = new Ticket(f, 1, 1000, 50, 1);
p = new Passenger("Roham", "Zendehdel", 1);
}
@Test
void getType() {
assertEquals("FC001", a.getType());
}
@Test
void addSeat() {
a.addSeat(new Seat("Economy", 1));
assertEquals("Economy", a.getSeats().get(1).getType());
}
@Test
void getSeats() {
assertEquals("Economy", a.getSeats().get(1).getType());
}
@Test
void reserveSeat() {
assertEquals(0, a.reserveSeat(new Seat("Economy", 1)));
}
@Test
void getEmptySeats() {
assertEquals(0, a.getEmptySeats().size());
}
@Test
void getReservedSeats() {
assertEquals("Economy", a.getReservedSeats().get(1).getType());
}
}
\ No newline at end of file
package Test;
import com.Airplane;
import com.Flight;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class FlightTest {
static Airplane a;
static Flight f;
@BeforeAll
public static void createFlight() {
a = new Airplane("FC001");
f = new Flight(1, "Tehran", "Esfehan", "5/3/2019", 10, 2, "Roham Air", a);
}
@Test
void getId() {
assertEquals(1, f.getId());
}
@Test
void getSource() {
assertEquals("Tehran", f.getSource());
}
@Test
void getDestination() {
assertEquals("Esfehan", f.getDestination());
}
@Test
void getDate() {
assertEquals("5/3/2019", f.getDate());
}
@Test
void getHour() {
assertEquals(10, f.getHour());
}
@Test
void getMinute() {
assertEquals(2, f.getMinute());
}
@Test
void getCompanyName() {
assertEquals("Roham Air", f.getCompanyName());
}
@Test
void getAirplane() {
assertEquals("FC001", f.getAirplane().getType());
}
}
\ No newline at end of file
package Test;
import com.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class PassengerTest {
static Airplane a;
static Flight f;
static Passenger p;
static Ticket t;
@BeforeAll
public static void createFlight() {
a = new Airplane("FC001");
f = new Flight(1, "Tehran", "Esfehan", "5/3/2019", 10, 2, "Roham Air", a);
t = new Ticket(f, 1, 1000, 50, 1);
p = new Passenger("Roham", "Zendehdel", 1);
a.addSeat(new Seat("Economy", 1));
}
@Test
void getFirstName() {
assertEquals("Roham", p.getFirstName());
}
@Test
void getLastName() {
assertEquals("Zendehdel", p.getLastName());
}
@Test
void getId() {
assertEquals(1, p.getId());
}
@Test
void reserveTicket() {
assertEquals(1, a.getEmptySeats().size());
assertEquals(0, p.reserveTicket(t));
assertEquals(1, a.getReservedSeats().get(1).getNumber());
assertEquals("Economy", a.getReservedSeats().get(1).getType());
assertEquals(p, a.getSeats().get(1).getPassenger());
assertEquals(p, a.getReservedSeats().get(1).getPassenger());
assertEquals(0, a.getEmptySeats().size());
}
@Test
void getReservedTicket() {
assertEquals(t, p.getReservedTicket());
}
}
\ No newline at end of file
package Test;
import com.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class SeatTest {
static Seat s;
static Passenger p;
@BeforeAll
public static void createFlight() {
s = new Seat("Economy", 1);
p = new Passenger("Roham", "Zendehdel", 1);
}
@Test
void getType() {
assertEquals("Economy", s.getType());
}
@Test
void getNumber() {
assertEquals(1, s.getNumber());
}
@Test
void setPassenger() {
s.setPassenger(p);
assertEquals(p, s.getPassenger());
}
}
\ No newline at end of file
package Test;
import com.*;
import com.System;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class SystemTest {
static System system;
static Flight flight;
static Airplane airplane;
static Passenger passenger;
@BeforeAll
public static void createSystem() {
system = new System("Roham Air");
airplane = new Airplane("FC001");
flight = new Flight(1, "Tehran", "Mexico", "5/3/2019", 10, 30, "Roham Air", airplane);
passenger = new Passenger("Roham", "Zendehdel", 1);
system.addFlight(flight);
airplane.addSeat(new Seat("Economy", 1));
airplane.addSeat(new Seat("Economy", 2));
system.addPassenger(passenger);
passenger.reserveTicket(new Ticket(flight, 1, 1000, 50, 1));
}
@Test
public void testSystem() {
assertEquals(2, airplane.getSeats().size());
assertEquals("Roham", airplane.getSeats().get(1).getPassenger().getFirstName());
assertEquals(flight.getId(), passenger.getReservedTicket().getFlight().getId());
assertEquals(1, airplane.getEmptySeats().size());
assertEquals("Mexico", system.getFlights().get(0).getDestination());
system.removeFlight(flight);
assertEquals(0, system.getFlights().size());
}
}
\ No newline at end of file
package Test;
import com.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class TicketTest {
static Airplane a;
static Flight f;
static Passenger p;
static Ticket t;
@BeforeAll
public static void createFlight() {
a = new Airplane("FC001");
f = new Flight(1, "Tehran", "Esfehan", "5/3/2019", 10, 2, "Roham Air", a);
t = new Ticket(f, 1, 1000, 50, 1);
}
@Test
void getFlight() {
assertEquals(f, t.getFlight());
}
@Test
void getSeatNumber() {
assertEquals(1, t.getSeatNumber());
}
@Test
void getPrice() {
assertEquals(1000, t.getPrice());
}
@Test
void getLuggageWeight() {
assertEquals(50, t.getLuggageWeight());
}
@Test
void getFoodStatus() {
assertEquals(1, t.getFoodStatus());
}
}
\ No newline at end of file
package com;
import java.util.ArrayList;
import java.util.HashMap;
/**
* The Airplane class representing an airplane that is on the airport with it's available seats and full seats
*
* @author Roham Zendehdel
* @version 1.00, May 2019
*/
public class Airplane {
private HashMap<Integer, Seat> seats;
private HashMap<Integer, Seat> reservedSeats;
private HashMap<Integer, Seat> emptySeats;
private String type;
public Airplane(String type) {
this.type = type;
this.seats = new HashMap<>();
this.reservedSeats = new HashMap<>();
this.emptySeats = new HashMap<>();
}
public String getType() {
return type;
}
public void addSeat(Seat s) {
this.seats.put(s.getNumber(), s);
this.emptySeats.put(s.getNumber(), s);
}
/**
* Getting the full list of the airplane's seats
*
* @return list of the airplane's seats
*/
public HashMap<Integer, Seat> getSeats() {
return this.seats;
}
/**
* Reserving a seat thus making it unavailable
*
* @param s the seat that is going to be reserved
* @return 0 if reservation was successful and -1 if it wasn't
*/
public int reserveSeat(Seat s) {
if (this.reservedSeats.get(s.getNumber()) == null) {
this.reservedSeats.put(s.getNumber(), s);
this.emptySeats.remove(s.getNumber(), s);
return 0;
} else return -1;
}
/**
* Getting a list of the empty seats in the airplane
*
* @return list of empty seats
*/
public HashMap<Integer, Seat> getEmptySeats() {
return this.emptySeats;
}
/**
* Getting a list of the reserved seats in the airplane
*
* @return list of reserved seats
*/
public HashMap<Integer, Seat> getReservedSeats() {
return this.reservedSeats;
}
}
package com;
/**
* The Flight class representing the the flights that take place in an airport and the details of the flight
*
* @author Roham Zendehdel
* @version 1.00, May 2019
*/
public class Flight {
private int id;
private String source;
private String destination;
private String date;
private int hour;
private int minute;
private String companyName;
private Airplane airplane;
public Flight(int id, String source, String destination, String date, int hour, int minute, String companyName, Airplane airplane) {
this.id = id;
this.source = source;
this.destination = destination;
this.date = date;
this.hour = hour;
this.minute = minute;
this.companyName = companyName;
this.airplane = airplane;
}
/**
* Getting the id of the flight
*
* @return the id of the flight
*/
public int getId() {
return id;
}
/**
* getting the source of the flight
*
* @return source of the flight
*/
public String getSource() {
return source;
}
public String getDestination() {
return destination;
}
public String getDate() {
return date;
}
public int getHour() {
return hour;
}
public int getMinute() {
return minute;
}
public String getCompanyName() {
return companyName;
}
public Airplane getAirplane() {
return airplane;
}
}
package com;
/**
* The Passenger class representing the the passengers that request tickets and decide their flights
*
* @author Roham Zendehdel
* @version 1.00, May 2019
*/
public class Passenger {
private String firstName;
private String lastName;
private int id;
private Ticket reservedTicket;
public Passenger(String firstName, String lastName, int id) {
this.firstName = firstName;
this.lastName = lastName;
this.id = id;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public int getId() {
return id;
}
public Ticket getReservedTicket() {
return reservedTicket;
}
/**
* Reserving the ticket requested by the passenger
*
* @param t the ticket that the passenger wants to reserve
*/
public int reserveTicket(Ticket t) {
int status = t.getFlight().getAirplane().reserveSeat(t.getFlight().getAirplane().getSeats().get(t.getSeatNumber()));
if (status == 0) {
t.getFlight().getAirplane().getSeats().get(t.getSeatNumber()).setPassenger(this);
this.reservedTicket = t;
}
return status;
}
}
package com;
/**
* The Seat class representing a seat in an airplane with it's id and passenger
*
* @author Roham Zendehdel
* @version 1.00, May 2019
*/
public class Seat {
private String Type;
private int number;
Passenger passenger;
public Seat(String type, int number) {
Type = type;
this.number = number;
}
public String getType() {
return Type;
}
public int getNumber() {
return number;
}
/**
* Reserving the seat for a special passenger
*
* @param passenger the passenger that is going to be identified by the seat
*/
public void setPassenger(Passenger passenger) {
this.passenger = passenger;
}
public Passenger getPassenger() {
return this.passenger;
}
}
package com;
import java.util.ArrayList;
import java.util.HashMap;
/**
* The System class represents a core system controlling all the flights and passengers
*
* @author Roham Zendehdel
* @version 1.00, May 2019
*/
public class System {
private HashMap<Integer, Flight> flights;
private HashMap<Integer, Passenger> passengers;
private String companyName;
public System(String Name) {
this.companyName = Name;
this.flights = new HashMap<>();
this.passengers = new HashMap<>();
}
/**
* Gets the flight list
*
* @return list of flights
*/
public ArrayList<Flight> getFlights() {
ArrayList<Flight> f = new ArrayList<>();
for (Flight value : flights.values()) {
f.add(value);
}
return f;
}
/**
* Adding a flight to the flight list
*
* @param f the flight that is going to get added to the flight list
*/
public void addFlight(Flight f) {
flights.put(f.getId(), f);
}
/**
* Removing a flight from the flight list
*
* @param f the requested flight that needs to be removed from the list
*/
public void removeFlight(Flight f) {
flights.remove(f.getId(), f);
}
public void addPassenger(Passenger passenger) {
this.passengers.put(passenger.getId(), passenger);
}
public ArrayList<Passenger> getPassengers() {
ArrayList<Passenger> p = new ArrayList<>();
for (Passenger value : passengers.values()) {
p.add(value);
}
return p;
}
}
package com;
/**
* The Ticket class representing a ticket with the seat number and flight id
*
* @author Roham Zendehdel
* @version 1.00, May 2019
*/
public class Ticket {
private Flight flight;
private int seatNumber;
private int price;
private int luggageWeight;
private int foodStatus;
public Ticket(Flight flight, int seatNumber, int price, int luggageWeight, int foodStatus) {
this.flight = flight;
this.seatNumber = seatNumber;
this.price = price;
this.luggageWeight = luggageWeight;
this.foodStatus = foodStatus;
}
public Flight getFlight() {
return this.flight;
}
public int getSeatNumber() {
return seatNumber;
}
public int getPrice() {
return price;
}
public int getLuggageWeight() {
return luggageWeight;
}
public int getFoodStatus() {
return foodStatus;
}
}
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