我在代码中有两个equals方法,但它们都不起作用.我自己制作了一个,然后我也通过源自动生成一个来自Eclipse.我用一个或另一个多次运行程序,并且都没有工作.
import java.util.Arrays;
import java.util.Scanner;
import java.math.*;
public class Item {
static //the properties of an Item
double cash=59;
static double sum=0;
private int priority;
private String name;
private double price;
//default constructer
public Item() {
priority = -1; //fill with default values
price = 0.0;
name = "No name yet";
}
public Item(int priority, String name, double price) {//constructor with all 3 arguments
this.priority = priority;
this.name = name;
this.price = price;
}
public int getPriority() {
return priority; …Run Code Online (Sandbox Code Playgroud) 我想知道我是否正确地写了这个equals方法.我的程序不断打印出"平等",即使两个对象Item和otherObject不相等.我有三个equals方法,一次运行一个似乎没有工作.三个等于方法正好位于彼此之后以供参考.我的主要是在最后.
import static java.lang.System.*;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Scanner;
import java.math.*;
public class Item {
DecimalFormat df = new DecimalFormat("#.00");
//the properties of an Item
static double cash=59.00;
static double sum=0.00;
private int priority;
private String name;
private double price;
static boolean value= false;
//default constructer
public Item() {
priority = -1; //fill with default values
price = 0.00;
name = "No name yet";
}
public Item(int priority, String name, double price) {//constructor with all …Run Code Online (Sandbox Code Playgroud)