Java(Eclipse)类返回语句不起作用

时间:2017-08-22 17:58:44

标签: java eclipse class testing return

我正在编写一个类,其中包括创建访问器和更改器。但是,当我运行我的程序来使用该类时,没有返回任何内容,或者我的程序没有输出任何内容。

在测试程序(下面)中,我创建了类变量并将它们发送到我输入的类,然后返回变量。

我理想的输出是函数调用返回变量。 例如(getLatitude将输出Latitude变量)

这是我的课程代码:

package practiceProblems;

import stdlib.StdOut;

public class GPSPosition implements Comparable <GPSPosition> {

    // Private global variables
    private Double Latitude;
    private Double Longitude;
    private Double Altitude;

    // Constructor 1
    public <Item extends Comparable<? super Item>> GPSPosition() { 
        Latitude  = 0.0; 
        Longitude = 0.0; 
    }

    // Constructor 2
    public <Item extends Comparable<? super Item>> GPSPosition (Double lat, Double lon, Double alt) {
        this.Altitude  = alt;
        this.Latitude  = lat;
        this.Longitude = lon;

        if (lat < -90 || lat > 90) {
            throw new IllegalArgumentException ("NOPE!");
        }

        if (lon < -180 || lon > 180) {
            throw new IllegalArgumentException ("NOPE!!");
        }

        if (alt < 0) {
            throw new IllegalArgumentException ("NOPE!!!");
        }
    }

    // Latitude Accessor
    public Double getLatitude () { 
        return this.Latitude; 
    }

    // Longitude Accessor
    public Double getLongitute () { 
        return this.Longitude; 
    }

    // Altitude Accessor
    public Double getAltutude () { 
       return this.Altitude; 
    }

    // Mutator for Latitude
    public void setLatitude (Double Latitude) { 
        this.Latitude = Latitude;
    }

    // Mutator for Longitude
    public void setLongitude (Double Longitude) { 
        this.Longitude = Longitude;
    }

    // Mutator for Altitude
    public void setAltitude (Double Altitude) { 
        this.Altitude = Altitude;
    }

    // Compare to method
    public int compareTo (GPSPosition that) {
        if (this.Latitude.compareTo (that.Latitude) > 0) {
            return 1;
        }

        if (this.Latitude.compareTo (that.Latitude) < 0) {
            return -1;
        }

        return that.Latitude.compareTo (this.Latitude);
    }

    // toString method
    public String toString () {
        String latOutput  = "";
        String longOutput = "";

        if (this.Latitude < 0) { 
            latOutput = "S"; 
        } else {
            latOutput = "N";
        }

        if (this.Longitude < 0) { 
            latOutput = "W"; 
        } else {
            latOutput = "E";
        }

        return (this.Latitude + latOutput + " " + this.Longitude + longOutput + " " + this.Altitude + "m");
    }

    public double distance (GPSPosition that) {
        return (Math.sqrt ((this.Latitude - this.Longitude) + (that.Longitude - that.Latitude)));
    }   
}

这是我的测试计划:

package practiceProblems;

import practiceProblems.GPSPosition;

public class TestGPS {

    public static void main (String[] args) {

        // Positions
        GPSPosition position  = new GPSPosition (-37.2, 87.2, 200.0);   
        GPSPosition position2 = new GPSPosition (37.2, 7.2, 100.0); 

        // Set
        position.setAltitude (200.0); 
        position.setLatitude (-37.2);
        position.setLongitude (87.2);

        // Get
        position.getAltutude (); 
        position.getLatitude (); 
        position.getLongitute ();

        // Compare to
        position.compareTo (position2);

        // To String call
        position.toString ();

        // Distance between two positions
        position.distance (position2);  
    }
}

1 个答案:

答案 0 :(得分:1)

我建议在你的主要方法中使用以下内容:

WHERE floor(pow(2,FIND_IN_SET('A',c)-1))+
floor(pow(2,FIND_IN_SET('L',c)-1))+
floor(pow(2,FIND_IN_SET('E',c)-1))=c

但请注意,您的距离法不会返回数字,NaN代表“非数字”。