Commit 0a28a80b authored by 9731050's avatar 9731050

first

parent ec68b46a
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Lab7.iml" filepath="$PROJECT_DIR$/Lab7.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library name="JUnit5.3">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.5.0-M1/junit-jupiter-api-5.5.0-M1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.0.0/apiguardian-api-1.0.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.1.1/opentest4j-1.1.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.5.0-M1/junit-platform-commons-1.5.0-M1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.5.0-M1/junit-jupiter-api-5.5.0-M1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.0.0/apiguardian-api-1.0.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.1.1/opentest4j-1.1.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.5.0-M1/junit-platform-commons-1.5.0-M1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
\ No newline at end of file
package com.TicketManagement;
import java.util.ArrayList;
public class Airplane {
private String model;
private ArrayList<Seat>seats;
private ArrayList<Seat>freeSeats;
public Airplane(String model){
this.model=model;
seats=new ArrayList<>();
freeSeats=new ArrayList<>();
}
public String getModel() {
return model;
}
public void addSeat(Seat seat){
seats.add(seat);
freeSeats.add(seat);
}
public ArrayList<Seat> getseats(){return seats;}
public void reserveSeat(Seat seat,Passenger passenger){
if(seats.contains(seat)) {
freeSeats.remove(seat);
seat.setUser(passenger);
}
}
public ArrayList<Seat>getFreeSeats(){return freeSeats;}
}
package com.TicketManagement;
public class Flight {
private String date;
private String destination;
private String company;
private int ID;
private String source;
private Airplane model;
public Flight(String date,int ID,String destination,String source,String company,Airplane model){
this.date=date;
this.source=source;
this.company=company;
this.destination=destination;
this.ID=ID;
this.model=model;
}
public int getID() {
return ID;
}
public String getSource() {
return source;
}
public String getCompany() {
return company;
}
public Airplane getModel(){return model;}
public String getDate() {
return date;
}
public String getDestination() {
return destination;
}
}
package com.TicketManagement;
import java.util.ArrayList;
/**
* this class manages the booking flight system
*
*@author Mohammad Kazemi
*/
public class Management {
private ArrayList<Flight> flights;
public Management(){
flights=new ArrayList<Flight>();
}
/**
*
* @return all flights
*/
public ArrayList<Flight> getFlights() {
return flights;
}
/**
*takes a flight and add it to flight array list
*
* @param flight
*/
public void addFlight(Flight flight){
flights.add(flight);
}
/**
*takes an specific flight object and remove it from our flight array list
*
* @param flight
*/
public void removeFlight(Flight flight){flights.remove(flight);}
}
package com.TicketManagement;
import java.util.ArrayList;
public class Passenger {
private String name,lastname;
private int ID;
private ArrayList<Ticket> tickets;
public Passenger(String name,String lastname,int ID){
this.name=name;
this.ID=ID;
this.lastname=lastname;
tickets= new ArrayList<Ticket>();
}
public void addTicket(Ticket ticket){
tickets.add(ticket);
}
public ArrayList<Ticket> getTickets() {
return tickets;
}
public int getID() {
return ID;
}
public String getName() {
return name;
}
public String getLastname() {
return lastname;
}
}
package com.TicketManagement;
import java.util.ArrayList;
public class Seat {
private int ID;
private String type;
private Passenger user;
public Seat(int ID,String type){
this.type=type;
this.ID=ID;
}
public int getID() {
return ID;
}
public String getType() {
return type;
}
public void setUser(Passenger passenger){
user=passenger;
}
public Passenger getUser(){
return user;
}
}
package com.TicketManagement;
/**
* this class is for simulating a ticket and some related parameters
*
* @author Mohammad Kazemi
*/
public class Ticket {
private int seatNumber;
private int flightNumber;
private int cargo;
private boolean food;
public Ticket(int seatNumber,int flightNumber,int cargo){
this.flightNumber=flightNumber;
this.seatNumber=seatNumber;
this.cargo=cargo;
}
/**
* this method determines whether or not we receive a ticket for
* @param food
*/
public void food(boolean food){this.food=food;}
/**
* this method shows the amount of load
* @return amount of load(cargo)
*/
public int getCargo() {
return cargo;
}
/**
* this method is determine whether a ticket has a food
* @return true or false
*/
public boolean getFood() {
return food;
}
public int getFlightnumber() {
return flightNumber;
}
public int getSeatnumber() {
return seatNumber;
}
}
package test;
import com.TicketManagement.Airplane;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class testAirplane {
static Airplane airplane;
@BeforeAll
public static void creatairplane(){
airplane=new Airplane("abc");
}
@Test
public void testagency(){
assertEquals("abc",airplane.getModel());
}
}
package test;
import com.TicketManagement.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class testFlight {
static Flight flight;
static String date;
static Airplane airplane;
@BeforeAll
public static void creatflight()
{
airplane=new Airplane("a1");
flight=new Flight(date,1,"shiraz","yazd","homa",airplane);
}
@Test
public void testflightNumber()
{
assertEquals(1,flight.getID());
}
@Test
public void testdestenation()
{
assertEquals("shiraz",flight.getDestination());
}
@Test
public void teststart()
{
assertEquals("yazd",flight.getSource());
}
@Test
public void testAirplane()
{
assertEquals(airplane,flight.getModel());
}
@Test
public void testDate()
{
assertEquals(date,flight.getDate());
}
}
package test;
import com.TicketManagement.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class testManagement {
static Management management;
static Airplane airplane1,airplane2;
static Flight flight1,flight2,flight3;
static Seat a,b,c,d;
static Passenger passenger1,passenger2;
static Ticket ticket1,ticket2;
@BeforeAll
public static void creatManagement(){
management=new Management();
airplane1=new Airplane("c1");
airplane2=new Airplane("c2");
flight1=new Flight("2019/5/20",1,"tehran","mashad","homa",airplane1);
flight2=new Flight("2019/5/21",2,"tehran","yazd","homa",airplane2);
flight3=new Flight("2019/5/21",3,"shanghai","tehran","homa",airplane2);
management.addFlight(flight1);
management.addFlight(flight2);
management.addFlight(flight3);
a=new Seat(1,"fristClass");
b=new Seat(2,"fristClass");
c=new Seat(3,"economicClass");
d=new Seat(4,"fristClass");
airplane1.addSeat(a);
airplane2.addSeat(b);
airplane1.addSeat(c);
airplane2.addSeat(d);
passenger1=new Passenger("mohammad","kazemi",1);
passenger2=new Passenger("ali","kashani",2);
ticket1=new Ticket(1,1,10);
ticket1.food(true);
ticket2=new Ticket(2,2,100);
ticket2.food(false);
}
@Test
public void testmanagement(){
assertEquals(3,management.getFlights().size());
passenger1.addTicket(ticket1);
flight1.getModel().reserveSeat(b,passenger1);
assertEquals(2,flight1.getModel().getFreeSeats().size());
passenger2.addTicket(ticket2);
flight2.getModel().reserveSeat(b,passenger2);
assertEquals(d,flight2.getModel().getFreeSeats().get(0));
assertEquals("ali",b.getUser().getName());
assertEquals(false,passenger2.getTickets().get(0).getFood());
assertEquals(100,passenger2.getTickets().get(0).getCargo());
}
}
package test;
import com.TicketManagement.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class testPassenger {
static Ticket ticket;
static Passenger passenger;
@BeforeAll
public static void createcustomer(){
ticket=new Ticket(1,2,10);
ticket.food(true);
passenger=new Passenger("mohammad","kz",1);
}
@Test
public void testcustomergetID(){
assertEquals(1,passenger.getID());
}
@Test
public void testlastname(){
assertEquals("kz",passenger.getLastname());
}
@Test
public void testcustomername(){
assertEquals("mohammad",passenger.getName());
}
@Test
public void testaddticket(){
assertEquals(0,passenger.getTickets().size());
passenger.addTicket(ticket);
assertEquals(1,passenger.getTickets().size());
}
}
package test;
import com.TicketManagement.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class testSeat {
static Seat seat;
@BeforeAll
public static void createSeat(){
seat=new Seat(1,"fristclass");
}
@Test
public void tesTicketgetID(){
assertEquals(1,seat.getID());
}
@Test
public void testSeatgetkind(){
assertEquals("fristclass",seat.getType());
}
}
package test;
import com.TicketManagement.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class testTicket {
static Ticket ticket;
@BeforeAll
public static void createticket(){
ticket= new Ticket(1,2,10);
ticket.food(true);
}
@Test
public void testTcketgetseatnumber(){
assertEquals(1,ticket.getSeatnumber());
}
@Test
public void testTicketgetflightnumber(){
assertEquals(2,ticket.getFlightnumber());
}
@Test
public void testticketgetcargo(){
assertEquals(10,ticket.getCargo());
}
@Test
public void testTicketgetmeal(){
assertEquals(true,ticket.getFood());
}
}
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