该方法应该接受 3 个参数 - String、double 和 String。然后它将返回一个要在 main 方法中打印的值。我该怎么做呢?这就是我所做的
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
public class coordinates
{
public static void main(String args[])
{
double angle=0, az = 0;
JOptionPane.showMessageDialog(null, "Hello, this is the 'Bearing to Azimuth' converter.\nFirst, you must input whether the angle is from the North or from the South, input the angle, and then input whether it is East or West.", "Bearing to Azimuth converter", JOptionPane.PLAIN_MESSAGE);
String ns = JOptionPane.showInputDialog("Input n for North and s for South:");
String inputangle = JOptionPane.showInputDialog("Input the angle in decimal format:");
angle = Double.parseDouble(inputangle);
String ew = JOptionPane.showInputDialog("Input e for East and w for West:");
convertToSouthAzimuth(ns, angle, ew);
JOptionPane.showMessageDialog(null, "The converted azimuth is " + az, "Bearing to Azimuth converter", JOptionPane.PLAIN_MESSAGE);
} //end main method
public double convertToSouthAzimuth(String ns, double angle, String ew)
{
double az = 0;
if (ns.equals("n")||ns.equals("N")) {
if (ew.equals("e")||ew.equals("E")) {az= 180+angle;}
if(ew.equals("w")|| ew.equals("W")){az= 180-angle;}
}
if (ns.equals("s")||ns.equals("S")) {
if (ew.equals("e")||ew.equals("E")) {az= 360-angle;}
if (ew.equals("w")||ew.equals("W")) {az= angle;}
}
return az;
} //end convertToSouthAzimuth method
}