The Artima Developer Community
Sponsored Link

Java Answers Forum
HELP with depreciation method!!!

1 reply on 1 page. Most recent reply: Apr 13, 2004 12:15 AM by mausam

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Scarlett

Posts: 3
Nickname: scar78
Registered: Mar, 2004

HELP with depreciation method!!! Posted: Apr 11, 2004 1:43 PM
Reply to this message Reply
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);

}
}


mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: HELP with depreciation method!!! Posted: Apr 13, 2004 12:15 AM
Reply to this message Reply
Two issues.

1)How was u able to complie this programme.??

U correct the follwoing things.

In code
for (int i = 1; i<=year;i++)
{
    int div;
    div = div + i;
		    
    for (int j=year; j>=1; j--);
    {
      // HERE remove comma after for (int j=year; j>=1; j--);
 


Now after this u will get error

variable div might not have been initialized

use int div = 0;

This will solve the compilation problem

I will like to declare ur variables in for loop and variable div as double instead of int to get the correct values after decimal.

use double div = 0;

and in for loop use double i = ...

and double j =....

and make sure to remve semicolon after for looop else it will not come in the loop

Flat View: This topic has 1 reply on 1 page
Topic: Unable to print found element in array Previous Topic   Next Topic Topic: 'cannot resolve symbol' - why?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use