ArrayList的增删改查 查询出来应该是孙科 但是变成了张紫萱 望前辈指出错误如何更正
代码如下
package yxcwsbz;
import java.util.*;
public class Demo9 {
public static void main(String[] args) {
// TODO Auto-generated method stub
//雇员集合
ArrayList boa=new ArrayList();
//al中的数据类型是object类型
Staff sta1=new Staff(25,"张紫萱",4500f,"HB201611");
Staff sta2=new Staff(32,"何明",3800f,"HB201613");
Staff sta3=new Staff(27,"孙科",3200f,"HB201615");
Staff sta4=new Staff(29,"齐明",6200f,"HB201621");
//将对象加入集合
StaffManage staffmanage=new StaffManage();
staffmanage.add(sta1);
staffmanage.add(sta2);
staffmanage.add(sta3);
staffmanage.add(sta4);
staffmanage.showname("HB201615");
System.out.println(" ");
staffmanage.delstaff("HB201621");
System.out.println(" ");
staffmanage.revisesoal("HB201613", 1705.23f);
System.out.println(" ");
staffmanage.showall();
//System.out.print(boa.size());
}
}
//员工管理类
class StaffManage
{
private ArrayList boa= null;
public StaffManage()
{
boa=new ArrayList();
}
//增加一个员工
public void add(Staff staff)
{
boa.add(staff);
}
//查找一个员工
public void showname(String staffno)
{
for(int i=0;i<boa.size();i++)
{
Staff staff=(Staff)boa.get(i);
if(staff.getStaffno().equals(staffno));
{
System.out.println("查询的员工编号是:"+staffno);
System.out.println("查询的员工姓名是:"+staff.getName());
System.out.println("查询的员工工资是:"+staff.getSoal());
System.out.println("查询的员工年龄是:"+staff.getAge());
break;
}
}
}
//删除一个员工
public void delstaff(String staffno)
{
for(int i=0;i<boa.size();i++)
{
Staff staff=(Staff)boa.get(i);
if(staff.getName().equals(staffno));
{
boa.remove(i);
}
}
}
//修改员工工资
public void revisesoal(String staffno,float newsoal)
{
for(int i=0;i<boa.size();i++)
{
Staff staff=(Staff)boa.get(i);
if(staff.getName().equals(staffno));
{
staff.setSoal(newsoal);
}
}
}
public void showall()
{
for(int i=0;i<boa.size();i++)
{
Staff staff=(Staff)boa.get(i);
System.out.println("名字是:"+staff.getName()+" "+"工资是:"+staff.getSoal());
}
}
}
//创建一个员工类
class Staff
{
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getSoal() {
return soal;
}
public void setSoal(float soal) {
this.soal = soal;
}
public String getStaffno() {
return staffno;
}
public void setStaffno(String staffno) {
this.staffno = staffno;
}
private String name;
private float soal;
private String staffno;
public Staff(int age,String name,float soal,String staffno)
{
this.age=age;
this.name=name;
this.soal=soal;
this.staffno=staffno;
}
}