⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flightschedular.java

📁 航空定票系统:户端功能模块:用户登录模块
💻 JAVA
字号:
package com.tarena.abs.model;

import java.util.*;
import java.io.Serializable;
/**航班计划类用来描述一个航班计划,该类不包含具体的航班日期,
 * 只给一个周计划表。
 */
public class FlightSchedular implements Serializable{
	private String number;//航班号
	private String fromAdd;//出发地
	private String toAdd;//目的地
	private MyDate startDate;
	private MyDate endDate;
	private MyTime fromTime;//起飞时间
	private MyTime toTime;//到达时间
	private int length;//总里程
	private PlaneModel plane;//执行机型
	private int schedular;//周计划表
	private int totalPrice;//全价
	private static final long serialVersionUID = 585764319801237L;
	/**
	 * 构造方法,该构造方法通过属性来构造航班计划对象。
	 */
	public FlightSchedular( String number,String fromAdd, String toAdd,
			MyDate startDate,MyDate endDate,MyTime fromTime, MyTime toTime,
			int length, PlaneModel plane, int schedular,  int price) {
		this.number = number;
		this.fromAdd = fromAdd;
		this.toAdd = toAdd;
		this.startDate=startDate;
		this.endDate=endDate;
		this.fromTime = fromTime;
		this.toTime = toTime;
		this.length = length;
		this.setPlane(plane);
		this.schedular = schedular;
		totalPrice = price;

		
	}

	public PlaneModel getPlane() {
		return plane;
	}
	/**
	 * 该方法负责为航班计划设置执行的飞机机型,该方法检查机型的最大航程
	 * 是否大于航班的里程。
	 * @return void
	 */
	public void setPlane(PlaneModel plane) {
		if(plane.getMaxLine()>this.length){
			this.plane =plane;
		}
		else{
			System.out.println("不能将此型号飞机设为本航班的执行飞机!");
			System.out.println("飞机型号:"+plane.getModel()+"  最大续飞里程:"+plane.getMaxLine());
			System.out.println("航班编号:"+this.number+"  航班里程:"+this.length);
		}
	}
	

	public String getFromAdd() {
		return fromAdd;
	}
	public MyTime getFromTime() {
		return fromTime;
	}
	public int getLength() {
		return length;
	}
	public String getNumber() {
		return number;
	}

	public String getToAdd() {
		return toAdd;
	}
	public int getTotalPrice() {
		return totalPrice;
	}
	public MyTime getToTime() {
		return toTime;
	}
	public int getSchedular() {
		return schedular;
	}
	public void setSchedular(int schedular) {
		this.schedular = schedular;
	}
	
	public MyDate getEndDate() {
		return endDate;
	}

	public MyDate getStartDate() {
		return startDate;
	}

	/**
	 * 该方法用来判断某天是否有航班。
	 * @param day WeekDay对象,用来代表一周的某一天。
	 * @return 如果周
	 */
	public boolean hasFlight(WeekDay day){
		int flag=0;
		flag=this.schedular & (1<<day.getDay()-1);
		return flag!=0;
	}
	public boolean hasFlight(int day){
		return (this.schedular & (1<<day-1))!=0;
	}
	public boolean hasFlight(MyDate date){
		return (this.schedular &(1<<date.get(Calendar.DAY_OF_WEEK)-1))!=0;
	}
	/**
	 * 该方法用来生成一个当前航班计划下的航班对象。通过两个参数来确定
	 * 航班,日期(MyDate date)和折扣(double off)。
	 * @param date
	 * @param off
	 * @return 返回一个Flight对象或返回null
	 */
	public Flight createNewFlight(MyDate date,double off){
		if(hasFlight(date)){
			MyDate tmp=(MyDate)date.clone();
			return this.new Flight(tmp,off);
		}
		else{
			System.out.println("对不起,日期与航班计划的班期不符");
			return null;
		}
	}
	/**
	 * 仅通过date来生成一个航班对象并返回。
	 * @param date
	 * @return
	 */
	public Flight createNewFlight(MyDate date){
		return createNewFlight(date,1.0);
	}
	/**
	 * 覆盖的equals方法,认为当两个航班计划对象
	 * 的航班号相同的时候,这两个对象就相同。
	 */
	public boolean equals(Object o){
		if(o instanceof FlightSchedular){
			FlightSchedular fs=(FlightSchedular)o;
			return fs.number.equalsIgnoreCase(this.number);
		}
		return false;
	}
	/**
	 * 覆盖的hashCode方法,返回航班计划对象的航班号的hashCode().
	 */
	public int hashCode(){
		return number.hashCode();
	}
	/**
	 * 返回该航班计划下的某段时间内的所有航班的集合。
	 * @param start
	 * @param end
	 * @return
	 */
	public HashSet<Flight> allFlightSet(MyDate start,MyDate end){
		HashSet<Flight> hs=new HashSet<Flight>();
		MyDate day;
		for(day=start;day.compareTo(end)<=0;day.add(Calendar.DAY_OF_MONTH,1)){
			if(hasFlight(day)){
				hs.add(this.createNewFlight(day));
			}
		}
		return hs;
	}
	public HashSet<Flight> allFlightSet(){
		return allFlightSet(this.startDate,this.endDate);
	}
	/**
	 * 返回该航班计划下的某段时间的所有航班的集合,并按航班的日期来排序。
	 * @param start
	 * @param end
	 * @return
	 */
	public TreeSet<Flight> allFightSorted(MyDate start,MyDate end,Comparator<Flight> com){
		TreeSet<Flight> ts=new TreeSet<Flight>(com);
		ts.addAll(allFlightSet(start,end));
		return ts;
	}
	public TreeSet<Flight> allFightSorted(Comparator<Flight> com){
		TreeSet<Flight> ts=new TreeSet<Flight>(com);
		ts.addAll(allFlightSet());
		return ts;
	}
	/**
	 * Flight类是一个内部类,用来描述一个确定日期的航班对象。
	 * @author tony.tang
	 *
	 */
	public class Flight implements Comparable{
		private FlightSchedular schedular;//航班所属的航班计划。
		private MyDate date;//航班的日期。
		private int remainSeat;//航班的剩余座位数
		private double priceOff;//航班的折扣
		/**
		 * 构造方法,使用一个日期和一个折扣值来构造一个航班对象。
		 * 该航班对象使用外部类的当前对象作为其航班计划属性。
		 * @param date
		 * @param off
		 */
		private Flight(MyDate date,double off){
			this.date=date;
			this.priceOff=off;
			this.schedular=FlightSchedular.this;
			this.remainSeat=this.schedular.getPlane().getMaxSeat();
		}
		/**
		 * 实现的compareTo方法,用来比较两个航班对象的大小,
		 * @param 
		 * @return
		 */
		public int compareTo(Object o){
			Flight f=(Flight)o;
			return this.date.compareTo(f.date);
		}
		/**
		 * 覆盖的equals方法,当两个航班对象的航班计划和日期都相同时,它们相同。
		 */
		public boolean equals(Object o){
			if(o instanceof Flight){
				Flight f=(Flight)o;
				return (f.schedular.equals(this.schedular) && 
						f.date.equals(this.date));
			}
			return false;
		}
		/**
		 * 覆盖的hashCode方法。
		 */
		public int hashCode(){
			return this.date.hashCode()^this.schedular.hashCode();
		}
		public String toString(){
			return this.schedular.number+":"+this.date;
		}
		public double getPriceOff() {
			return priceOff;
		}
		public void setPriceOff(double priceOff) {
			this.priceOff = priceOff;
		}
		public FlightSchedular getSchedular() {
			return schedular;
		}
		public Calendar getDate() {
			return date;
		}
		public int getRemainSeat() {
			return remainSeat;
		}
		public void setRemainSeat(int remainSeat) {
			this.remainSeat = remainSeat;
		}
	}//Flight类结束
}//FlightSchedular类结束。















⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -