Java program to calculate Depreciation. Depreciation is a financial word, defined as the reduction of the recorded cost of a fixed asset in a systematic manner until the value of the asset becomes zero or negligible. We too added how to calculate the Depreciation, formula, and Java program in different ways. Do check it out.
What is Depreciation?
A:
- The decrease in value of assets (fair value depreciation)
- The allocation of the cost of assets to periods in which the assets are used (depreciation with the matching principle)
Depreciation is a method of reallocating the cost of a tangible asset over its useful lifespan of it being in motion. Businesses depreciate long-term assets for both tax and accounting purposes.
How To Calculate Depreciation?
There are mainly three ways to calculate Depreciation.
- Straight line method
- Unit of production method
- Double-declining balance method
You can refer to the article: What is Depreciation and how to calculate.
Java Program By Using Standard Values
[wp_ad_camp_3]
- There you go with standard values.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
class Depreciation { public static void main(String arg[]) { long amount,deppercent,year,afterdep,temp; amount=100000; deppercent=10; year=3; temp=amount; for(int i=0;i<year;i++) temp=((100-deppercent)*temp)/100; System.out.println("after depreciation = "+temp); } } |
output:
1 |
after depreciation = 72900 |
2. Java Program To Calculate Depreciation Through Scanner Class
Here we are taking inputs through scanner class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import java.util.Scanner; class Depreciation { public static void main(String arg[]) { long amount,deppercent,year,afterdep,temp; Scanner sc=new Scanner(System.in); System.out.println("enter amount"); amount=sc.nextLong(); System.out.println("enter Depreciation percentage"); deppercent=sc.nextLong(); System.out.println("enter number of years"); year=sc.nextLong(); temp=amount; for(int i=0;i<year;i++) temp=((100-deppercent)*temp)/100; System.out.println("after depreciation = "+temp); } } |
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
output:1 enter amount 1000 enter Depreciation percentage 10 enter number of years 1 after depreciation = 900 output:2 enter amount 1000 enter Depreciation percentage 10 enter number of years 2 after depreciation = 810 output:3 enter amount 1000 enter Depreciation percentage 10 enter number of years 3 after depreciation = 729 |
3. Inputs Through Command Line Arguments
[wp_ad_camp_3]
There you go another method by taking inputs through command line arguments. Command line arguments, if have no idea about command line arguments then you can check out our article here on what are command line arguments and how it works.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
class Depreciation { public static void main(String arg[]) { long amount,deppercent,year,afterdep,temp; amount=Long.parseLong(arg[0]); deppercent=Long.parseLong(arg[1]); year=Long.parseLong(arg[2]); System.out.println("amount is = "+arg[0]); System.out.println("Depreciation percent = "+arg[1]); System.out.println("number of years = "+arg[2]); temp=amount; for(int i=0;i<year;i++) temp=((100-deppercent)*temp)/100; System.out.println("after depreciation = "+temp); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
output:1 C:\Users\goutham\Desktop\E>javac Depreciation.java C:\Users\goutham\Desktop\E>java Depreciation 2000 20 1 amount is = 2000 Depreciation percent = 20 number of years = 1 after depreciation = 1600 output:2 C:\Users\goutham\Desktop\E>javac Depreciation.java C:\Users\goutham\Desktop\E>java Depreciation 2000 20 2 amount is = 2000 Depreciation percent = 20 number of years = 2 after depreciation = 1280 output:3 C:\Users\goutham\Desktop\E>javac Depreciation.java C:\Users\goutham\Desktop\E>java Depreciation 2000 20 3 amount is = 2000 Depreciation percent = 20 number of years = 3 after depreciation = 1024 |
4. Using a User Define Method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import java.util.Scanner; class Depreciation { public static void main(String arg[]) { long amount,deppercent,year,afterdep,temp; Scanner sc=new Scanner(System.in); System.out.println("enter amount"); amount=sc.nextLong(); System.out.println("enter Depreciation percentage"); deppercent=sc.nextLong(); System.out.println("enter number of years"); year=sc.nextLong(); temp=depreciationCal(amount,deppercent,year); System.out.println("after depreciation = "+temp); } static long depreciationCal(long amount,long deppercent, long year ) { for(int i=0;i<year;i++) amount=((100-deppercent)*amount)/100; return amount; } } |
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
output:1 enter amount 10000 enter Depreciation percentage 50 enter number of years 1 after depreciation = 5000 output:2 enter amount 10000 enter Depreciation percentage 50 enter number of years 2 after depreciation = 2500 output:3 enter amount 10000 enter Depreciation percentage 50 enter number of years 3 after depreciation = 1250 |
5. Creating a Separate Class
- ( DepreciationCalculation) and taking inputs through scanner class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import java.util.Scanner; class DepreciationCalculation { long amount,deppercent,year,afterdep,temp; DepreciationCalculation(long amount,long deppercent, long year ) { afterdep=amount; for(int i=0;i<year;i++) afterdep=((100-deppercent)*afterdep)/100; } } class Depreciation { public static void main(String arg[]) { long amount,deppercent,year,afterdep,temp; Scanner sc=new Scanner(System.in); System.out.println("enter amount"); amount=sc.nextLong(); System.out.println("enter Depreciation percentage"); deppercent=sc.nextLong(); System.out.println("enter number of years"); year=sc.nextLong(); DepreciationCalculation d=new DepreciationCalculation(amount,deppercent,year); System.out.println("after depreciation = "+d.afterdep); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
output:1 enter amount 100000 enter Depreciation percentage 10 enter number of years 5 after depreciation = 59049 output:2 enter amount 80000 enter Depreciation percentage 20 enter number of years 2 after depreciation = 51200 output:3 enter amount 9000 enter Depreciation percentage 50 enter number of years 1 after depreciation = 4500 |