我正在做我的功課,我很難在這裏找到問題。我寫的程序不能編譯。請幫忙。作業詳細信息:如何從包(java)中的其他類訪問主類中的變量?
「創建一個名爲Airport的類,其中包含以下字段:標識符。包含經度和緯度的座標(不要創建每個!!的兩個)。緯度爲正值表示赤道北,負值當它位於南半球時,經度爲負值,表示爲西,正值表示它是格林威治中位數的東部,磁性變化也表示西方爲負,東方爲正值,沒有磁性變化是可以的。海拔高度以英尺爲單位
添加一個靜態方法,該方法接受四個雙精度座標(雙lat1,double long1,double lat2,double long2),並返回海里距離,使用給出的公式實驗室05.例如,聖地亞哥機場的值爲ID:SAN,Lat:32.7335556,Long:-117.1896667,Var:14,Elev:16.8'(http://www.airnav.com/airport/SAN)該類應該爲每個字段提供訪問器和增變器方法。「
我在這裏做了大部分的工作,但我想我需要在這裏添加構造函數。請幫忙。
主要類:
package lab06;
import javax.swing.JOptionPane;
public class Lab06
{
public static void main(String[] args) {
double number; // To hold the number
String input; // To hold user input
//Create two Airport objects.
Airport firstAirport = new Airport();
Airport secondAirport = new Airport();
// Get and store the coordinates for firstAirport.
input = JOptionPane.showInputDialog("Enter the first Latitude: ");
number = Double.parseDouble(input);
firstAirport.setLatitude(number);
input = JOptionPane.showInputDialog("Enter the first Longitude: ");
number = Double.parseDouble(input);
firstAirport.setLongitude(number);
input = JOptionPane.showInputDialog("Enter the first Elevation: ");
number = Double.parseDouble(input);
firstAirport.setElevation(number);
// Get and store the coordinates for secondAirport.
input = JOptionPane.showInputDialog("Enter the second Latitude: ");
number = Double.parseDouble(input);
secondAirport.setLatitude(number);
input = JOptionPane.showInputDialog("Enter the second Longitude: ");
number = Double.parseDouble(input);
secondAirport.setLongitude(number);
input = JOptionPane.showInputDialog("Enter the second Elevation: ");
number = Double.parseDouble(input);
secondAirport.setElevation(number);
}
// The Distance method calculates the distance in nautical miles
public static void getDistance(String[] args)
{
double R = 3440;
double dist = Math.sin(firstAirport.getLatitude())
* Math.sin(secondAirport.getLatitude())
+ Math.cos(secondAirport.getLatitude())
* Math.cos(firstAirport.getLatitude())
* Math.cos(firstAirport.getLongitude()
- secondAirport.getLongitude());
dist = Math.acos(dist);
dist = dist * R;
// Display result in nautical miles.
JOptionPane.showMessageDialog(null,
"The distance in nautical miles is: %.1f\n" + dist);
System.exit(0);
}
}
和機場類....
package lab06;
public class Airport
{
public double latitude;
public double longitude;
public double elevation;
//The setLatitude method stores a value in the latitude field.
public void setLatitude(double latitude)
{
this.latitude = latitude;
}
//The setLongitude method stores a value in the longitude field.
public void setLongitude(double longitude)
{
this.longitude = longitude;
}
//The setElevation method stores a value in the elevation field.
public void setElevation (double elevation)
{
this.elevation = elevation;
}
//The getLatitude method returns an Airport object's latitude.
public double getLatitude()
{
return latitude;
}
//The getLongitude method returns an Airport object's longitude.
public double getLongitude()
{
return longitude;
}
//The getElevation method returns an Airport object's elevation.
public double getElevation()
{
return elevation;
}
}
我讀了一個問題,「這並不編譯,我不能打擾閱讀錯誤消息或把它給你我希望你能爲我做所有的工作「。 – John3136
*爲什麼*不編譯?當你嘗試編譯它時,會發生什麼?是否有東西*阻止它從編譯?那是什麼? – David
不要發佈這麼多的代碼。發佈[MCVE]:發佈最低限額以顯示您的問題。 – c0der