代码有效,但不是所需的输出,需要帮助调试(Java)[新程序员:D]

问题描述 投票:-1回答:1

[创建一个控制台应用程序,它将读取两个文件(employees.txt和manager.txt)的内容。

应用程序应使用地图数据结构存储有关部门的信息。

应创建以下课程:

-具有信息的名字,姓氏和工资(每月)的雇员类;

-经理类,其中包含有关名字,姓氏,工资(每月)和年度奖金(占工资百分比)的信息

使用继承创建类。

将以下报告输出到单独的文件中:

-每个部门的平均薪水,例如市场营销1000,生产2000;

-支付部门所有薪水所需的总金额;

-所有经理的年度奖金金额

-每个部门雇员的最高薪水*及其名称

-每个部门雇员的最低工资*及其名称

**可以有一个或多个薪水最高的员工

**可以有一个或多个最低薪的员工

注意:每个部门最多可以有一位经理

<是错误的,应该说:

[行销中薪水最高的人是:约翰·普罗基迪

但是我得到:

[行销中薪水最高的人是:约翰·普罗基迪(John Prodigy)和Pasty Laprade

这里是我的

尝试

,在代码处:

注:scp =扫描仪生产,scm =扫描仪销售,hsp =最高工资生产,lsp =最低工资生产,hsm =最高工资销售,lsm =最低工资销售,salPro =工资生产,salMar =工资销售, emp =员工

package com.company; import javax.swing.plaf.synth.SynthMenuBarUI; import java.io.FileNotFoundException; import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.Scanner; public class Main { public static void main(String[] args) throws FileNotFoundException { Scanner scp = new Scanner(new File("C:\\Users\\denim\\IdeaProjects\\ProgrammingAssignment\\src\\com\\company\\employees.txt")); Scanner scm = new Scanner(new File("C:\\Users\\denim\\IdeaProjects\\ProgrammingAssignment\\src\\com\\company\\managers.txt")); int salPro = 0; int salMar = 0; ArrayList<Employee> marketing = new ArrayList<>(); ArrayList<Employee> production = new ArrayList<>(); HashMap<String, Integer> emp = new HashMap<String, Integer>(); while(scp.hasNextLine()) { String[] obj = scp.nextLine().split(", "); switch(obj[2]) { case "Production": { salPro += Integer.parseInt(obj[3]); Employee e = new Employee(obj); production.add(e); if (emp.containsKey("hsp")) { if (production.get(emp.get("hsp")).getSalary() < Integer.parseInt(obj[3])) emp.replace("hsp", (production.size()-1)); else if (production.get(emp.get("hsp")).getSalary() == Integer.parseInt(obj[3])) emp.put("hsp1", (production.size()-1)); } else { emp.put("hsp", (production.size()-1)); } if(emp.containsKey("lsp")) { if (production.get(emp.get("lsp")).getSalary() > Integer.parseInt(obj[3])) emp.replace("lsp", (production.size()-1)); else if (production.get(emp.get("lsp")).getSalary() == Integer.parseInt(obj[3])) emp.put("lsp1", (production.size()-1)); } else { emp.put("lsp", (production.size()-1)); } break; } case "Marketing": { salMar += Integer.parseInt(obj[3]); Employee e = new Employee(obj); marketing.add(e); if (emp.containsKey("hsm")) { if (marketing.get(emp.get("hsm")).getSalary() < Integer.parseInt(obj[3])) emp.replace("hsm", (marketing.size()-1)); else if (marketing.get(emp.get("hsm")).getSalary() == Integer.parseInt(obj[3])) emp.put("hsm1", (marketing.size()-1)); } else { emp.put("hsm", (marketing.size()-1)); } if(emp.containsKey("lsm")) { if (marketing.get(emp.get("lsm")).getSalary() > Integer.parseInt(obj[3])) emp.replace("lsm", (marketing.size()-1)); else if (marketing.get(emp.get("lsm")).getSalary() == Integer.parseInt(obj[3])) emp.put("lsm1", (marketing.size()-1)); } else { emp.put("lsm", (marketing.size()-1)); } break; } } } while(scm.hasNextLine()) { String[] obj = scm.nextLine().split(", "); switch (obj[0]) { case "Production": { salPro += Integer.parseInt(obj[3]); Manager m = new Manager(obj); production.add(m); if (emp.containsKey("hsp")) { if (production.get(emp.get("hsp")).getSalary() < Integer.parseInt(obj[3])) emp.replace("hsp", (production.size() - 1)); else if (production.get(emp.get("hsp")).getSalary() == Integer.parseInt(obj[3])) emp.put("hsp1", (production.size()-1)); } else { emp.put("hsp", (production.size() - 1)); } if (emp.containsKey("lsp")) { if (production.get(emp.get("lsp")).getSalary() > Integer.parseInt(obj[3])) emp.replace("lsp", (production.size() - 1)); else if (production.get(emp.get("lsp")).getSalary() == Integer.parseInt(obj[3])) emp.put("lsp1", (production.size()-1)); } else { emp.put("lsp", (production.size() - 1)); } break; } case "Marketing": { salMar += Integer.parseInt(obj[3]); Manager m = new Manager(obj); marketing.add(m); if (emp.containsKey("hsm")) { if (marketing.get(emp.get("hsm")).getSalary() < Integer.parseInt(obj[3])) emp.replace("hsm", (marketing.size() - 1)); else if (marketing.get(emp.get("hsm")).getSalary() == Integer.parseInt(obj[3])) emp.put("hsm1", (marketing.size()-1)); } else { emp.put("hsm", (marketing.size() - 1)); } if (emp.containsKey("lsm")) { if (marketing.get(emp.get("lsm")).getSalary() > Integer.parseInt(obj[3])) emp.replace("lsm", (marketing.size() - 1)); else if (marketing.get(emp.get("lsm")).getSalary() == Integer.parseInt(obj[3])) emp.put("lsm1", (marketing.size()-1)); } else { emp.put("lsm", (marketing.size() - 1)); } break; } } } System.out.println("The total Salary of the Production Department is: " + salPro); System.out.println("The total amount of Employees in the Production Department is: " + production.size()); System.out.println("The Average Salary for the Production Department is: " + salPro/(production.size())); System.out.println("\nThe total Salary of the Marketing Department is: " + salMar); System.out.println("The total amount of Employees in the Marketing Department is: " + marketing.size()); System.out.println("The Average Salary for the Marketing Department is: " + salMar/(marketing.size())); if(emp.containsKey("hsp1")) System.out.println("\nThe people with the highest salary in Production are: " + production.get(emp.get("hsp")).getFullName() + " and " + production.get(emp.get("hsp1")).getFullName()); else System.out.println("\nThe person with the highest salary in Production is: " + production.get(emp.get("hsp")).getFullName()) ; if(emp.containsKey("lsp1")) System.out.println("The people with the lowest salary in Production are: " + production.get(emp.get("lsp")).getFullName() + " and " + production.get(emp.get("lsp1")).getFullName()); else System.out.println("The person with the lowest salary in Production is: " + production.get(emp.get("lsp")).getFullName()) ; if(emp.containsKey("hsm1")) System.out.println("\nThe people with the highest salary in Marketing are: " + marketing.get(emp.get("hsm")).getFullName() + " and " + marketing.get(emp.get("hsm1")).getFullName()); else System.out.println("\nThe person with the highest salary in Marketing is: " + marketing.get(emp.get("hsm")).getFullName()) ; if(emp.containsKey("lsm1")) System.out.println("The people with the lowest salary in Marketing are: " + marketing.get(emp.get("lsm")).getFullName() + " and " + marketing.get(emp.get("lsm1")).getFullName()); else System.out.println("The person with the lowest salary in Marketing is: " + marketing.get(emp.get("lsm")).getFullName()) ; } }
这里是我制作的

课程

package com.company; public class Manager extends Employee { private int Bonus; public Manager(String department, String firstName, String lastName, int Salary, int Bonus) { super(firstName, lastName, department, Salary); this.Bonus = Bonus; } public Manager(String[] list) { this(list[0], list[1], list[2], Integer.parseInt(list[3]), Integer.parseInt(list[4])); } public int getBonus() { return Bonus; } }
package com.company;

public class Employee extends Person {
    private int Salary;
    private String department;

    public Employee(String firstName, String lastName, String department, int Salary) {
        super(firstName, lastName);
        this.department = department;
        this.Salary = Salary;
    }

    public Employee(String[] list) {
        this(list[0], list[1], list[2], Integer.parseInt(list[3]));
    }

    public int getSalary() {
        return Salary;
    }
}
package com.company;

public class Person {
    private String firstName;
    private String lastName;

    public Person(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }

    public String getLastName() {
        return lastName;
    }

    public String getFirstName() {
        return firstName;
    }

    public String getFullName() {
        return firstName + " " + lastName;
    }
}
这里是

文本文件

(managers.txt和employees.txt)
Marketing, John, Prodigy, 5300, 15 Production, Boss, Old, 2000, 20 Production, Bossic, Young, 1400, 20
Ginny, Gullatt, Marketing, 1000
Tiara, Curd, Production, 1200
Camie, Poorman, Marketing, 900
Jammie, Hasson, Marketing, 800
Lionel, Hailey, Marketing, 500
Genevive, Mckell, Production, 2000
Esteban, Slaubaugh, Marketing, 1300
Elden, Harte, Production, 1340
Tasia, Rodrigue, Marketing, 1200
Nathanial, Dentler, Production, 1700
Valda, Nicoletti, Marketing, 600
Kary, Wilkerson, Production, 600
Coletta, Akey, Marketing, 800
Wilmer, Jack, Production, 600
Loreta, Agnew, Marketing, 700
Suzy, Cleveland, Production, 1450
Pasty, Laprade, Marketing, 1300
Candie, Mehaffey, Production, 1800
Glady, Landman, Marketing, 1900
Tierra, Mckeown, Production, 2200
[创建一个控制台应用程序,它将读取两个文件(employees.txt和manager.txt)的内容。应用程序应使用Map数据结构存储有关部门的信息。正在关注...
java output text-files
1个回答
0
投票
尽管该代码正在运行,但它不满足所描述的要求:
© www.soinside.com 2019 - 2024. All rights reserved.