佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1045|回复: 5

关于java array 和 method 的问题

[复制链接]
发表于 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, 6-10 for non smoking section
2. 要passenger enter 是否要在飞机上吸烟?(10年前合法的)
3. 如果其中一个section满了, 问客人是否要去隔壁section, 如果客人不要, 请他等3hours for next flight, vice versa
  1. import javax.swing.JOptionPane;

  2. public class AARS {
  3. public static void main(String []args) {
  4. final int ARRAY_LENGTH = 10;
  5. int []array = new int [10];

  6. for(int sysLimit = 0; sysLimit < 9; sysLimit++){
  7. int IM = inputMessage();

  8. seatSelection(IM, array);


  9. if(sysLimit == 9){
  10. JOptionPane.showMessageDialog(null, "**The Flight was Full**\n"
  11. +"Next flight is 3 hours later\n"
  12. +"Have a nice day",
  13. "AARS",
  14. JOptionPane.INFORMATION_MESSAGE );
  15. System.exit(0);
  16. }
  17. }//end for
  18. System.exit(0);
  19. }// end main

  20. /* inputMessage Method */
  21. public static int inputMessage(){
  22. String smoke;
  23. int smokeType;

  24. smoke = JOptionPane.showInputDialog("Welcome to Airline Automated Reservations System\n"
  25. +"lease answer the following question\n"
  26. +"Choose 1 for "Smoking" \n"
  27. +"Choose 2 for "Non Smoking" ";
  28. smokeType = Integer.parseInt(smoke);

  29. if(smokeType == 1 || smokeType == 2)
  30. return smokeType;
  31. else{
  32. JOptionPane.showMessageDialog(null, "Sorry, you only can enter either 1 or 2\n"
  33. +"lease try again", "AARS", JOptionPane.WARNING_MESSAGE);
  34. inputMessage();
  35. return 0;
  36. }
  37. }

  38. /* seatSelection Method*/
  39. public static void seatSelection( int IM , int array[]){
  40. if( IM == 1){
  41. for(int counter = 0; counter < 5; counter++){
  42. if(array[counter] == 0){
  43. array[counter] =1;
  44. JOptionPane.showMessageDialog(null, "You admission had been approval\n"
  45. +"lease go to SMOKING SECTION\n"
  46. +"Your seat is Seat " +(counter + 1),
  47. "AARS",
  48. JOptionPane.INFORMATION_MESSAGE );
  49. break;
  50. }
  51. else if(array[4] == 1){
  52. String sorryMessage;

  53. sorryMessage = JOptionPane.showInputDialog("******* SORRY *******\n"
  54. +"Sorry, this SMOKING SECTION was full\n"
  55. +"Do you want to change to next secion\n"
  56. +"If yes please choose 1\n"
  57. +"If no please choose 2\n"
  58. +"******* SORRY *******" );
  59. int SM = Integer.parseInt(sorryMessage);

  60. if(SM == 1){
  61. JOptionPane.showMessageDialog(null, "We will transfer u to the next section, thank you for ur co-operation", "Airline Automated Reservations System", JOptionPane.INFORMATION_MESSAGE);
  62. seatSelection(2, array);
  63. }
  64. else{
  65. JOptionPane.showMessageDialog(null, "**Admission Failed**\n"
  66. +"Next flight is 3 hours later\n"
  67. +"Have a nice day",
  68. "AARS",
  69. JOptionPane.INFORMATION_MESSAGE );
  70. }
  71. }
  72. else {
  73. continue;
  74. }
  75. }// end for
  76. }// end if
  77. else{
  78. for(int counter = 5; counter < 10; counter++){
  79. if(array[counter] == 0){
  80. array[counter] =1;
  81. JOptionPane.showMessageDialog(null, "You admission had been approval\n"
  82. +"lease go to NON SMOKING SECTION\n"
  83. +"Your seat is Seat " +(counter + 1),
  84. "AARS",
  85. JOptionPane.INFORMATION_MESSAGE );
  86. break;
  87. }
  88. else if(array[9] == 1){
  89. String sorryMessage;

  90. sorryMessage = JOptionPane.showInputDialog("******* SORRY *******\n"
  91. +"Sorry, this NON SMOKING SECTION was full\n"
  92. +"Do you want to change to next secion\n"
  93. +"If yes please choose 1\n"
  94. +"If no please choose 2\n"
  95. +"******* SORRY *******" );
  96. int SM = Integer.parseInt(sorryMessage);

  97. if(SM == 1){

  98. JOptionPane.showMessageDialog(null, "We will transfer u to the next section, thank you for ur co-operation", "Airline Automated Reservations System", JOptionPane.INFORMATION_MESSAGE);
  99. seatSelection(1, array);
  100. }
  101. else{
  102. JOptionPane.showMessageDialog(null, "**Admission Failed**\n"
  103. +"Next flight is 3 hours later\n"
  104. +"Have a nice day",
  105. "AARS",
  106. JOptionPane.INFORMATION_MESSAGE );
  107. }
  108. }
  109. else{
  110. continue;
  111. }
  112. }// end for
  113. }// end if
  114. }
  115. }
复制代码
请各位大大帮我检查code
code需要很厉害运用array和method
code有问题吗?
我的method很weak, 大大可以教我充分运用method吗?
大大可以教我正确的pattern吗?
step可以在简略吗?
有什么意见请告诉我, 小弟愿意听

[ 本帖最后由 晨天 于 11-7-2008 10:58 PM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 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 | 显示全部楼层
谢谢大大

原帖由 winmxaa 于 9-7-2008 11:45 PM 发表
try {
            smokeType = Integer.parseInt(smoke);            
        }
        catch (Exception e) {
            errorMessage();
            return inputMessage();            
        }        


这个 try&catch是什么东西, 我还是新手

erm
我总是觉得我的method flow有问题, 可是我又找不到, 各位大大可以帮忙吗???
回复

使用道具 举报

发表于 12-7-2008 11:55 AM | 显示全部楼层
原帖由 晨天 于 11-7-2008 10:58 PM 发表
谢谢大大



这个 try&catch是什么东西, 我还是新手

erm
我总是觉得我的method flow有问题, 可是我又找不到, 各位大大可以帮忙吗???


try catch 是要来抓exception 的,
比如input 字母,字母不能转换成号码,酱就有error 了。
flow 有问题?
我觉得有点乱而已!
把你要做的东西,放进method里,酱就不会乱了!
回复

使用道具 举报

 楼主| 发表于 12-7-2008 01:23 PM | 显示全部楼层
原帖由 winmxaa 于 12-7-2008 11:55 AM 发表


try catch 是要来抓exception 的,
比如input 字母,字母不能转换成号码,酱就有error 了。
flow 有问题?
我觉得有点乱而已!
把你要做的东西,放进method里,酱就不会乱了!


oh谢谢
对!就是乱
你任为我应该怎样改
回复

使用道具 举报

Follow Us
您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 27-12-2025 07:36 AM , Processed in 0.104846 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表