gpt4 book ai didi

java - 错误: cannot find symbol symbol: variable A

转载 作者:行者123 更新时间:2023-12-02 05:22:15 32 4
gpt4 key购买 nike

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

最佳答案

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

例如改变

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

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

关于java - 错误: cannot find symbol symbol: variable A,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26413406/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com