(航空訂票系統(tǒng))一家小型航空公司剛購買一臺計算機衣陶,用于其最新的自動訂票系統(tǒng)德挣,要求編寫新的程序内狗,為該公司唯一一架飛機(運量:10
)的每次飛行安排座位啦膜,程序應(yīng)當顯示下列選項:
Please type 1 for "smoking"(吸煙區(qū)請安1)
Please type 2 for "nonsmoking"(無煙區(qū)請安2)
如果某人按下1,那么程序應(yīng)當在吸煙艙(1——5)為其分配一個座位胃榕。如果某人按下2盛险,那么程序應(yīng)當在無煙艙為其分配一個座位(6——10)。在
程序中應(yīng)打印出一張登記卡勋又,以表明此人的座號以及他在飛機的吸煙艙還是無煙艙苦掘。用一個單下標數(shù)組描述飛機的訂票情況,將所有的數(shù)組元素初始
化為0楔壤,表明所有座位都是空的鹤啡。在分配一個座位后,設(shè)置數(shù)組的相應(yīng)元素為1蹲嚣,則該座位不能再分配递瑰,
程序中當然不應(yīng)分配已分配的座位。當吸煙艙客滿后程序應(yīng)當詢問此人是否接受安排的無煙區(qū)端铛,反之亦然泣矛。如果回答肯定,那么應(yīng)當進行適當?shù)淖?/p>
安排禾蚕。如果回答否定您朽,那么打印消息“Next flight leaves in 3 hours.”(下次航班三小時后起飛)。
public class lian3 {
static int[] site = new int[10];
public static int xiyanqu(){
for (int i = 0; i < 5; i++) {
if (site[i] == 0) {
site[i] = 1;
System.out.println("您的座位號是:吸煙區(qū)" + (i + 1) + "號");
return (i+1);
}
}
return 0;
}
public static int wuyanqu(){
for (int j = 5; j < 10; j++) {
if (site[j] == 0) {
site[j] = 1;
System.out.println("您的座位號是:無煙區(qū)" + (j + 1) + "號");
return (j+1);
}
}
return 0;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true){
System.out.println("歡迎來到航空公司選票系統(tǒng)");
System.out.println("吸煙區(qū)請選1 换淆,無煙區(qū)請選2");
int choice = scanner.nextInt();
if (choice == 1) {
int sitenum = xiyanqu();
if (sitenum == 0){
System.out.println("吸煙區(qū)已滿哗总,是否接受無煙區(qū)");
String input = scanner.next();
if (input.equals("是")){
int siteno =wuyanqu();
if (siteno == 0){
System.out.println("飛機座位已滿,下次航班三小時后起飛");
}
}
else {
System.out.println("下次航班三小時后起飛");
}
}
}
else {
int sitenum = wuyanqu();
if (sitenum == 0){
System.out.println("無煙區(qū)已滿倍试,是否接受吸煙區(qū)");
String input = scanner.next();
if (input.equals("是")){
int siteno =xiyanqu();
if (siteno == 0){
System.out.println("飛機座位已滿讯屈,下次航班三小時后起飛");
}
}
else {
System.out.println("下次航班三小時后起飛");
}
}
}
}
}
}