JAVA-modifyemployee
善良,学习 这些是我拥有的类:Employee、salaryworker、hourlyworker、PayrollTest 我需要能够修改现有员工,但我需要它能够区分是小时工还是带薪工,因为他们有不同的输入。我可以通过id找到员工,但无法正确修改。我不知道该怎么做JAVA-modifyemployee,java,Java,善良,学习 这些是我拥有的类:Employee、salaryworker、hourlyworker、PayrollTest 我需要能够修改现有员工,但我需要它能够区分是小时工还是带薪工,因为他们有不同的输入。我可以通过id找到员工,但无法正确修改。我不知道该怎么做 import java.util.*; import java.lang.*; public class PayrollTest { //Array Lists for Hourly and Salary Workers.
import java.util.*;
import java.lang.*;
public class PayrollTest {
//Array Lists for Hourly and Salary Workers.
public static hourlyworker hourlyEmp = new hourlyworker(null, 0, 0.0, 0.0, 0.0, 0, 0, 0);
public static ArrayList<hourlyworker> hourlyList = new ArrayList<hourlyworker>();
//(String name, int dependents, double annualSalary, int month, int day, int year) {
public static salaryworker salaryEmp = new salaryworker(null, 0, 0.0, 0, 0, 0);
public static ArrayList<salaryworker> salaryList = new ArrayList<salaryworker>();
//Arraylist Initializing
public static ArrayList emps = new ArrayList(); //<Employee>
//Initializing scanner for user input
public static Scanner scan = new Scanner(System.in);
//Fields needed for PayrollTest
private static char choice;
private static char typeChoice;
private static boolean switcher = true;
@SuppressWarnings("resource")
public static void main(String[] args) {
menuSelection();
System.out.println();
}
@SuppressWarnings("unchecked")
private static void loadHourlyEmployee() {
System.out.println("\nEnter full name, number of dependents, hourly rate, regular hours worked, overtime worked, and date hired (yyyy mm dd)");
System.out.println("[one field per line, except date hired]: ");
hourlyEmp = new hourlyworker(null, 0, 0.0, 0.0, 0.0, 0, 0, 0);
hourlyEmp.setName(scan.nextLine());
hourlyEmp.setDependents(scan.nextInt());
hourlyEmp.setPayrate(scan.nextDouble());
hourlyEmp.setHours(scan.nextDouble());
hourlyEmp.setOvertimeHours(scan.nextDouble());
hourlyEmp.setHireDay(scan.nextInt());
emps.add(hourlyEmp);
System.out.println("\nYou entered an employee type for non-exempt: hourly.");
}
@SuppressWarnings("unchecked")
private static void loadSalaryEmployee() {
System.out.println("\nEnter full name, number of dependents, annual salary, and date hired (yyyy mm dd)");
System.out.println("[one field per line, except date hired]: ");
salaryEmp = new salaryworker(null, 0, 0.0, 0, 0, 0);
salaryEmp.setName(scan.nextLine());
salaryEmp.setDependents(scan.nextInt());
salaryEmp.setAnnualSalary(scan.nextDouble());
salaryEmp.setHireDay(scan.nextInt());
emps.add(salaryEmp);
System.out.println("\nYou entered an employee type for exempt: salary.");
}
private static void menuSelection() {
do {
System.out.println("\n\n\tEmployee Database");
System.out.println("\nEmployee Info Menu");
System.out.println("\tEnter L to (L)oad Employee info");
System.out.println("\tEnter M to (M)odify Employee info");
System.out.println("\tEnter P to (P)rint Employee info");
System.out.println("\tEnter Q to quit");
System.out.print("Please enter your choice: ");
choice = scan.nextLine().toUpperCase().charAt(0);
//Choice validation
while ((choice != 'L') && (choice != 'M') && (choice != 'P') && (choice != 'Q')) {
System.out.println("Invalid choice! Please select (L)oad, (M)odify, (P)rint, or (Q)uit: ");
choice = scan.nextLine().toUpperCase().charAt(0);
}
//Switch Statement
switch (choice) {
case 'L' :
System.out.println("What is the employee type? S = salary H = hourly ");
System.out.print("\n[Please enter letter] : ");
typeChoice = scan.nextLine().toUpperCase().charAt(0);
//typeChoice validation
while ((typeChoice != 'S') && (typeChoice != 'H')) {
System.out.println("Invalid choice! Please select (S)alary, (H)ourly: ");
typeChoice = scan.nextLine().toUpperCase().charAt(0);
}
if (typeChoice == 'H') {
loadHourlyEmployee();}
else if (typeChoice == 'S') {
loadSalaryEmployee();
}
break;
case 'M' :
modifyEmployee();
break;
case 'P' :
printEmployees();
break;
case 'Q' :
switcher = false;
System.out.println("\nProgram Terminated.");
break;
}
}
while (switcher != false);
}
private static void printEmployees() {
System.out.println("\nThere are " + emps.size() + " people in this database.\n");
for (int i = 0; i < emps.size(); i++) {
System.out.println(emps.get(i));
}
System.out.println("\nTotal = " + emps.size());
}
private static void modifyEmployee() {
System.out.print("Employee id#? ");
int findID = scan.nextInt();
boolean found = false;
int index = 0;
boolean deleteMod = false;
int index1 = 0;
while (index < emps.size() && !found) {
if (emps.get(index) != null) {
found = true;
}
deleteMod = true;
System.out.println("\nCurrent Info: ");
}
}
}
import java.util.*;
导入java.lang.*;
公共类工资测试{
//小时工和带薪工的数组列表。
public static hourlyworker hourlyep=新的hourlyworker(null,0,0.0,0.0,0.0,0,0);
public static ArrayList hourlyist=new ArrayList();
//(字符串名称,整数依赖项,双年历,整数月,整数日,整数年){
公共静态salaryworker salaryEmp=新的salaryworker(null,0,0.0,0,0);
public static ArrayList salaryList=new ArrayList();
//数组列表初始化
公共静态ArrayList emps=新ArrayList()//
//为用户输入初始化扫描仪
公共静态扫描仪扫描=新扫描仪(System.in);
//PayrollTest所需的字段
私有静态字符选择;
私有静态字符类型选择;
私有静态布尔切换器=true;
@抑制警告(“资源”)
公共静态void main(字符串[]args){
菜单选择();
System.out.println();
}
@抑制警告(“未选中”)
私有静态void loadHourlyEmployee(){
System.out.println(“\n输入全名、家属人数、小时工资、正常工作时间、加班时间和雇用日期(yyyy-mm-dd)”;
System.out.println(“[每行一个字段,租用日期除外]:”;
hourlyep=新的hourlyworker(null,0,0.0,0.0,0.0,0,0,0);
hourlyep.setName(scan.nextLine());
hourlyEmp.setDependents(scan.nextInt());
hourlyEmp.setPayrate(scan.nextDouble());
hourlyEmp.setHours(scan.nextDouble());
hourlyEmp.setOvertimeHours(scan.nextDouble());
hourlyEmp.setHireDay(scan.nextInt());
皇帝添加(小时);
System.out.println(“\n您输入了非豁免的员工类型:小时。”);
}
@抑制警告(“未选中”)
私有静态void loadSalaryEmployee(){
System.out.println(“\n输入全名、家属人数、年薪和聘用日期(yyyy-mm-dd)”;
System.out.println(“[每行一个字段,租用日期除外]:”;
salaryEmp=新的salaryworker(null,0,0.0,0,0);
salaryEmp.setName(scan.nextLine());
salaryEmp.setDependents(scan.nextInt());
salaryEmp.setAnnualSalary(scan.nextDouble());
salaryEmp.setHireDay(scan.nextInt());
emps.add(salaryEmp);
System.out.println(“\n您输入了免税的员工类型:工资。”);
}
私有静态void菜单选择(){
做{
System.out.println(“\n\n\tEmployee数据库”);
System.out.println(“\n员工信息菜单”);
System.out.println(“\t输入到(L)加载员工信息”);
System.out.println(“\t输入M到(M)修改员工信息”);
System.out.println(“\t输入P到(P)打印员工信息”);
System.out.println(“\t退出Q”);
System.out.print(“请输入您的选择:”);
choice=scan.nextLine().toUpperCase().charAt(0);
//选择验证
而((选择!='L')&&(选择!='M')&&(选择!='P')&&(选择!='Q')){
System.out.println(“选择无效!请选择(L)加载、(M)修改、(P)打印或(Q)uit:”);
choice=scan.nextLine().toUpperCase().charAt(0);
}
//开关语句
开关(选择){
案例“L”:
System.out.println(“员工类型是什么?S=工资H=小时”);
System.out.print(“\n[请输入字母]:”);
typeChoice=scan.nextLine().toUpperCase().charAt(0);
//类型选择验证
while((typeChoice!='S')&&(typeChoice!='H')){
System.out.println(“无效选择!请选择alary,(H)ourly:”);
typeChoice=scan.nextLine().toUpperCase().charAt(0);
}
if(typeChoice='H'){
loadHourlyEmployee();}
else if(typeChoice='S'){
loadSalaryEmployee();
}
打破
案例“M”:
修改employee();
打破
案例“P”:
打印员工();
打破
案例‘Q’:
切换器=假;
System.out.println(“\n程序终止”);
打破
}
}
while(switcher!=假);
}
私有静态void printEmployees(){
System.out.println(“\n此数据库中有“+emps.size()+”人。\n”);
对于(int i=0;i
使用instanceof
确定它是否是您想要的类
if (emps.get(index) instanceof hourlyworker) {
// code for hourlyworker
} else {
// code for salaryworker
}
使用
instanceof
确定它是否是您想要的类
if (emps.get(index) instanceof hourlyworker) {
// code for hourlyworker
} else {
// code for salaryworker
}
使用
instanceof
确定它是否是您想要的类
if (emps.get(index) instanceof hourlyworker) {
// code for hourlyworker
} else {
// code for salaryworker
}
使用
instanceof
确定它是否是您想要的类
if (emps.get(index) instanceof hourlyworker) {
// code for hourlyworker
} else {
// code for salaryworker
}
中的