【问题标题】:Sum of Years depreciation class return issue年总和折旧类退货问题
【发布时间】:2014-06-10 02:45:41
【问题描述】:

因此,我的任务是创建一个表单,用户可以输入购置成本、残值和物品的使用寿命。我有 3 种单独的折旧方法,直线法、年数总和和双倍递减法。直线我工作正常,但最后两个在退货单上给了我相同的问题,在应该变化的情况下给每年相同的折旧(我得到了一个结果示例)。下面是年总和的类部分和整个类的公共变量。接下来是给出返回语句的私有双精度。

变量:

    public class DepreciationScheduleClass {
    NumberFormat money = NumberFormat.getCurrencyInstance();
    // the schedule is just an array of formatted strings
    public String[] schedule;
    int period;

方法:

    public void MakeSumOfYearsDigitSchedule(double acquisitionCost, 
    double salvageValue, int usefulLife)
{        
    double totalDepreciation = 0.0;
    double undepreciatedAmount = acquisitionCost;
    double depreciation = SYD(acquisitionCost,salvageValue,usefulLife,period);

    String scheduleLine;

    schedule = new String[usefulLife + 2];

    // add period 0 to schedule
    scheduleLine = "0\t " + money.format(depreciation) + "  \t  " 
            + money.format(undepreciatedAmount); 
    schedule[0] = scheduleLine;

    //add period lines to schedule
    for (int i = 1; i <= usefulLife; i++)
    {
        totalDepreciation = totalDepreciation + depreciation;
        undepreciatedAmount = acquisitionCost - totalDepreciation;
        scheduleLine = i + "\t " + money.format(depreciation) + "  \t  " 
            + money.format(undepreciatedAmount);
        schedule[i] = (scheduleLine);
    }

    //add total depreciation line to schedule
    schedule[usefulLife + 1] = "Total depreciated \t" + 
            money.format(totalDepreciation);
}

带返回的私有双精度:

    private double SYD(double acquisitionCost, 
        double salvageValue, int usefulLife, int period)
{  
    double SOYlife=(usefulLife*(usefulLife+1))/2; 
    return ((usefulLife-period)/SOYlife)*(acquisitionCost-salvageValue);
}

老实说,我认为我只是错过了一些非常简单的东西,但我一遍又一遍地回顾它,我需要另一双眼睛和大脑来看看。提前致谢!

编辑

很抱歉给您带来了困惑。在这方面还是新的。

这就是我得到的。 !http://i.imgur.com/HZQfLjr.jpg

这就是我应该得到的。 !http://i.imgur.com/E51RSng.jpg

我认为导致我出现问题的是给出 return 语句的私有双精度。

【问题讨论】:

  • 你能澄清一下你得到了什么,你应该是什么,以及哪些方法导致了这个问题?有点不清楚
  • 标记为不清楚您在问什么。
  • 年数总和和双倍递减的方法在哪里。
  • @Petro 上面的方法(中间部分代码)是年数总和。我没有提出双重下降,因为我相信这与这个问题相同。

标签: java class return


【解决方案1】:

您需要在循环中根据 (acquisitionCost - totalDepreciation) 计算弃用,而不是仅根据 acquireCost。这就是弃用率逐年降低的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-29
    • 1970-01-01
    • 2021-10-22
    相关资源
    最近更新 更多