62,614
社区成员
发帖
与我相关
我的任务
分享
import java.util.Scanner;
class Tools
{
final static int START_TAX = 2000;
private static double tax;//这里要设置为static
public static double computeTax(double wage) ////这里也要设置为static
{
if (wage - START_TAX <= 0)
{
tax = 0;
}
if (wage - START_TAX <= 500)
{
tax = (wage - 2000) * 0.05;
}
if ((wage - START_TAX > 500) && (wage - START_TAX <= 2000))
{
tax = (wage - 2000) * 0.1 - 25;
}
if (wage - START_TAX > 2000)
{
tax = (wage - 2000) * 0.15 - 125;
}
return tax;
}
}
public class Salary
{
String employeeId = "";
double wage = 0;
static double tax = 0;
double realWage = 0;
public double computeTax()
{
tax =Tools.computeTax(wage);
return tax;
}
public double computeRealWage()
{
realWage = wage - this.computeTax();
return realWage;
}
public static void main(String[] args)
{
Salary salary = new Salary();
Scanner sc = new Scanner(System.in);
System.out.println("职工号");
salary.employeeId = sc.nextLine();
System.out.println("税前工资");
salary.wage = sc.nextDouble();
System.out.println("职工号" + salary.employeeId + "税前工资" + salary.wage
+ "扣税" + salary.computeTax() + "实发工资"
+ salary.computeRealWage());
}
}
import java.util.Scanner;
class Tools
{
final static int START_TAX = 2000;
double tax;
public double computeTax(double wage)
{
if (wage - START_TAX <= 0)
{
tax = 0;
}
if (wage - START_TAX <= 500)
{
tax = (wage - 2000) * 0.05;
}
if ((wage - START_TAX > 500) && (wage - START_TAX <= 2000))
{
tax = (wage - 2000) * 0.1 - 25;
}
if (wage - START_TAX > 2000)
{
tax = (wage - 2000) * 0.15 - 125;
}
return tax;// 把大括号里面的return语句去掉,直接在外面return。
}
}
public class Salary
{
String employeeId = "";
double wage = 0;
static double tax = 0;
double realWage = 0;
public double computeTax()
{
tax = new Tools().computeTax(wage);// 这里没必要把此函数设置为static的。
return tax;
}
public double computeRealWage()
{
realWage = wage - this.computeTax();
return realWage;
}
public static void main(String[] args)
{
Salary salary = new Salary();
Scanner sc = new Scanner(System.in);
System.out.println("职工号");
salary.employeeId = sc.nextLine();
System.out.println("税前工资");
salary.wage = sc.nextDouble();
System.out.println("职工号" + salary.employeeId + "税前工资" + salary.wage
+ "扣税" + salary.computeTax() + "实发 工资"
+ salary.computeRealWage());
}
}