无法正确计算预订金额

时间:2014-04-15 00:34:57

标签: java methods count integer

我正在尝试使用此方法计算单独文本文件中的航班预订。 我本来应该输入一个城市,这个方法应该告诉我这个城市的航班数量。

这是我第一次使用嵌套循环。 我输入“亚特兰大”这个词,它应该给我答案“3.0”。 无论我得到什么样的城市,我都会不断得到“2.0”

所以我认为我的match_count或其他什么是错的,有人可以告诉我如何才能正确计算预订吗?

         public static void city_origin(int count,String[]flight,int[]flight_number,String[]origin,String[]destination,String[]date,String[]time, int rcount, int[]fl_number)
            {
             int i, j;
             int match_count= 0;
             double total=0;
             String search_city = "";
             String output = "Enter the City from a particular flight you are searching for";
             search_city = JOptionPane.showInputDialog(null,
                                                       output, " ",
                                                       JOptionPane.QUESTION_MESSAGE);
             for (i = 0; i <=count; ++i) {
                  if(origin[i].equals(search_city))
                     {
                         System.out.println(flight[i]+" "+flight_number[i]+" "+origin[i]+" "+destination[i]+" "+date[i]+" "+time[i]);
                     }
                         //section in question
             for (j = 0; j <=rcount; ++j) {
                 if(fl_number[j] == flight_number[i])
                 {
                     total+=match_count+1;
                 }
             }
             System.out.println("The total reservations for " +search_city+ " = " +total);
             }
            }// method city_origin

        public static void exit_program()
           {
            System.out.println("Executing exit_program");
           }//method exit_program 

0 个答案:

没有答案