package 第三次作业2;
public class Employee {
private String name;
static int id = 1;
private double salary;
public Employee() {}
public Employee(String name, double salary) {
super();
this.name = name;
this.salary = salary;
id++;
}
public static int getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
package 第三次作业2;
import java.util.jar.Attributes.Name;
public class Manager extends Employee{
private double bonus;//奖金,罚金
public Manager() {}
public Manager(String name,double salary,double bonus) {
super(name,salary);
this.bonus = bonus;
id++;
}
public double addsalary(double salary,double bonus) {
double newsalary=salary+bonus;
return newsalary;
}
public double subsalary(double salary,double bonus) {
double newsalary=salary-bonus;
return newsalary;
}
}
package 第三次作业2;
import java.util.ArrayList;
import java.util.Scanner;
import 练习.Employee;
public class EmployeeTest {
static Scanner sc=new Scanner(System.in);//
static ArrayList<Employee> employees= new ArrayList<>();//
public static void main(String[] args) {
System.out.println("请输入要进行的功能1:添加 2:删除 3:查找");
int choose=sc.nextInt();
if(choose==1) {
System.out.println("请输入要添加的职工个数");
int m=sc.nextInt();
for(int i=0;i<m;i++) {
getEmployee();
}
for(int i=0;i<employees.size();i++) {
System.out.println(employees.get(i).getName()+employees.get(i).getEmpID()+
employees.get(i).getSalary());
}
}
if(choose==2) {
delete();
for(int i=0;i<employees.size();i++) {
System.out.println(employees.get(i).getName()+employees.get(i).getEmpID()+
employees.get(i).getSalary());
}
}
if(choose==3) {
search();
for(int i=0;i<employees.size();i++) {
System.out.println(employees.get(i).getName()+employees.get(i).getEmpID()+
employees.get(i).getSalary());
}
}
}
public static void getEmployee() {
System.out.println("请输入1:添加一个员工 2:添加一个经理");
int n=sc.nextInt();
switch(n) {
case 1:
Employee employee = new Employee(sc.next(),sc.nextDouble());
employees.add(employee);
break;
case 2:
Manager manager = new Manager(sc.next(),sc.nextDouble(),sc.nextDouble());
employees.add(manager);//???
break;
}
}
static public void search() {
System.out.println("请输入查找员工的姓名");
String searchname=sc.next();
for(int i=0;i<employees.size();i++) {
if(searchname==employees.get(i).getName()) {
System.out.println(employees.get(i).getName()+"的id是:"+i);
}
}
}
static public void delete() {
System.out.println("请输入要删除的成员姓名");
String deletename=sc.next();
for(int i=0;i<employees.size();i++) {
if(deletename==employees.get(i).getName()) {
employees.remove(i);
}
}
}
}
应该怎么改