4、航空服务查询问题:根据航线,仓位,飞行时间查询航空服务。
假设一个中国的航空公司规定:
① 中国去欧美的航线所有座位都有食物供应,每个座位都可以播放电影。
② 中国去非欧美的国外航线都有食物供应,只有商务仓可以播放电影。
③ 中国国内的航班的商务仓有食物供应,但是不可以播放电影
④ 中国国内航班的经济仓只有当飞行时间大于2小时时才有食物供应,但是不可以播放电影。
请用程序实现上述功能,并用决策表法设计测试用例,再执行测试,撰写实验报告。
实验步骤:
① 编写程序
package org.example;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class AirlineService {
private static String food = "无食物供应";
private static String movie = "无电影播放";
public static void main(String[] args) {
JFrame frame = new JFrame("航空服务选择");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 300);
frame.setLayout(new GridLayout(7, 2));
// 创建航线选择按钮组
JPanel routePanel = new JPanel();
routePanel.setLayout(new GridLayout(1, 3));
routePanel.add(new JLabel("请选择航线:"));
JRadioButton route1 = new JRadioButton("1. 欧美");
JRadioButton route2 = new JRadioButton("2. 国外非欧美");
JRadioButton route3 = new JRadioButton("3. 国内");
ButtonGroup routeGroup = new ButtonGroup();
routeGroup.add(route1);
routeGroup.add(route2);
routeGroup.add(route3);
routePanel.add(route1);
routePanel.add(route2);
routePanel.add(route3);
// 创建舱位选择按钮组
JPanel seatPanel = new JPanel();
seatPanel.setLayout(new GridLayout(1, 2));
seatPanel.add(new JLabel("请选择舱位:"));
JRadioButton seat1 = new JRadioButton("1. 商务舱");
JRadioButton seat2 = new JRadioButton("2. 经济舱");
ButtonGroup seatGroup = new ButtonGroup();
seatGroup.add(seat1);
seatGroup.add(seat2);
seatPanel.add(seat1);
seatPanel.add(seat2);
// 创建飞行时间选择按钮组
JPanel timePanel = new JPanel();
timePanel.setLayout(new GridLayout(1, 2));
timePanel.add(new JLabel("请选择飞行时间:"));
JRadioButton time1 = new JRadioButton("1. 两小时以内");
JRadioButton time2 = new JRadioButton("2. 超过两小时");
ButtonGroup timeGroup = new ButtonGroup();
timeGroup.add(time1);
timeGroup.add(time2);
timePanel.add(time1);
timePanel.add(time2);
JButton submitButton = new JButton("提交");
JButton resetButton = new JButton("重置");
JLabel foodLabel = new JLabel("食物供应:");
JLabel movieLabel = new JLabel("电影播放:");
frame.add(routePanel);
frame.add(seatPanel);
frame.add(timePanel);
frame.add(submitButton);
frame.add(resetButton);
frame.add(foodLabel);
frame.add(movieLabel);
submitButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int route = getSelectedButtonIndex(route1, route2, route3) + 1;
int seat = getSelectedButtonIndex(seat1, seat2) + 1;
int time = getSelectedButtonIndex(time1, time2) + 1;
food = "无食物供应";
movie = "无电影播放";
if (route == 1) { // 欧美航线
food = "有食物供应";
movie = "可以播放电影";
} else if (route == 2) { // 国外非欧美航线
food = "有食物供应";
if (seat == 1) { // 商务舱
movie = "可以播放电影";
}
} else if (route == 3) { // 国内航线
if (seat == 1) { // 商务舱
food = "有食物供应";
} else if (seat == 2 && time == 2) { // 经济舱且飞行时间超过两小时
food = "有食物供应";
}
}
foodLabel.setText("食物供应:" + food);
movieLabel.setText("电影播放:" + movie);
}
});
resetButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
food = "无食物供应";
movie = "无电影播放";
foodLabel.setText("食物供应:" + food);
movieLabel.setText("电影播放:" + movie);
}
});
frame.setVisible(true);
}
private static int getSelectedButtonIndex(JRadioButton... buttons) {
for (JRadioButton button : buttons) {
if (button.isSelected()) {
return buttons.indexOf(button);
}
}
return -1;
}
}
② 构造决策表
|
规则桩 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
|
航线 |
欧美 |
欧美 |
欧美 |
欧美 |
非欧 |
非欧 |
非欧 |
非欧 |
国内 |
国内 |
国内 |
国内 |
|
仓位 |
经济舱 |
商务舱 |
经济舱 |
商务舱 |
经济舱 |
商务舱 |
经济舱 |
商务舱 |
经济舱 |
商务舱 |
经济舱 |
商务舱 |
|
飞行时间 |
<2h |
<2h |
>=2h |
>=2h |
<2h |
<2h |
>=2h |
>=2h |
<2h |
<2h |
>=2h |
>=2h |
|
电影 |
1 |
1 |
1 |
1 |
0 |
1 |
0 |
1 |
0 |
0 |
0 |
0 |
|
食物 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
0 |
1 |
1 |
1 |
③ 根据决策表设计测试用例,得到测试用例表
|
欧美1,国外非欧美2,国内3;商务舱1,经济舱2;飞行时间两小时以内1,超过两小时2 |
|||
|
序号 |
输入数据 |
期望输出 |
实际输出 |
|
1 |
1,1,2 |
食物供应、播放电影 |
食物供应、播放电影 |
|
2 |
1,1,1 |
食物供应、播放电影 |
食物供应、播放电影 |
|
3 |
2,1,2 |
播放电影 |
播放电影 |
|
4 |
2,2,1 |
食物供应 |
食物供应 |
|
5 |
3,1,2 |
食物供应 |
食物供应 |
|
6 |
3,2,1 |
无 |
无 |

浙公网安备 33010602011771号