错误:找不到符号符号:变量A.

时间:2014-10-16 20:33:06

标签: java variables symbols

我正在尝试创建一种在控制台中打印的工资单但我从代码中收到以下错误。它真的只是一次错误很多次,但我不认为我有足够的java知识可以自己解决它。

import java.io.*;
import java.text.*;
import java.util.Scanner;

class Assign2num2 
{
  public static void main (String [] args)
  {
   String famname, firstname;
   double gross, deduct, tax, pay, hrs, ovtm;
   char letter, yn;
   Scanner in = new Scanner(System.in);
   System.out.println("Please enter your family name and first name.");
   famname = in.nextLine();
   firstname = in.nextLine();
System.out.println("Please enter how much you are paid per hour and the amount of hours you worked this week. Enter overtime hours seperately please.");
pay = in.nextInt();
 if (pay<0) {
  System.out.println("You must enter a positive number or zero for your hourly pay.");
    pay = in.nextInt();
 }
  else {
    pay = pay;
  }
hrs = in.nextInt();
 if (hrs<0||hrs>40) {
  System.out.println("You must enter a positive number less than or equal to 40, or zero for the amount of hours worked this week.");
    hrs = in.nextInt();
 }
  else {
    hrs = hrs;
  }
ovtm = in.nextInt();
 if (ovtm<0) {
  System.out.println("You must enter a positive number or zero for your overtime hours worked.");
    ovtm = in.nextInt();
 }
  else {
    ovtm = ovtm;
  }
   gross = (pay*hrs) + ((pay*2)*ovtm);
System.out.println("Please enter a letter indicating your tax category: A is no tax deduction, B is 10% of gross pay, \nC is 20% of gross pay, D is 29% of gross pay, E is 35% of gross pay");
letter = in.next().charAt(0);
 if (letter==A||letter==a){
  letter = letter;
  gross = gross;
 }
  else if (letter==B||letter==b){
  letter = letter;
  deduct = (gross*0.1);
  tax = gross - deduct;  
 }
  else if (letter==C||letter==c){
  letter = letter;
  deduct = (gross*0.2);
  tax = gross - deduct;
 }
  else if (letter==D||letter==d){
  letter = letter;
  deduct = (gross*0.29);
  tax = gross - deduct;
 }
  else if (letter==E||letter==e){
  letter = letter;
  deduct = (gross*0.35);
  tax = gross - deduct;
 }
  else {
    System.out.println("You must enter a letter between A and E.");
     letter = in.next().charAt(0);
 }

System.out.println("If you want $20.00 deducted from your weekly pay as a contribution to the \nUnited Way Charity, enter Y for yes. If not, enter N for no.");
yn = in.next().charAt(0);
if (letter==Y||letter==y||letter==N||letter==n){
  yn = yn;
 }
  else {
    System.out.println("You must enter either Y or N.");
    yn = in.next().charAt(0);
 }
  if (yn==Y||yn==y) {
    deduct = deduct + 20;
    tax = tax - 20;
  }
   else {
    deduct = deduct;
    tax = tax;
  System.out.println("PAY SLIP");
  System.out.println("---------");
  System.out.println(famname + ", " + firstname);
  System.out.println("---------");
  System.out.println("Gross Pay: " + gross);
  System.out.println("---------");
  System.out.println("Deductions: " + deduct);
  System.out.println("---------");
  System.out.println("Net Pay: " + tax);
  }
 }
}

16 errors found:
File: G:\Computer Science\Dr Java Exercises\Java Files\Assign2num2.java  [line: 44]
Error: cannot find symbol
symbol:   variable A
location: class Assign2num2
File: G:\Computer Science\Dr Java Exercises\Java Files\Assign2num2.java  [line: 44]
Error: cannot find symbol
symbol:   variable a
location: class Assign2num2
File: G:\Computer Science\Dr Java Exercises\Java Files\Assign2num2.java  [line: 48]
Error: cannot find symbol
symbol:   variable B
location: class Assign2num2
File: G:\Computer Science\Dr Java Exercises\Java Files\Assign2num2.java  [line: 48]
Error: cannot find symbol
symbol:   variable b
location: class Assign2num2
File: G:\Computer Science\Dr Java Exercises\Java Files\Assign2num2.java  [line: 53]
Error: cannot find symbol
symbol:   variable C
location: class Assign2num2
File: G:\Computer Science\Dr Java Exercises\Java Files\Assign2num2.java  [line: 53]
Error: cannot find symbol
symbol:   variable c
location: class Assign2num2
File: G:\Computer Science\Dr Java Exercises\Java Files\Assign2num2.java  [line: 58]
Error: cannot find symbol
symbol:   variable D
location: class Assign2num2
File: G:\Computer Science\Dr Java Exercises\Java Files\Assign2num2.java  [line: 58]
Error: cannot find symbol
symbol:   variable d
location: class Assign2num2
File: G:\Computer Science\Dr Java Exercises\Java Files\Assign2num2.java  [line: 63]
Error: cannot find symbol
symbol:   variable E
location: class Assign2num2
File: G:\Computer Science\Dr Java Exercises\Java Files\Assign2num2.java  [line: 63]
Error: cannot find symbol
symbol:   variable e
location: class Assign2num2
File: G:\Computer Science\Dr Java Exercises\Java Files\Assign2num2.java  [line: 75]
Error: cannot find symbol
symbol:   variable Y
location: class Assign2num2
File: G:\Computer Science\Dr Java Exercises\Java Files\Assign2num2.java  [line: 75]
Error: cannot find symbol
symbol:   variable y
location: class Assign2num2
File: G:\Computer Science\Dr Java Exercises\Java Files\Assign2num2.java  [line: 75]
Error: cannot find symbol
symbol:   variable N
location: class Assign2num2
File: G:\Computer Science\Dr Java Exercises\Java Files\Assign2num2.java  [line: 75] 
Error: cannot find symbol
symbol:   variable n
location: class Assign2num2
File: G:\Computer Science\Dr Java Exercises\Java Files\Assign2num2.java  [line: 82]
Error: cannot find symbol
symbol:   variable Y
location: class Assign2num2
File: G:\Computer Science\Dr Java Exercises\Java Files\Assign2num2.java  [line: 82]
Error: cannot find symbol
symbol:   variable y
location: class Assign2num2

3 个答案:

答案 0 :(得分:2)

当您将变量与预期字符进行比较时,该字符必须使用单引号,否则编译器会认为它是另一个未定义的变量。

E.g。变化

if (letter==A||letter==a){

if (letter=='A'||letter=='a'){

答案 1 :(得分:0)

你需要使用&#39; &#39;

if (letter == 'A')
char文字必须被&#39; &#39;和字符串文字必须被&#34;包围。 &#34;

答案 2 :(得分:0)

使用字母=='D',同样如此。字符文字用单引号括起来。