船艙訂票系統測試

2022-09-12 11:18:18 字數 4550 閱讀 9342

package com.dong.mytest.demo.other.yan;

import j**a.util.arraylist;

import j**a.util.hashmap;

import j**a.util.iterator;

import j**a.util.list;

import j**a.util.map;

public class ticketsystem

// 初始化每個船艙的資訊:id,座位列表,候補佇列

for (int i = 0; i < cabins.length; i++)

cabin cabin = new cabin();

cabin.setcabinid(i);

cabin.setseatlist(seatlist);

cabinmap.put(i, cabin);}}

/*** 從cabinid艙位中預定num個座位,訂單編號為id

*/public boolean book(int id, int cabinid, int num)

if (ordermap.containskey(id))

cabin cabin = cabinmap.get(cabinid);

// 生成訂單

ticketorder order = new ticketorder();

order.setid(id);

order.setcabinid(cabinid);

order.setnum(num);

order.setstatus(order_status_init);

ordermap.put(id, order);

// 該船艙的候補佇列

listhbqueue = cabin.gethbqueue();

// 候補隊列為空

if (hbqueue.isempty())

// 記錄訂單預定的座位列表

order.setorderseatnumlist(seatnumlist);

order.setstatus(order_status_success);

return true;

} else

} else

}/**

* 根據連續優先訂票規則,獲取座位號

*/private listcheckhascontinuousseatnum(listremainseatnumlist, int orderseatcount)

list.add(seatnum);

// 如果連續座位號達到訂票數,則直接返回

if (list.size() >= orderseatcount)

preseatnum = seatnum;

}// 走到這裡說明沒有連續的號,返回最小的幾個座位號

list.clear();

for (integer seatnum : remainseatnumlist) else

}return list;

}/**

* 取消編號為id的訂單,並及時處理候補佇列訂單

*/public boolean cancel(int id)

ticketorder order = ordermap.get(id);

cabin cabin = cabinmap.get(order.getcabinid());

boolean result = false;

// 如果該訂單已預定成功,則成功取消訂單、退票並返回true

if (order_status_success.equals(order.getstatus()))

// 候補佇列嘗試繼續買票

queueretry(cabin);

result = true;

} else if (order_status_failed.equals(order.getstatus())) else

// 修改訂單狀態

order.setstatus(order_status_cancel);

order.setorderseatnumlist(new arraylist<>());

return result;

}/**

* 候補佇列嘗試繼續買票

*/private void queueretry(cabin cabin)

// 有足夠餘票,根據連續優先訂票規則,獲取座位號

listseatnumlist = checkhascontinuousseatnum(remainseatnumlist, ticketorder.getnum());

for (integer seatnum : seatnumlist)

// 記錄訂單預定的座位列表

ticketorder.setorderseatnumlist(seatnumlist);

ticketorder.setstatus(order_status_success);

// 從佇列中移除

iterator.remove();}}

public int query(int id)

// 如果預定成功,則返回最小的座位號

return order.getorderseatnumlist().get(0);

}public static void main(string args) );

system.out.println(ticketsystem.book(71, 0, 2));

system.out.println(ticketsystem.book(73, 0, 10));

system.out.println(ticketsystem.book(72, 0, 2));

system.out.println(ticketsystem.query(72));

system.out.println(ticketsystem.book(74, 0, 2));

system.out.println(ticketsystem.cancel(73));

system.out.println(ticketsystem.query(74));

system.out.println(ticketsystem.query(72));

system.out.println(ticketsystem.cancel(72));

system.out.println(ticketsystem.book(75, 0, 3));

system.out.println(ticketsystem.query(75));

system.out.println(ticketsystem.cancel(75));

system.out.println(ticketsystem.book(76, 0, 2));

system.out.println(ticketsystem.book(77, 0, 2));

system.out.println(ticketsystem.cancel(76));

system.out.println(ticketsystem.book(78, 0, 3));

system.out.println(ticketsystem.query(78));

}}

package com.dong.mytest.demo.other.yan;

import j**a.util.arraylist;

import j**a.util.list;

public class cabin

}return remainseatnumlist;

}public int getcabinid()

public void setcabinid(int cabinid)

public listgetseatlist()

public void setseatlist(listseatlist)

public listgethbqueue()

public void sethbqueue(listhbqueue)

}

package com.dong.mytest.demo.other.yan;

import j**a.util.list;

public class ticketorder

public void setid(int id)

public int getnum()

public void setnum(int num)

public listgetorderseatnumlist()

public void setorderseatnumlist(listorderseatnumlist)

public int getstatus()

public void setstatus(int status)

public int getcabinid()

public void setcabinid(int cabinid)

}

飛機訂票系統登入測試指令碼

dim url if dialog login exist 1 then optionalstep.dialog login winedit agent name set datatable username dtglobalsheet optionalstep.dialog login wined...

航空客運訂票系統

通過此系統可以實現如下功能 錄入 可以錄入航班情況 資料可以儲存在乙個資料檔案中,資料結構 具體資料自定 查詢 可以查詢某個航線的情況 如,輸入航班號,查詢起降時間,起飛抵達城市,航班票價,票價折扣,確定航班是否滿倉 可以輸入起飛抵達城市,查詢飛機航班情況 訂票 訂票情況可以存在乙個資料檔案中,結構...

訂票系統學習五

1 日誌管理控制器 日誌管理控制器 author llq admin log controller public class logcontroller 3 獲取日誌列表 獲取日誌列表 param page param content param roleid param return value ...