我在调用方法printDetails()和salaryDeductions()时遇到问题

时间:2020-03-25 00:43:11

标签: java oop

我的原始输出应该看起来像this,但字符串类型显示为null,而双精度类型显示为R0.0。但是,当我将所有内容放入主程序中时,它就起作用了。错了有人可以帮我吗?

我做了什么

import java.util.Scanner;
public class EmployeeReport {
    private static double updatedSalary;
    public static void printDetails(details report)
    {
        System.out.println("\nEMPLOYEE DETAILS REPORT");//Report Header 1
        for(int i = 1 ; i <28 ; i++) {
            System.out.print("*");
        }
        System.out.println("\nEMPLOYEE NUMBER:      "+details.getEmployee_ID());
        System.out.println("EMPLOYEE FIRST NAME:  "+details.getName());
        System.out.println("EMPLOYEE SURNAME:     "+details.getSurname());
        System.out.println("ORIGINAL SALARY:      R"+details.getOrigSalary());
        System.out.println("INCREASE SALARY:      R"+details.getUpdatedSalary());
        System.out.println("INCREASED AMOUNT:     R"+details.getAmtIncrease());
        updatedSalary = details.getUpdatedSalary();
        System.out.println("");
        for(int i = 1 ; i <28 ; i++) {
            System.out.print("*");
        }
    }
    public static void salaryDeductions(Object details)
    {
         System.out.println("\nEMPLOYEE DEDUCTIONS REPORT  ");//Report Header 2
         for (int i = 1; i<28; i++){
             System.out.print("*");
         }
         double updatedSalary = ((details) details).getUpdatedSalary();
        double tax = ((details) details).getTax();
        System.out.println("\nSALARY:             R"+updatedSalary+"\n"+
             "TAX:               R"+tax+"\n"+
             "MEDICAL AID:       R"+((details) details).getMedical()+"\n"+
             "CAR ALLOWANCE:     R"+((details) details).getCarAllowance()+"\n"+
             "UIF:               R"+((details) details).getUIF()+"\n"+
             "Take Home Pay:     R"+((details) details).getHome()); 
         for (int i = 1; i<28; i++){
             System.out.print("*");
         }
    }
    public static void main(String[] args) 
    {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter the employee number >> ");
        String id = input.nextLine();
        System.out.println("Enter the employee first name >> "); 
        String firstName = input.nextLine();
        System.out.print("Enter the employee surname >> ");
        String Surname = input.nextLine();
        System.out.println("Enter the employee salary to increased >>  ");
        double origSalary = input.nextDouble();
        details report = new details(id, firstName , Surname, origSalary);
        printDetails(report);
        int question = 1;
        {
             System.out.println("\nWould you like to see the increased salary with deductions? Enter (1) to view the the deductions report or any other key to exit.");
             question = input.nextInt();
        }
        if (question == 1)
        {
            salaryDeductions(report);
        }
    }

详细课程

 public class details
    {
        //employee ID number, first name, surname and salary
        public static String employeeID;
        public static String firstName, Surname;
        public static double origSalary,updatedSalary,increaseAmount;
        //salaryIncrease : origSalary + (origSalary * 0.15)
        //increaseAmount : origSalary * 0.15
        public static final double FINAL_TAX = 0.18;
        public static final double FINAL_MEDICAL = 0.125;
        public static final double FINAL_CAR_ALLOWANCE = 0.08;
        public static final double FINAL_UIF = 0.02;
        ///
        public static double employeeTax , employeeMedical , employee_Car_Allowance, employeeUif,dblHome;
        public details(String id, String firstName2, String surname2, double origSalary2) {
            // TODO Auto-generated constructor stub
            id = employeeID;
            firstName2 = firstName;
            surname2 = Surname;
            origSalary2 = origSalary;
        }
        //Start of Details Report
        public void setEmployee_ID(String id) 
        {
            employeeID = id;
        }
        public static String getEmployee_ID()
        {
            return employeeID;
        }
        public void setName(String strName)
        {
            firstName = strName;
        }
        public static String getName()
        {
            return firstName;
        }
        public void setSurname(String strSurname) 
        {
            Surname = strSurname;
        }
        public static String getSurname() 
        {
            return Surname;
        }
        public void setOrigSalary(double dblSalary)
        {
            origSalary = dblSalary;
        }
        public static double getOrigSalary()
        {
            return origSalary;
        }
        public void setUpdatedSalary(double dblIncreaseSalary) 
        {
            updatedSalary = dblIncreaseSalary;
        }
        public static double getUpdatedSalary()
        {
            return origSalary + (origSalary * 0.15);
        }
        public void setAmtIncrease(double amtIncrease) 
        {
            increaseAmount = amtIncrease;
        }
        public static double getAmtIncrease()
        {
            return origSalary * 0.15;
        }
        //End of Details report
        //Start of Deductions report
        public void setTax(double tax)
        {
            employeeTax = tax;
        }
        public double getTax() 
        {
            return updatedSalary * FINAL_TAX;

        }
        public void setMedical(double medical) 
        {
            employeeMedical = medical;
        }
        public double getMedical()
        {
            return updatedSalary * FINAL_MEDICAL;
        }
        public void setCarAllowance(double dblCar_Allowance)
        {
            employee_Car_Allowance = dblCar_Allowance;
        }
        public double getCarAllowance() 
        {
            return updatedSalary* FINAL_CAR_ALLOWANCE ;
        }
        public void setUIF(double dblUIF)
        {
            employeeUif = dblUIF;
        }
        public double getUIF()
        {
            return updatedSalary * FINAL_UIF;
        }
        public void setHome(double home)
        {
            dblHome = home;
        }
        public double getHome()
        {
            return updatedSalary - ((updatedSalary * FINAL_TAX) + 
                    (updatedSalary * FINAL_MEDICAL) + (updatedSalary* FINAL_CAR_ALLOWANCE) +
                    (updatedSalary * FINAL_UIF));
        }
    }

当我将所有内容都放置在main方法中而没有 我不应该做的其他方法。

0 个答案:

没有答案