2016-11-29 4 views
-5

私はコーディング時に新しいです。私はjGraspで給与計算の登録をしようとしていますが、 "シンボルを見つけることができません"と "変数はすでにメソッドに定義されています。私は既に変数の1つを定義したように見えますが、変数を適切に動作させるために何を変更するかを知ることはできません。私は下のエラーでスポットをマークした。助けをあらかじめありがとう!エラー "シンボルを見つけることができません"と "変数は既にメソッドに定義されています"

あなたは整数20、30、などと比較されているとして、あなたの case文( empDeptCodeが整数であるとして、あなたが switch(empDeptCode)に変更した場合、それが動作するには... switch(empDeptCode)switch(empDeptNumb)からあなた switchを変更する必要が
//Lab4 Payroll Register Refinements 

//this makes available all extra utilities from Java library including scanner 
import java.util.*; 
import java.io.*; //needed for files 



public class Lab4 // class name MUST be name of .java file 
{//start of class 
    public static void main(String [] args) throws FileNotFoundException 

    {// start of main method 
     Scanner keyIn = new Scanner(System.in); 
     // assigns "keyIn" to keyboard 

     Scanner inPayrollFile = new Scanner(new FileReader("Lab4Input1.txt")); 
     // assigns "inPayrollFile" to input file 

     PrintWriter outPayrollFile = new PrintWriter("Lab4Output1.txt"); 
     // assigns "outPayrollFile" to output file 

     //System.out displays on the monitor 


    //Variables and defined constants go here 

     final String HEADING1 = "ID#  HOURS  RATE GROSS  DEDUCT  NET"; //example of a defined constant 

     String employeeName;  //Employee's name is entered 
     int empId;    //Employee's Id number is entered 
     int empDeptCode;   //Employee's department code is entered 
     double hoursWorked;  //Amount of hours worked is entered 
     double hourlyPayRate;  //Employee's hourly pay rate is entered 
     double empOvertimePay; //Employee's overtime rate 
     double empRegPay;   //Employee's regular rate of pay 
     double empBonus;   //Employee's bonus pay 
     double grossPay;   //Employee's gross pay 
     double deduction;   //Amount deducted from gross pay 
     double netPay;   //Employee net pay 
     double totalGrossPay = 0; //Employee's total gross pay 
     double totalNetPay = 0; //Employee's total net pay 
     double totalDeduction = 0;//Total amount deducted 
     int totalEmployees = 0; //Total number of employees 
///////////////////////////////////////////////////////////////////////////  
    //instructions start here 

    System.out.println ("Please enter Employee name: "); 
    employeeName = keyIn.nextLine(); 

     //before loop instructions go here 

      outPayrollFile.println (HEADING1); 
     //example of Printing report heading to the output file 


/////////////////////////////////////////////////////////////////////////// 
    //loop, which has input, process, output 
      while(inPayrollFile.hasNext()) 
     {//start while loop - hasNext is TRUE when there is an input record 
     //     hasNext is FALSE when no more input records - the loop ends 

      //input - within loop 

      empId = inPayrollFile.nextInt(); //example of reading from input file 
     hoursWorked = inPayrollFile.nextDouble (); 
     hourlyPayRate = inPayrollFile.nextDouble (); 
     empDeptCode = inPayrollFile.nextInt(); 
     System.out.println ("Processing empId" + empId); 


      //process - within loop 

     empRegPay = getRegPay(hoursWorked, hourlyPayRate); 
     empOvertimePay = getEmpOvertimePay(hoursWorked, hourlyPayRate); 
     grossPay = empRegPay + empOvertimePay; 
     empBonus = getBonus(grossPay, hoursWorked, empDeptCode); 
     grossPay = grossPay + empBonus; 
     deduction = getDeduction(grossPay); 
     netPay = grossPay - deduction; 



     if (grossPay > 1000) 
     { 
      deduction = grossPay * 0.30; 
     } 
     else 
     { deduction = grossPay * 0.25; 
     } //endif 

     netPay = (grossPay - deduction); 
     totalGrossPay = (totalGrossPay + grossPay); 
     totalDeduction = (totalDeduction + deduction); 
     totalNetPay = (totalNetPay + netPay); 
     totalEmployees = (totalEmployees + 1); 


     if (grossPay > 1000) 
     { 
      deduction = grossPay * 0.30; 
     } 
     else 
     { deduction = grossPay * 0.25; 
     } //endif 
      //output - within loop 

     outPayrollFile.printf ("%4d", empId); 
     outPayrollFile.printf ("%10.2f", hoursWorked); 
     outPayrollFile.printf ("%10.2f", hourlyPayRate); 
     outPayrollFile.printf ("%10.2f", grossPay); 
     outPayrollFile.printf ("%10.2f", deduction); 
     outPayrollFile.printf ("%10.2f%n", netPay); 


     }//end while loop 

       /////////////////////////////////////////////////////////////////////////// 
    //after loop instructions go here 

     System.out.println (); 
     outPayrollFile.printf ("Total%29.2f", totalGrossPay); 
     outPayrollFile.printf ("%10.2f", totalDeduction); 
     outPayrollFile.printf ("%10.2f%n", totalNetPay); 
     outPayrollFile.printf ("Total Employees%4d", totalEmployees); 
     inPayrollFile.close(); 
     outPayrollFile.close(); 
     System.out.println ("Program Completed"); 
     System.out.println ("Program written by " + employeeName); 


    }//end of main 


/////////////////////////////////////////////////////////////////////////// 
    //regular pay method goes here 
/////////////////////////////////////////////////////////////////////////// 

public static double getRegPay (double mEmpHours, double mEmpRate) 

{//begin method 
    double result;  //local variable for gross 

     if (mEmpHours > 40) 
     { 
      result = mEmpRate * 40; 
     } 
     else 
     { result = mEmpHours * mEmpRate; 
     } //endif 


    return result;  //value in mGross is returned  
}//end method 

/////////////////////////////////////////////////////////////////////////// 
    //overtime pay method goes here 
/////////////////////////////////////////////////////////////////////////// 

public static double getEmpOvertimePay (double mEmpHours, double mEmpRate) 

{//begin method 
    double result;  //local variable for gross 

     if (mEmpHours > 40) 
     { 
      result = mEmpRate * 1.5 * (mEmpHours - 40); 
     } 
     else 
     { result = 0; 
     } //endif  


    return result;  //value in mGross is returned  
}//end method 

/////////////////////////////////////////////////////////////////////////// 
    //gross pay method goes here 
/////////////////////////////////////////////////////////////////////////// 

public static double getGrossPay (double empRegPay, double empOvertimePay) 

{//begin method 
    double result;  //local variable for gross pay 

      result = empRegPay + empOvertimePay; 

    return result;  //value in gross pay is returned 
}//end method   

/////////////////////////////////////////////////////////////////////////// 
    //bonus pay method goes here 
/////////////////////////////////////////////////////////////////////////// 

public static double getBonus (double mGrossPay, double mEmpHours, int mEmpDept) 

{//begin method 
    double mBonus; //local variable for bonus 

     if (mEmpDept ==25) 
     if (mEmpHours >= 40) 

      mBonus = 0.10 * mGrossPay; 
     else 
      mBonus = 0.05 * mGrossPay; 

     else mBonus = 0; 

    return mBonus; //value in mBonus is returned   
}//end method 

//switch method/translation of department code to department name 
public static String getEmpDeptCode (int empDeptCode) 

{//begin method 
String empDeptNumb; 

switch (empDeptNumb) 
{//begin switch 
    case 20:   //if code = 20 
     empDeptNumb = "Administration"; 
     break; 

    case 23:   //if code = 23 
     empDeptNumb = "Production"; 
     break; 

    case 25:   //if code = 25 
     empDeptNumb = "Sales"; 
     break; 

    default:   //else if none of the cases are true 
     empDeptNumb = "Invalid"; 

}//end switch 
return empDeptNumb; 
}//end method 

/////////////////////////////////////////////////////////////////////////// 
    //second gross pay method goes here 
/////////////////////////////////////////////////////////////////////////// 

public static double getEmpGrossPay (double empGrossPay, double empBonus) 

{//begin method 
    double result;  //local variable for gross pay 

      result = empGrossPay + empBonus; 

    return result;  //value in gross pay is returned 
}//end method   


////////////////////////////////////////////////////////////////////////// 
    //deduction pay method goes here 
////////////////////////////////////////////////////////////////////////// 
public static double getDeduction (double mGross) 
// getDeduction is the value-returning method name 
// it will be sent a double and that value goes into mGross 
{//begin method 
    double mDeduction; //local variable for deduction 

    if (mGross > 1000) 
     mDeduction = (mGross - 1000) * 0.30 + 225; 
    else 

    if (mGross > 500) 
     mDeduction = (mGross - 500) * 0.25 + 100; 
    else 
     mDeduction = mGross * 0.20; 

    return mDeduction; //value in mDeduction is returned 
}//end method 

////////////////////////////////////////////////////////////////////////// 
    //net pay method goes here 
////////////////////////////////////////////////////////////////////////// 

public static double getNetPay (double empGrossPay, double empDeduction) 

{//begin method 
    double netPay;  //local variable for net pay 

      result = empGrossPay - empDeduction; <--- this is the first error 

    return result;  //value in net pay is returned <--- this is the second error 
}//end method   

/////////////////////////////////////////////////////////////////////////// 
    //department code method goes here 
/////////////////////////////////////////////////////////////////////////// 

public static double empDeptNumb (double empDeptNumb) 

{//begin method 
    double empDeptCode; //local variable for empDeptCode <---this is the third error 

      result = empDeptNumb; <---this is the fourth error 

    return result;  //value in empDeptNumb is returned <--- the final error 
}//end method 

}//end of class  
+2

は、あなたが初期化されていない文字列を切り替えると、あなたが期待する「スイッチ(empDeptCode)」である必要がありますにすべてであることを賭けていますそれは継続するべきではないain)数字?それはどうやって動くのだろう? – Tom

答えて

1

+0

答えをありがとう!それはその問題を修正しましたが、私はもう1つを持っています-_- –

0

私はこれが原因あなたが持っているタイプミス。「スイッチ(empDeptNumb)」を、それはおそらく

関連する問題