Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Sep 2013
    Location
    Accra,Ghana
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calculate Monthly Depreciation and Accumulation

    i want to write a function which calculates the Monthly depreciation and accumulation of an asset but i am having difficulties writing it to calculate and insert it into mysql database.I will appreciate the help

    Code:
    private double getAccumulation(){
           double Accumulation = 0;
           double Monthly_Depreciation;
           int Estimated_Useful_Life = Integer.parseInt(eul.getText());
           double Cost_Of_Acquisition = Integer.parseInt(txt_coa.getText());
           double Estimated_Residual_Value = Integer.parseInt(txt_erv.getText());
           try{
                Monthly_Depreciation = (Cost_Of_Acquisition - Estimated_Residual_Value)/Estimated_Useful_Life;
                Accumulation = Monthly_Depreciation;
                Accumulation++;
           }catch(Exception e){
            JOptionPane.showMessageDialog(null, e);   
           }
           return Accumulation;
       }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    And what is your question about this? Its syntactically correct assuming eul, txt_coa, and txt_erv are all class properties, so beyond that I don't know what the issue is.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Sep 2013
    Location
    Accra,Ghana
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    those are text fields not classes. i want to fuse this code into my program where the user enter the cost of acquisiton, residual value and life, it calculates and outputs the results in a jTable

  • #4
    New Coder
    Join Date
    Sep 2013
    Location
    Accra,Ghana
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this is the updated code i wrote but with this the values are declared but i want the values to be declared in the program.

    Code:
     private void getAccumulation(){
         
           try{
              
               
               for(int row = 0; row <= 5; row++)
            {
           
            double Cost_Of_Acquisition = 2000;
            double Estimated_Residual_Value = 250;
            int Estimated_Useful_Life = 5; 
            
            int depreciationMethod = 1;
           
            
            System.out.println (" acquisition cost of asset = " + (int)Cost_Of_Acquisition);
            System.out.println (" salvage value = " + (int)Estimated_Residual_Value);
            System.out.println (" number of months = " + Estimated_Useful_Life);
            System.out.println (" depreciation method  = " + depreciationMethod);
             
                 for(int y=1; y<=5 ; y++) {
                    switch (depreciationMethod)
                        {
             
            case 1: System.out.println (" straight line depreciation ");
            double StraightLineDepreciation = ((Cost_Of_Acquisition-Estimated_Residual_Value)/Estimated_Useful_Life);
            double AccumulatedDeprecaitionSL = (StraightLineDepreciation*y);                                     
            System.out.println ("Asset number " + "1" + " uses straight line depreciation");
            System.out.println (" depreciation charge for asset number " + "1" + " in month " + y + "=" + StraightLineDepreciation);
            System.out.println ("accumulated depreciation is " + AccumulatedDeprecaitionSL);    
                                break;
                        case 2: System.out.println (" sum of months digits depreciation ");
                                    int SumofMonths =(0);
                                break;    
                          
                        }
                }
                
                
              
              
               
            }  
                
           }catch(Exception e){
            JOptionPane.showMessageDialog(null, e);   
           }
           
           
       }

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Actually, those inputs are objects. If they were not, you could not use .getText() on it. That said, that wasn't what I was referring to, what I was referring to is that they must be declared as a class property to not throw a fatal error during compilation since they are not declared and instantiated within this method.

    First you have to decide if you are using a gui or a cli interface. The first block indicates you are using a gui, while the second indicates you are using a command line (but with a gui error box, which doesn't really make sense).
    If you want to use a JTable, you'll need to use the gui components. The JTable will require you to provide it with a multi-dimensional array of any type (but all the same type), use a Vector of any type (in particular, Vector<Vector<T>>), or a TableModel. If you are mixing datatypes, a custom TableModel would be the best solution.
    I personally would write a custom TableModel to do this with. Simply write a collection class and implement the TableModel interface, and then ensure that you trigger a tableChanged event on the listener whenever you change something within the dataset. This allows the table to repaint itself whenever anything within the collection is added or removed. A custom listener could be created to an enclosing class that allows modification to also handle a repaint, but typically that would only make sense if you can modify the dataset from an alternative location while the JTable component is available for viewing.

    The alternative is to use a concrete Object[][] and dump data into that. When all data is available, you construct the JTable object by providing it with the Object[][]. Same goes with the Vector approach. Both are easy to write, but not very flexible.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •