0

私は Java クラスを使用していますが、コードを正常に実行するのに役立つ次の例がありますが、コードを実行できません。問題は strAlt にあることがわかりましたが、次のコードで strAlt がどこに定義されているかわかりません。Net Beans でデバッガーを使用すると、スイッチ テストで最初に使用されたときに、strAlt が整数 3 に変換される文字列 "03" として定義されていることがわかりましたが、文字列 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);
 }
}

このクラスは、次のようにクラスの天気を実行するために使用されます

// 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") ;
  }
}
4

1 に答える 1

2

これは、弦がどこから来ているかです。

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

NWSFB文字列はを介し​​てクラスに入りますgetWindInfo()。そこからgetWindDir() Toに渡されgetAltitudeWeather() 、最終的にTo に渡されます。getPos()

于 2013-03-10T05:35:31.557 に答える