Scarlett
Posts: 3
Nickname: scar78
Registered: Mar, 2004
HELP with depreciation method!!!
Posted: Apr 11, 2004 1:43 PM
Advertisement
i'm trying to caculate the depreciaiton of an asset, but i'm having problems with the method sum of years.I cannot get the rate to work.Can someone help me? import javax.swing.JOptionPane; import java.text.*; public class Depreciation { private double amount, sum, asset; private int year; public void Straightline() { String input; NumberFormat formatter = NumberFormat.getNumberInstance(); formatter.setMinimumFractionDigits(2); input = JOptionPane.showInputDialog("Enter the value of the asset"); amount = Integer.parseInt(input); input = JOptionPane.showInputDialog("Enter the number of years"); year = Integer.parseInt(input); System.out.println("Year\tDepreciation\tDepreciation\tAccumulated\tAsset"+ "\n" + "\t Rate\t\tAmount\t\tDepreciation\tValue"+ "\n"); for (int i = 1; i<=year;i++) { double value; value = amount/year; sum= sum + value; asset = amount - sum; System.out.println(i+ "\t" +"1/"+year+ "\t\t"+ formatter.format(value)+ "\t\t" + formatter.format( sum)+"\t\t"+ formatter.format( asset)+ "\n"); }//end of loop //end of method straight } public void SumofYears() { String input; double rate; NumberFormat formatter = NumberFormat.getNumberInstance(); formatter.setMinimumFractionDigits(2); input = JOptionPane.showInputDialog("Enter the value of the asset"); amount = Integer.parseInt(input); input = JOptionPane.showInputDialog("Enter the number of years"); year = Integer.parseInt(input); System.out.println("Year\tDepreciation\tDepreciation\tAccumulated\tAsset"+ "\n" + "\t Rate\t\tAmount\t\tDepreciation\tValue"+ "\n"); for (int i = 1; i<=year;i++) { int div; div = div + i; for (int j=year; j>=1; j--); { double value; rate = j/ div; value = amount* rate; sum = sum + amount; asset = amount-sum; System.out.println( i+ "\t" + rate + "\t\t"+ formatter.format(value)+ "\t\t" + formatter.format( sum)+"\t\t"+ formatter.format( asset)+ "\n"); } }//end of the 1st loop }//end of method SumofYears } class TestDepreciation { public static void main (String [] args) { Depreciation myasset = new Depreciation(); int choice; do { String input = JOptionPane.showInputDialog("Choose:\n" + "1. Straight-Line Method\n" + "2. Sum of digits \n" + "3. Quit"); choice = Integer.parseInt(input); switch (choice) { case 1: myasset.Straightline(); break; case 2: //myasset.SumofYears(); break; case 3: JOptionPane.showMessageDialog (null, "Thank you!"); } } while (choice != 3); System.exit(0); } }