Мой исходный вывод должен выглядеть как 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));
}
}
Все работало, когда я помещал все в основной метод без каких-либо других методов, которые я не предполагал делать.