输不出来数据……,想问一下,toString函数的调用方法,有大佬心情好的话,可以看一下别的代码,萌新啥也不懂,泪流满面
package cn.campsg.java.experiment;
public class Employee {
private String no;
private String name;
private float salary;
private String department;
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getSalary() {
return salary;
}
public void setSalary(float salary) {
this.salary = salary;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public Employee(){
}
public Employee(int index,Employee[]employees){
this.no = employees[index].no;
this.name = employees[index].name;
this.salary = employees[index].salary;
this.department = employees[index].department;
}
public Employee(String string, String string2, String string3, float f) {
// TODO Auto-generated constructor stub
this.no = string;
this.name = string2;
this.department = string3;
this.salary = f;
}
public boolean equals(Object o) {
if(o==null){
return false;
}
if(!(o instanceof Employee)){
return false;
}
Employee emp = (Employee)o;
if(!emp.getNo().equals(this.getNo()))
return false;
return false;
}
@SuppressWarnings("null")
public String toString() {
StringBuffer buffer=null;
buffer.append("工号:"+this.no+",姓名:"+name+",部门:"+department+",薪水:"+salary);
return buffer.toString();
}
}
package cn.campsg.java.experiment;
public class MainClass {
private static final char[] buffer = null;
public static boolean isRepeat(int index,Employee[] employees) {
Employee emp = new Employee();
emp = employees[index];
for(int i=0;i<3;i++){
if(emp == employees[i]){
continue;
}
if(emp.getNo().equals(employees[i].getNo())){
return true;
}
else
return false;
}
return true;
}
public static void main(String[] arge){
Employee []employees = new Employee[3];;
employees[0] = new Employee("1001","张一","销售部",5000.0f);
employees[1] = new Employee("1002","王二","销售部",6500.0f);
employees[2] = new Employee("1001","Alan","研发部",15000.0f);
int count = 0;
for(int i=0;i<3;i++){
int index = i;
if(isRepeat(index,employees)==false){
System.out.println(employees);
count ++;
}
}
System.out.println("本公司有效员工数:"+count);
}
}