0
在解決java和im有問題的問題時,即使初學者如此幫助,我的打印語句(名稱和部門)在從用戶處獲取值時也會相互衝突。java打印語句在用戶輸入值時發生衝突
public class payroll2
{
public static void main(String args[])
{
payroll2 payroll = new payroll2();
payroll.SetPayrollDetail();
payroll.SetBonus();
payroll.SetCommission();
payroll.SetNssf();
payroll.SetNetSalary();
payroll.GetPayroll();
}
Scanner myScanner=new Scanner(System.in);
int empID;
String empName;
String empDept;
String designation;
int basicSalary;
double netSal;
double bonus;
double commission;
double nssf;
public void SetPayrollDetail()
{
System.out.println("Enter ID: ");
empID = myScanner.nextInt();
System.out.println("Enter Name: ");
empName = myScanner.nextLine();
System.out.println("Enter Department (Marketing or Other): ");
empDept = myScanner.nextLine();
System.out.println("Enter Designation (Manager, Executive or Other):");
designation = myScanner.nextLine();
System.out.println("Enter Basic Salary: ");
basicSalary = myScanner.nextInt();
}
public void SetBonus()
{
if(basicSalary < 1500){
bonus = 0.0;
}
else if(basicSalary>=1500 && basicSalary<3000){
bonus = basicSalary * (12.0/100.0);
}
else if(basicSalary>=3000 && basicSalary<5000){
bonus = basicSalary * (15.0/100.0);
}
else{
bonus = basicSalary * (25.0/100.0);
}
}
public void SetCommission()
{
if(empDept.equalsIgnoreCase("other")){
commission = 0.0;
}
else if(empDept.equalsIgnoreCase("marketing") && designation.equalsIgnoreCase("manager")){
commission = basicSalary * (30.0/100.0);
}
else if(empDept.equalsIgnoreCase("marketing") && designation.equalsIgnoreCase("executive")){
commission = basicSalary * (15.0/100.0);
}
else if(empDept.equalsIgnoreCase("marketing") && designation.equalsIgnoreCase("other")){
commission = basicSalary * (10.0/100.0);
}
else{
commission = 0.0;
}
}
public void SetNssf()
{
if(basicSalary < 1500){
nssf = basicSalary * (5.0/100.0);
}
else if(basicSalary>=1500 && basicSalary<3000){
nssf = basicSalary * (8.0/100.0);
}
else if(basicSalary>=3000 && basicSalary<5000){
nssf = basicSalary * (12.0/100.0);
}
else if(basicSalary>=5000 && basicSalary<7000){
nssf = basicSalary * (15.0/100.0);
}
else if(basicSalary>=7000 && basicSalary<10000){
nssf = basicSalary * (20.0/100.0);
}
else{
nssf = basicSalary * (25.0/100.0);
}
}
public void SetNetSalary()
{
netSal=(basicSalary + commission + bonus) - nssf;
}
public void GetPayroll()
{
System.out.println("\n\n\n\t\tPayroll Details \n____________________________________________________\n");
System.out.println("Employee Id : " + empID + "\t\t Bonus : " + bonus);
System.out.println("Name : " + empName + "\t\t\t\t Commission : " + commission);
System.out.println("Department : " + empDept + "\t\t NSSF : " + nssf);
System.out.println("Designation : " + designation + "\t\t NetSalary : " + netSal);
System.out.println("Basic Salary : " + basicSalary + "\n");
}
}
「衝突」是什麼意思?輸出結果混合起來了嗎?你能顯示你的輸出嗎? – 2014-10-16 10:40:14
你的問題是什麼? – karvoynistas 2014-10-16 10:41:01
您在打印語句中缺少\ n – Madhesh 2014-10-16 10:43:11