与目标相比,它给了我错误的陈述我做错了什么?

问题描述 投票:0回答:0

你好,我正在尝试与具有 equals 功能的 Objectives 进行比较,但它给了我错误,我无法弄清楚如果有人可以提供帮助,我会很高兴

这是我的班级

等于第 32 行和第 34 行的函数


public class City
{
    final static int zero=0,one=1;
    private String cityName;
    private Date dateEstablished;
    private Point cityCenter,centralStation;
    private long numOfResidents;
    private int numOfNeighborhoods;

    public City(String cityName,int d,int m,int y,int cityCenterX,int cityCenterY,int centralStationX,int centralStationY,long numOfResidents,int numOfNeighborhoods)
    {
        this.cityName=cityName;
        this.dateEstablished=new Date (d,m,y);
        this.cityCenter=new Point (cityCenterX,cityCenterY);
        this.centralStation=new Point (centralStationX,centralStationY);
        if(numOfResidents<0)
            this.numOfResidents=0;
        else
            this.numOfResidents=numOfResidents;
        if(numOfNeighborhoods<1)
            this.numOfNeighborhoods=1;
        else
            this.numOfNeighborhoods=numOfNeighborhoods;

    }

    public City(City other)
    {
        this.cityName=other.cityName;
        this.dateEstablished=other.dateEstablished;
        this.cityCenter=other.cityCenter;
        this.centralStation=other.centralStation;
        this.numOfResidents=other.numOfResidents;
        this.numOfNeighborhoods=other.numOfNeighborhoods;

    }

    
}//end of class

这是我的主要

public class tester
{
    public static void main(String[] args) {
   
        City city3=new City("SomeCity",2,8,1000,10,20,30,40,10000,50);
        City city4=new City("SomeCity",2,8,1000,10,20,30,40,10000,50);
        
        if(city3.equals(city4))
             System.out.println("\tcity3 is the same  as city4");
        else 
             System.out.println("\tcity3 isn't the same  as city4");

        
}
    

据我所知,equals 函数应该比较对象自身的实例值,但我认为正在发生的事情是比较引用,如果我错了,如果有人指导我,我会很高兴

试图找到一个没有成功的解决方案。 帮帮我

java string-comparison
© www.soinside.com 2019 - 2024. All rights reserved.