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

时间:2023-01-25 19:47:41

I am trying to create a sort of pay slip to print in the console but I receive the following errors from my code. Its really just one error many times, but I don't think I have enough knowledge of java to fix it on my own.

我正在尝试创建一种在控制台打印的工资单,但是我从我的代码中收到了以下错误。它实际上只是一个错误,但我认为我没有足够的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 个解决方案

#1


2  

When you compare variables to an expected character, the character must be in single quotes, else the compiler thinks that it's another variable, which isn't defined.

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

E.g. change

如改变

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

to

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

#2


0  

you need to use ' '

你需要使用' '

if (letter == 'A')

char literals have to be sorrounded by ' ' and string literals have to be surrounded by " "

字符文字必须用' '来表示,字符串文字必须用" "来表示

#3


0  

Use letter=='D', and likewise. Char literals are enclosed in single quotes.

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

#1


2  

When you compare variables to an expected character, the character must be in single quotes, else the compiler thinks that it's another variable, which isn't defined.

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

E.g. change

如改变

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

to

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

#2


0  

you need to use ' '

你需要使用' '

if (letter == 'A')

char literals have to be sorrounded by ' ' and string literals have to be surrounded by " "

字符文字必须用' '来表示,字符串文字必须用" "来表示

#3


0  

Use letter=='D', and likewise. Char literals are enclosed in single quotes.

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