2013-03-07 73 views
-5

代碼中缺少一些東西。如果我選​​擇兼職(1號),它只能顯示每小時的工資率和工作時間來計算收入......但加班工資,加班費時間和加班率不斷時,他們都應該出來,如果我選擇(第2號)顯示:員工的工作使用java計算工資

import java.io.*; 
    import java.util.*; 
    import java.util.Scanner; 
//author: Misty Stewart 

    public class salary{ 
      static Scanner console=new Scanner(System.in); 
       public static void main (String[]args) { 

       String name = ""; 
       int kindOfEmployee; 
       int overtimePay = 0; 
       int HRate = 0; 
       int HWorked = 0; 
       int regularPay = 0; 
       int overtimeRate = 0; 
       int overtimeHours = 0; 
       int Income = 0; 

       Scanner input = new Scanner(System.in); 

       System.out.println("Enter Name of the employee:"); 
       name = console.next(); 
      System.out.println("1]Part-time Employee"); 
      System.out.println("2]Full-time Employee"); 
      System.out.println("Choose what kind of employee?"); 
      kindOfEmployee=console.nextInt(); 

      System.out.println("Hourly Rate:"); 
       HRate = input.nextInt(); 
       System.out.println("Hours Worked:"); 
       HWorked = input.nextInt(); 
       System.out.println("Regular Pay:"); 
       regularPay = input.nextInt(); 
      System.out.println("Overtime Rate:"); 
       overtimeRate = input.nextInt(); 
       System.out.println("Overtime Hours:");  
       overtimeHours = input.nextInt(); 
       overtimePay = overtimeRate*overtimeHours; 

       System.out.println("Name of the employee: "+name); 
       System.out.println("Income: "+Income); 

       if (kindOfEmployee == 1){ 
        Income = HRate*HWorked;    
         } 
       if (kindOfEmployee == 2){ 
        Income = regularPay+overtimePay;  
        } 
      } 
     } 
+0

將我怎樣做才能停止展示呢? – thisOneNeedsHelp 2013-03-07 15:06:22

+0

兼職時間1號和2號,我上面說的代碼指kindOfEmplyee – thisOneNeedsHelp 2013-03-07 15:08:12

+0

你打印收入之前,你通過邏輯運行。 – tymeJV 2013-03-07 15:09:39

回答

0

嘗試

if (kindOfEmployee == 2) { 
    System.out.println("Overtime Rate:"); 
    overtimeRate = input.nextInt(); 
    System.out.println("Overtime Hours:");  
    overtimeHours = input.nextInt(); 
    overtimePay = overtimeRate*overtimeHours; 
} 
+0

非常感謝你的先生! :)... 我知道了.. – thisOneNeedsHelp 2013-03-07 16:05:19