查找导入的变量来自何处



我正在使用Java类,并有以下示例来帮助我使我的代码运行良好,但我不能让我的代码运行。我发现问题是与strAlt,但我不能告诉strAlt在以下代码中定义的位置。使用Net beans中的调试器,我发现当它第一次在开关测试中使用strAlt被定义为字符串"03",它被转换为整数3,但我不确定字符串03来自哪里。

public class NWSFB
{
   /** A class variable containing the Station Weather */
   private String strWea ;
   /** The Constructor */
   public NWSFB(String strVar)
   {
      // this is the constructor
       strWea = strVar;
   }

public String getWindInfo(String strAlt)
{
   String strRet;
   strRet = "The wind direction for " + strAlt + "000 feet is " + getWindDir(strAlt);
   return strRet;
}
/**
This routine will accept a string containing the altitude
and will return the starting position of the altitude weather
as an integer.
@param strAlt A string containing the altitude
@return An integer showing the position of the altitude weather within the station weather              
*/
private int getPos(String strAlt)
{
   int intAlt;
   int intRet =0;
   intAlt = Integer.parseInt(strAlt);
   switch (intAlt)
   {
     case 3:
      intRet = 4;
      break;
     case 6:
      intRet = 9;
      break;
     case 9:
      intRet = 14;
     // etc .... you can figure out the the other altitudes
   }
   return intRet;
}
 public String getAltitudeWeather(String strAlt)
 {
   // get the position in the station weather string
   int intPos = getPos(strAlt);
   // strAltitudeWeather contains a seven character string 
   String strRet = strWea.substring(intPos,intPos+7);
   // return the result
   return strRet;
 }
public String getWindDir(String strAlt)
 {
   String strRet = getAltitudeWeather(strAlt);
   return strRet.substring(0,2);
 }
}

这个类用来运行weather类,如下所示

// this code will be saved in a file called Weather.java
public class weather
{
   public static void main(String[] args)
    {
      // the next line is very long and ends with 352853
        //This code doesn't really end in 352853 I think when it did it was getting   diffrent weather data
     final String FAA_FD="SAN 3106 2915+23 2714+16 0710+08 1010-07 1916-17 222331 213141 203753";
     System.out.println("Start of Program Weather") ;
     NWSFB windsAloft = new NWSFB(FAA_FD);
     System.out.println(windsAloft.getWindInfo("03"));
     System.out.println(windsAloft.getWindInfo("06"));
     System.out.println(windsAloft.getWindInfo("09"));
     System.out.println(windsAloft.getWindInfo("12"));
     // etc. for the other altitudes
     System.out.println("End of Program Weather") ;
  }
}

这就是字符串的来源。

System.out.println(windsAloft.getWindInfo("03"));
System.out.println(windsAloft.getWindInfo("06"));
System.out.println(windsAloft.getWindInfo("09"));
System.out.println(windsAloft.getWindInfo("12"));

字符串通过getWindInfo()进入NWSFB类。它从那里传递到getWindDir()getAltitudeWeather()最后是getPos()

最新更新