2016-10-15 4 views
1

総賃金が「そういうもの」と「それ」の間であるかどうかを把握しなければなりません。これは「この」税率などです。私は問題ないと思っていましたが、私が働いている時間に高い数字を入力すると答えます。このように "控除は275.0165.0770.0000000000001"です。Javaで給与計算を試行しようとしている

私はこれを非常に長い方法でやっているのですが、私は思っています。 ありがとうございました!

import java.util.Scanner; 
public class prob2 
{ 
    public static void main(String[] args){ 
     Scanner in = new Scanner(System.in); 

     double range = (168); 

     System.out.println("Enter the number of hours worked in a week:"); 
     double hours = in.nextDouble(); 

     System.out.println("Enter rate per hour:"); 
     double rate = in.nextDouble(); 

     double overtimeHours = hours - 40; 
     double overtimePay = (overtimeHours * rate) * 1.5; 
     double basePay = (hours - overtimeHours) * rate; 
     double grossPay = basePay + overtimePay; 
     double socialSecurity = .1 * grossPay; 
     double medical = .06 * grossPay; 

     if (overtimeHours < 0) 
     { 
      System.out.println("Number of overtime hours are " + 0); 
     } 
     else 
     { 
      System.out.println("Number of overtime hours are " + overtimeHours); 
     } 

     if (overtimeHours < 0) 
     { 
      System.out.println("Base pay is " + hours * rate); 
     } 
     else 
     { 
      System.out.println("Base pay is " + basePay); 
     } 

     if (overtimeHours < 0) 
     { 
      System.out.println("Overtime pay is " + 0); 
     } 
     else 
     { 
      System.out.println("Overtime pay is " + overtimePay); 
     }   

     if (grossPay < 0) 
     { 
      System.out.println("Gross pay is " + hours * rate); 
     } 
     else 
     { 
      System.out.println("Gross pay is " + grossPay); 
     } 

     if (grossPay > 0 && grossPay < 43) 
     { 
      System.out.println("Deductions are " + socialSecurity + medical); 
     } 
     else 

     if (43.01 < grossPay && grossPay < 218.00)   
     { 
      System.out.println("Deductions are " + socialSecurity + medical + (.10 * grossPay)); 
     } 
     else 

     if (218.01 < grossPay && grossPay < 753.00)    
     { 
      System.out.println("Deductions are " + socialSecurity + medical + (.15 * grossPay)); 

     } 
     else 

     if (grossPay > 0 && 753.01 < grossPay && grossPay < 1762.00)    
     { 
      System.out.println("Deductions are " + socialSecurity + medical + (.25 * grossPay)); 

     } 
     else 

     if (1762.01 < grossPay && grossPay < 3627.00)    
     { 
      System.out.println("Deductions are " + socialSecurity + medical + (.28 * grossPay)); 

     } 
    } 
} 

答えて

0

括弧の中にあなたの合計をラップしてください:

System.out.println("Deductions are " + (socialSecurity + medical)); 

この場合、それはそれ以外の場合は、一つの医療1その後、socialSecurityをCONCATなり、文字列につながる連結最初に合計を作成します。

コード内に同様のケースがある場合、同じルールが適しています。

関連する問題