我已经尝试了网站上已经给出的各种建议。但老实说,我找不到解决问题的方法。
基本上,当我尝试使用在 Accept... 中创建的任何变量时,它不能用于其他函数。有没有简单的解决方案来解决这个问题?(不改主代码)
import java.util.Scanner;
class x4Salary
{
Scanner input = new Scanner(System.in);
public void accept()
{
System.out.println("Please input the name of the teacher");
String name = input.next();
System.out.println("Please input the address ");
String adress = input.next();
System.out.println("Please input the phone number");
long num = input.nextLong();
System.out.println("Please input the subject specialization");
String subjectSpecialization = input.next();
String subS = subjectSpecialization;
System.out.println("Please input the Monthly Salary");
long sal = input.nextLong();
if(sal>175000)
{
tax();
}
display();
double tax = 0.0;
}
public void tax()
{
System.out.println("Your current salary is : " + sal);
tax = sal + ((5/sal)*100);
System.out.println("The salary + Tax : " +tax);
display();
}
public void display()
{
System.out.println("The name of the teacher : " + name);
System.out.println("The Address of the teacher :" +adress);
System.out.println("The Phone number of the Teacher: "+num);
System.out.println("The Subject Specialization of the Teacher" + subS);
System.out.println("The Monthly salary of the teacher" +sal + tax);
}
}