Добрый день! Помогите пожалуйста решить проблему! Есть такой код
| Код | /* * To change this template, choose Tools | Templates * and open the template in the editor. */
package test3;
/** * * @author Midav */ abstract class Person { private String name; public Person (String n) { name=n; } public String getName() { return name; } public abstract String getDescription();
}
class Employe extends Person {
private double salary;
public Employe (String n, double s) {super(n); salary=s; } public String getDescription() { return "Sotrudnik s zarplatoi = "+salary; } public double getSalary(){ return salary; } public void resizSalary(double byPercent) { salary*=1+byPercent/100; }
@Override public boolean equals(Object other) { if (this==other) return true; if (other==null) return false; if (getClass()!= other.getClass()) return false; Employe e =(Employe) other; return getName().equals(e.getName()) && salary==e.salary;
}
}
class Manager extends Employe { private double bonus; public Manager (String n, double s) { super(n,s); bonus=0; } @Override public String getDescription() { return "Manager s zarplatoi = "+super.getSalary()+ " a tak je bonus = "+bonus; } public void setBonus(double b) { bonus=b; }
@Override public double getSalary() { double s=super.getSalary(); return s+bonus; }
@Override public boolean equals(Object other) { if (!super.equals(other)) return false; Manager m = (Manager) other; return bonus==m.bonus; } } class Students extends Person { private String major; public Students(String n,String m) { super(n); major=m; } public String getDescription() { return "Student s professiei - "+major; } @Override public boolean equals(Object other) { if (this==other) return true; if (other==null) return false; if (getClass()!= other.getClass()) return false; Students e =(Students) other; return getName().equals(e.getName()) && major.equals(e.major);
}
} class Children extends Person { private int age; public Children(String n, int i) { super(n); age=i; } public String getDescription() { return "Children. Ego vozrast = "+age; }
@Override public boolean equals(Object other) { if (this==other) return true; if (other==null) return false; if (getClass()!= other.getClass()) return false; Children e =(Children) other; return getName().equals(e.getName()) && age==e.age;
}
}
public class Main {
/** * @param args the command line arguments */ public static void main(String[] args) { Person[] people = new Person[9]; people[0] = new Employe("Pupkin S.E.", 50000); Manager m = new Manager("Sorokin I.I.", 60000); m.setBonus(10000); people[1]=m; people[2] = new Employe("Ivaniv P.I.", 35000); people[3] = people[1]; people[4] = new Children("Petrov E.R.", 12); people[5] = people[1]; people[6] = people[4]; people[7] = new Students("Sergeev E.A.", "computer since"); people[8] = people[7]; for (int i = 0;i<people.length;i++) { Person e = people[i]; System.out.println(i+" Name: "+e.getName()+", "+e.getDescription()); } System.out.println("-----------"); for (int i = 0;i<people.length;i++) { System.out.print(i); for (int j = 0;j<people.length;j++) { if (people[i].equals(people[j])); System.out.print(" = "+j); } System.out.println(); } System.out.println("-----------");
}
}
|
при вызове метода equals происходить не то, что нужно в чем проблема?? Заранее спасибо! |