员工使用java计算工资的工作

时间:2013-03-07 15:05:29

标签: java

代码中缺少某些东西..如果我选择兼职(1号),它必须只显示小时费率和工作时间来计算收入..但加班费,加班时间和加班费继续显示如果我选择(2号)他们应该出来的时候:

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;     
                    }
            }
        }

1 个答案:

答案 0 :(得分:0)

尝试

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