import java.util.Scanner;
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());
}
}
class Tools
{
final static int START_TAX=2000;
double tax;
public double computeTax(double wage)
{
if(wage-START_TAX<=0){
tax=0;
return tax;
}
if(wage-START_TAX<=500)
{
tax=(wage-2000)*0.05;
return tax;
}
if((wage-START_TAX>500)&&(wage-START_TAX<=2000))
{
tax=(wage-2000)*0.1-25;
return tax;
}
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());
}
}
class Tools
{
final static int START_TAX=2000;
double tax;
public double computeTax(double wage)
{
if(wage-START_TAX<=0){
tax=0;
return tax;
}
if(wage-START_TAX<=500)
{
tax=(wage-2000)*0.05;
return tax;
}
if((wage-START_TAX>500)&&(wage-START_TAX<=2000))
{
tax=(wage-2000)*0.1-25;
return tax;
}
if(wage-START_TAX>2000)
{
tax=(wage-2000)*0.15-125;
return tax;
}
}
}
解决方案 »
- JAVA SOCKET
- 怎样把异常一次全部捕获?
- 如何用JAVA 写登陆功能!
- 程序完成的后续工作
- 第三方JDBC疑问!
- 访问Anonymouse inner class 的方法。
- 一个方法中出现的异常什么时候应该抛出来,什么时候应该在方法里处理?
- 急求SQL问题与JAVA程序问题。。。。
- 在JB中怎样加上com.borland.jbcl.layout.*这个包急用谢谢了。在线等待。
- 为什么 总是 Exception in thread "main" java.lang.NoClassDefFoundError: NewsRobot/class????
- 求教服务器tcp连接数被占满的问题
- Invalid byte 2 of 2-byte UTF-8 sequence.问题,一直未解决!
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());
}
}
{
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());
}
}
“无法从静态上下文中引用非静态 方法”:
public double computeTax(){
tax=Tools.computeTax(wage);
return tax;
}
这里用对类的静态方法调用,没有new Tools().computeTax(wage),
而public double computeTax(double wage)
声明的是实例方法,只能通过对象实例调用。
还有return那一句的变量作用域问题。