|
查看: 1045|回复: 5
|
关于java array 和 method 的问题
[复制链接]
|
|
|
java-AARS code在第一楼, 请帮我检查
大家好
我在做Airline Automated Reservation System(AARS)
是college year 1 的Assignment啦, 不是真的
这个AARS,
1. 飞机只有10 seat,1-5 for smoking section, 6-10 for non smoking section
2. 要passenger enter 是否要在飞机上吸烟?(10年前合法的)
3. 如果其中一个section满了, 问客人是否要去隔壁section, 如果客人不要, 请他等3hours for next flight, vice versa- import javax.swing.JOptionPane;
- public class AARS {
- public static void main(String []args) {
- final int ARRAY_LENGTH = 10;
- int []array = new int [10];
- for(int sysLimit = 0; sysLimit < 9; sysLimit++){
- int IM = inputMessage();
- seatSelection(IM, array);
- if(sysLimit == 9){
- JOptionPane.showMessageDialog(null, "**The Flight was Full**\n"
- +"Next flight is 3 hours later\n"
- +"Have a nice day",
- "AARS",
- JOptionPane.INFORMATION_MESSAGE );
- System.exit(0);
- }
- }//end for
- System.exit(0);
- }// end main
- /* inputMessage Method */
- public static int inputMessage(){
- String smoke;
- int smokeType;
- smoke = JOptionPane.showInputDialog("Welcome to Airline Automated Reservations System\n"
- +"lease answer the following question\n"
- +"Choose 1 for "Smoking" \n"
- +"Choose 2 for "Non Smoking" ";
- smokeType = Integer.parseInt(smoke);
- if(smokeType == 1 || smokeType == 2)
- return smokeType;
- else{
- JOptionPane.showMessageDialog(null, "Sorry, you only can enter either 1 or 2\n"
- +"lease try again", "AARS", JOptionPane.WARNING_MESSAGE);
- inputMessage();
- return 0;
- }
- }
- /* seatSelection Method*/
- public static void seatSelection( int IM , int array[]){
- if( IM == 1){
- for(int counter = 0; counter < 5; counter++){
- if(array[counter] == 0){
- array[counter] =1;
- JOptionPane.showMessageDialog(null, "You admission had been approval\n"
- +"lease go to SMOKING SECTION\n"
- +"Your seat is Seat " +(counter + 1),
- "AARS",
- JOptionPane.INFORMATION_MESSAGE );
- break;
- }
- else if(array[4] == 1){
- String sorryMessage;
- sorryMessage = JOptionPane.showInputDialog("******* SORRY *******\n"
- +"Sorry, this SMOKING SECTION was full\n"
- +"Do you want to change to next secion\n"
- +"If yes please choose 1\n"
- +"If no please choose 2\n"
- +"******* SORRY *******" );
- int SM = Integer.parseInt(sorryMessage);
- if(SM == 1){
- JOptionPane.showMessageDialog(null, "We will transfer u to the next section, thank you for ur co-operation", "Airline Automated Reservations System", JOptionPane.INFORMATION_MESSAGE);
- seatSelection(2, array);
- }
- else{
- JOptionPane.showMessageDialog(null, "**Admission Failed**\n"
- +"Next flight is 3 hours later\n"
- +"Have a nice day",
- "AARS",
- JOptionPane.INFORMATION_MESSAGE );
- }
- }
- else {
- continue;
- }
- }// end for
- }// end if
- else{
- for(int counter = 5; counter < 10; counter++){
- if(array[counter] == 0){
- array[counter] =1;
- JOptionPane.showMessageDialog(null, "You admission had been approval\n"
- +"lease go to NON SMOKING SECTION\n"
- +"Your seat is Seat " +(counter + 1),
- "AARS",
- JOptionPane.INFORMATION_MESSAGE );
- break;
- }
- else if(array[9] == 1){
- String sorryMessage;
- sorryMessage = JOptionPane.showInputDialog("******* SORRY *******\n"
- +"Sorry, this NON SMOKING SECTION was full\n"
- +"Do you want to change to next secion\n"
- +"If yes please choose 1\n"
- +"If no please choose 2\n"
- +"******* SORRY *******" );
- int SM = Integer.parseInt(sorryMessage);
- if(SM == 1){
- JOptionPane.showMessageDialog(null, "We will transfer u to the next section, thank you for ur co-operation", "Airline Automated Reservations System", JOptionPane.INFORMATION_MESSAGE);
- seatSelection(1, array);
- }
- else{
- JOptionPane.showMessageDialog(null, "**Admission Failed**\n"
- +"Next flight is 3 hours later\n"
- +"Have a nice day",
- "AARS",
- JOptionPane.INFORMATION_MESSAGE );
- }
- }
- else{
- continue;
- }
- }// end for
- }// end if
- }
- }
复制代码 请各位大大帮我检查code
code需要很厉害运用array和method
code有问题吗?
我的method很weak, 大大可以教我充分运用method吗?
大大可以教我正确的pattern吗?
step可以在简略吗?
有什么意见请告诉我, 小弟愿意听
[ 本帖最后由 晨天 于 11-7-2008 10:58 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 8-7-2008 09:54 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 9-7-2008 11:45 PM
|
显示全部楼层
原帖由 晨天 于 6-7-2008 11:34 PM 发表 
java-AARS code在第一楼, 请帮我检查
大家好
我在做Airline Automated Reservation System(AARS)
是college year 1 的Assignment啦, 不是真的
这个AARS,
1. 飞机只有10 seat,1-5 for smoking section, ...
加一些error handler 进去!
public static int inputMessage() {
String smoke;
int smokeType;
smoke = JOptionPane.showInputDialog("Welcome to Airline Automated Reservations System\n" + "lease answer the following question\n" + "Choose 1 for \"Smoking\" \n"
+ "Choose 2 for \"Non Smoking\" ");
if(smoke==null) {
System.exit(0);
}
try {
smokeType = Integer.parseInt(smoke);
}
catch (Exception e) {
errorMessage();
return inputMessage();
}
if (smokeType == 1 || smokeType == 2)
return smokeType;
else {
JOptionPane.showMessageDialog(null, "Sorry, you only can enter either 1 or 2\n" + "lease try again", "AARS", JOptionPane.WARNING_MESSAGE);
inputMessage();
return 0;
}
}
public static void errorMessage() {
JOptionPane.showMessageDialog(null, "Invalid number, please input again!","", JOptionPane.WARNING_MESSAGE);
} |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 11-7-2008 10:58 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 12-7-2008 11:55 AM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 12-7-2008 01:23 PM
|
显示全部楼层
原帖由 winmxaa 于 12-7-2008 11:55 AM 发表 
try catch 是要来抓exception 的,
比如input 字母,字母不能转换成号码,酱就有error 了。
flow 有问题?
我觉得有点乱而已!
把你要做的东西,放进method里,酱就不会乱了!
oh谢谢
对!就是乱
你任为我应该怎样改 |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|