java中双倍下降的折旧

时间:2014-10-03 04:03:59

标签: java math

我正在开发一个基于控制台的简单程序来计算设定时间间隔内的折旧。我已经有了单行折旧的代码(它的折旧率为其原始值的1 / n)。我遇到双倍折旧问题(每年年初新价格折旧)

import java.util.*;
import java.text.*;
public class Number6 {

public static void main(String[] args){

Scanner scan = new Scanner(System.in);

  int year = 2001;
  int lifeSpan = 3;
  int limit = year + lifeSpan -1 ;
  double cost = 1500;
  double depreciation = cost/lifeSpan;
  double totalDepreciation  = 0;

System.out.println("Enter The Method Of Depriciation (straight-line or double-declining)");
String method = scan.next();

System.out.println("Please Enter The Description Of The Prodect");
String desc = scan.next();

System.out.println("Please Enter The Year Of The Product");
year = scan.nextInt();

System.out.println("Please enter cost of prodect");
cost = scan.nextInt();

System.out.println("Please Enter Years Of Depreciation");
lifeSpan = scan.nextInt();


 NumberFormat nf =  NumberFormat.getCurrencyInstance();

 System.out.println("Description: "+ desc);
 System.out.println("Year Of Purchase: "+ year);
 System.out.println("Cost Of Purchase: "+ cost);
 System.out.println("Estimated Life: "+ lifeSpan) ;
 System.out.println("Method Of Depreciation: "+ method);


 if(method.equalsIgnoreCase("straight-line")){//basically this while loop is for the fisrt type of depreciation
  while(year <= limit)
  {
      System.out.print(year + "\t");
      System.out.print(nf.format(cost) + "\t\t\t");
      depreciation = cost/lifeSpan;
      System.out.print(nf.format(depreciation) + "\t\t\t");
      totalDepreciation += depreciation;
      System.out.print(nf.format(totalDepreciation) + "\n");
      cost -= depreciation;
      year++;
  }
 }else if(method.equalsIgnoreCase("double-declining")){




     //but this is where the other type of depreciation that I cannot figure out would go


 }

 scan.close();

}

}

1 个答案:

答案 0 :(得分:1)

区别在于您需要根据项目的当前账面价值计算每年的折旧:

double depreciationRate = 0.3;  // 0.3 assumes a 30% depreciation each year

 }else if(method.equalsIgnoreCase("double-declining")){
  while(year <= limit)
  {
      System.out.print(year + "\t");
      System.out.print(nf.format(cost) + "\t\t\t");
      depreciation = cost*depreciationRate;                      // This is the "magic" - n% of the book value, so a new value is calculated for each year.
      System.out.print(nf.format(depreciation) + "\t\t\t");
      totalDepreciation += depreciation;
      System.out.print(nf.format(totalDepreciation) + "\n");
      cost -= depreciation;
      year++;
  }