ShMoMo 2018-10-07 11:52 采纳率: 0%
浏览 815

关于Java的toString函数调用

输不出来数据……,想问一下,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);
}

}

  • 写回答

4条回答 默认 最新

  • danielinbiti 2018-10-07 14:38
    关注
     if(isRepeat(index,employees)==false){
    System.out.println(employees[index]);
    count ++;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站