Commit 119547e1 authored by 9731001's avatar 9731001

files

parents
Pipeline #565 failed with stages
package com.company;
import java.util.ArrayList;
public class Airplain {
private ArrayList<Seat> seats = new ArrayList<Seat>();
private String airplaineKind;
public Airplain(String airplaineKind){
this.airplaineKind = airplaineKind;
}
public String getAirplaineKind(){
return airplaineKind;
}
public void setSeat(Seat seat) {
seats.add(seat);
}
public ArrayList<Seat> getSeats(){
return seats;
}
}
package com.company;
import java.util.ArrayList;
/**
* This class is used by custome rto check the flights and their seats and reserving a seat
* @author Seyedeh Fatemeh Ahmadzadeh
* @version 1.0
* @since 2019 - 3 - 5
*/
public class Customer {
private int ID;
private int balance;
private Operator operator;
public Customer(int ID , Operator operator){
this.ID = ID;
balance = 0;
this.operator = operator;
}
/**
* Increases the balance of the customer
* @param balance is the amount of increased balanced
*/
public void addBalance(int balance){
this.balance += balance;
}
/**
* Returns the ID of this customer
* @return ID of the customer
*/
public int getID(){
return ID;
}
/**
* Shows all available flights
*/
public void checkFlights(){
ArrayList<Flight> flights = operator.getFlights();
for(Flight f : flights){
System.out.println("date : "+f.getDate()+" time : "+f.getTime()+" destination : "+f.getDestination()+" airline : "+f.getAirline()+" airplaine kind : "+f.getAirplaineKind()+" flight number : "+f.getFlightNo());
}
}
/**
* Shows all seats and empty seats of the flight that customer has selected.
* @param flightNo the number of flight selected by the customer
*/
public void selectFlight(int flightNo){
for(Flight f : operator.getFlights()){
if(f.getFlightNo() == flightNo){
System.out.println("all seats : ");
for(Seat s : f.getAllseats()){
System.out.println("seat number : "+s.getSeatNumber()+" seat kind : "+s.getSeatKind());
}
System.out.println("empty seats : ");
for(Seat s : f.getEmptyTseats()){
System.out.println("seat number : "+s.getSeatNumber()+" seat kind : "+s.getSeatKind());
}
}
}
}
/**
* Reserves a seat in the selected flight for the customer and makes a ticket
* @param flightNo the number of selected flight
* @param seatNo the number of selected seat
* @param weight the weight of the customers baggage
* @param cost the price of the ticket
* @param food shows if the customer wants food or no
*/
public Ticket reserve(int flightNo , int seatNo , int weight , int cost , boolean food){
Flight flight = null;
for(Flight f : operator.getFlights()){
if(f.getFlightNo() == flightNo) {
flight = f;
break;
}
}
Seat seat = null;
for(Seat s : flight.getEmptyTseats()){
if(s.getSeatNumber() == seatNo) {
s.setReserveCondition("reserved");
flight.setSeats(seatNo);
seat = s;
break;
}
}
Ticket ticket = new Ticket(weight , cost , flight , food , seat , this);
balance -= cost;
return ticket;
}
/**
* Returns the balance of the customer
* @return balance of the customer
*/
public int getBalance(){
return balance;
}
}
package com.company;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class CustomerTest {
static Operator operator = new Operator();
static Customer customer = new Customer(1212 , operator);
@BeforeAll
public void creatCustomer(){
operator = new Operator();
int ID = 1212;
customer = new Customer(ID , operator);
}
@Test
public void testGetBalance(){
operator = new Operator();
int ID = 1212;
customer = new Customer(ID , operator);
assertEquals(0 , customer.getBalance());
}
@Test
public void testAddBalance(){
operator = new Operator();
int ID = 1212;
customer = new Customer(ID , operator);
customer.addBalance(1000);
assertEquals(1000 , customer.getBalance());
}
@Test
public void testGetID(){
operator = new Operator();
int ID = 1212;
customer = new Customer(ID , operator);
assertEquals(1212 , customer.getID());
}
@Test
public void testReserve(){
operator = new Operator();
int ID = 1212;
customer = new Customer(ID , operator);
Seat seat = new Seat("common" , 12);
Airplain airplain = new Airplain("booing");
airplain.setSeat(seat);
Flight flight = new Flight("98,3,1" , "15" , 123 , "Tehran" , "Boushehr" , airplain , "gheshmair");
operator.addFlight(flight);
assertEquals(123 , customer.reserve(123 , 12 , 20 , 300 , true).getFlightNo());
}
}
package com.company;
import java.util.ArrayList;
/**
* This class shows a flights with all of its properties
* @author Seyedeh Fatemeh Ahmadzadeh
* @version 1.0
* @since 2019 - 3 - 5
*/
public class Flight {
private String date;
private String time;
private int flightNo;
private String source;
private String destination;
private Airplain airplain;
private ArrayList<Seat> allseats = new ArrayList<Seat>();
private ArrayList<Seat> emptyTseats = new ArrayList<Seat>();
private String airline;
public Flight(String date , String time , int flightNo , String source , String destination , Airplain airplain , String airline){
this.date = date;
this.time = time;
this.flightNo = flightNo;
this.destination = destination;
this.source = source;
this.airplain = airplain;
this.airline = airline;
for(Seat s : airplain.getSeats()){
allseats.add(s);
emptyTseats.add(s);
s.setReserveCondition("empty");
}
}
/**
* This method is used for reserving a seat and remove that seat from the list of empty seats of the flight.
* @param seatNum is number of the seat that a customer wants to reserve.
*/
public void setSeats(int seatNum){
for(Seat s : allseats){
if(s.getSeatNumber() == seatNum){
emptyTseats.remove(s);
break;
}
}
}
/**
* This method is used to know the flight number in other classes.
* @return the number of flight.
*/
public int getFlightNo(){
return flightNo;
}
/**
* This method is used to know the flight time in other classes.
* @return the time of the flight.
*/
public String getTime(){
return time;
}
/**
* This method is used to know the flight date in other classes.
* @return the date of the flight.
*/
public String getDate(){
return date;
}
/**
* This method is used to know destination in other classes.
* @return the destination of the flight.
*/
public String getDestination(){
return destination;
}
/**
* This method is used to know the flight source in other classes.
* @return the source of the flight.
*/
public String getSource(){
return source;
}
/**
* This method is used to know the seats of this of this flight in other classes.
* @return all of the seats of this flight
*/
public ArrayList<Seat> getAllseats(){
return allseats;
}
/**
* This method is used to know the empty seats of this of this flight in other classes.
* @return the empty seats of this flight.
*/
public ArrayList<Seat> getEmptyTseats(){
return emptyTseats;
}
/**
* This method is used to know the type of airplane of this flight in other classes.
* @return the type of airplane of this flight.
*/
public String getAirplaineKind(){
return airplain.getAirplaineKind();
}
/**
* This method is used to know the flight airline in other classes.
* @return the flight airline.
*/
public String getAirline(){
return airline;
}
}
//package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
}
}
package com.company;
import java.util.ArrayList;
/**
*This class is used by the company for adding new airplanes to the system or adding and removing flights.
* @author Seyedeh Fatemeh Ahmadzadeh
* @version 1.0
* @since 2019 - 3 - 5
*/
public class Operator {
private ArrayList<Flight> flights = new ArrayList<Flight>();
private ArrayList<Airplain> airplains = new ArrayList<Airplain>();
/**
* Makes a new flight and then add it to the list of flights
* @param date the date of the flight
* @param time the time of the flight
* @param flightNo the number of the flight
* @param source the source of the flight
* @param destination the destination of the flight
* @param airplain the airplane of the flight
* @param airline the airline of the flight
*/
public void addFlight(String date , String time , int flightNo , String source , String destination , Airplain airplain , String airline){
Flight f = new Flight(date , time , flightNo , source , destination , airplain , airline);
flights.add(f);
}
/**
* Another way for adding a flight.
* @param flight the new flight.
*/
public void addFlight(Flight flight){
flights.add(flight);
}
/**
* This method adds a new airplane to the system.
* @param airplaneKind is the type of new airplane
*/
public void addAirplaine(String airplaneKind){
Airplain a = new Airplain(airplaneKind);
airplains.add(a);
}
/**
* This method is used when we have added a new airplane and we want to set and specify its seats.
* @param seatKind is the type of the seat
* @param seatNumber is the number of the seat
* @param airplane is the new airplane that we have added recently.
*/
public void addSeat(String seatKind , int seatNumber , Airplain airplane){
Seat s = new Seat(seatKind , seatNumber);
for(Airplain a : airplains){
if(a.equals(airplane)) {
a.setSeat(s);
break;
}
}
}
/**
* Another way to add an airplane to the system
* @param airplain the new airplane
*/
public void addAirplane(Airplain airplain){
airplains.add(airplain);
}
/**
* This method is used to check the flights in other classes.
* @return all available flights
*/
public ArrayList<Flight> getFlights(){
return flights;
}
/**
* Returns an array list of all the airplanes
* @return the array list of airplanes
*/
public ArrayList<Airplain> getAirplains(){
return airplains;
}
/**
* Removes a cancelled flight from the list of flights.
* @param flight is the cancelled flight
*/
public void removeFlight(Flight flight){
for(Flight f : flights){
if(f.equals(flight)){
flights.remove(flight);
break;
}
}
}
}
package com.company;
import org.junit.Test;
import static org.junit.Assert.*;
public class OperatorTest {
@Test
public void testAddFlight(){
Airplain airplain = new Airplain("booing");
Flight flight = new Flight("98,3,1" , "15:30" , 11 , "Tehran" , "Ahvaz" , airplain , "homa");
Operator operator = new Operator();
operator.addFlight(flight);
assertNotNull(operator.getFlights());
}
@Test
public void testAddAirplane(){
Airplain airplain = new Airplain("booing");
Seat seat = new Seat("common" , 1);
Seat seat2 = new Seat("common" , 2);
airplain.setSeat(seat);
airplain.setSeat(seat2);
Operator operator = new Operator();
operator.addAirplane(airplain);
assertNotNull(operator.getAirplains());
}
@Test
public void testRemoveFlight(){
Airplain airplain = new Airplain("booing");
Flight flight = new Flight("98,3,1" , "15:30" , 11 , "Tehran" , "Ahvaz" , airplain , "homa");
Operator operator = new Operator();
operator.addFlight(flight);
operator.removeFlight(flight);
assertEquals(0 , operator.getFlights().size());
}
}
package com.company;
public class Seat {
private String seatKind;
private int seatNumber;
private String reserveCondition;
public Seat(String seatKind , int seatNumber){
this.seatKind = seatKind;
this.seatNumber = seatNumber;
reserveCondition = "empty";
}
public String getSeatKind(){
return seatKind;
}
public int getSeatNumber(){
return seatNumber;
}
public String getReserveCondition(){
return reserveCondition;
}
public void setReserveCondition(String reserveCondition){
this.reserveCondition = reserveCondition;
}
}
package com.company;
/**
*By this class makes a ticket for customer when a seat is reserved
* @author Seyedeh Fatemeh Ahmadzadeh
* @version 1.0
* @since 2019 - 3 - 5
*/
public class Ticket {
private int flightNo;
private int seatNo;
private Customer customer;
private int cost;
private int weight;
private Boolean food;
public Ticket(int weight , int cost , Flight flight , Boolean food , Seat seat , Customer customer){
flightNo = flight.getFlightNo();
this.cost = cost;
this.weight = weight;
this.food = food;
seatNo = seat.getSeatNumber();
this.customer = customer;
}
public int getFlightNo(){
return flightNo;
}
public int getSeatNo(){
return seatNo;
}
public int getCustomerID(){
return customer.getID();
}
}
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