How to calculate depreciation per years in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        double amount, deppercent, years;
          
        amount = 1000;
        deppercent = 40; // 40%
        years = 3;
          
        double amount_left = amount;
          
        double annual_depreciation = 0;
         
        System.out.println("Initial amout = " + amount_left);
          
        for(int i = 0; i < years; i++) {
            annual_depreciation = (deppercent * amount_left) / 100;
            amount_left = amount_left - annual_depreciation;
            System.out.format("Year %d: Annual depreciation = %.2f Amount left = %.2f\n", i + 1, annual_depreciation, amount_left);
        }
  
        System.out.println("Amount after depreciation = " + amount_left);
    }
}




/*
run:

Initial amout = 1000.0
Year 1: Annual depreciation = 400.00 Amount left = 600.00
Year 2: Annual depreciation = 240.00 Amount left = 360.00
Year 3: Annual depreciation = 144.00 Amount left = 216.00
Amount after depreciation = 216.0

*/

 



answered Aug 15, 2021 by avibootz
edited Aug 15, 2021 by avibootz

Related questions

1 answer 207 views
1 answer 227 views
227 views asked Aug 15, 2021 by avibootz
1 answer 279 views
1 answer 234 views
1 answer 319 views
1 answer 247 views
1 answer 422 views
...