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 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2013
    Location
    Accra,Ghana
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy How to get value into jTable

    Honestly am writing an application and am stuck at this point.
    problem is am writing an asset depreciation application and i am calculating for Monthly Depreciation,End-of-year value ,Accumulated depreciation.I want get the results of the values in this form in my jTable when the calculation is done.

    for example when i enter the number of months, it should display the results over that number,so if it is 7 it should display as below.

    Code:
               Monthly            End-of-year       Accumulated
    Months   Depreciation          value            depreciation
    ----     ------------         -----------       ------------
    1            4000                   24000                 4000
    2            4000                  20000                   8000
    3            4000                  16000                   12000
    4            4000                  12000                   16000
    5            4000                   8000                     20000
    6            4000                  4000                     24000
    7            4000                   0                          28000
    how to get this in my jtable is now my headache. I will appreciate the assistance very much thank you

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    This will be trivial if you use a TableModel. What are the algorithms used for calculating the monthly depreciation value (I don't know how you get the 4000 from the 24000 and filter it down; my suspicion is that its 28000 divided by 7)?

    Edit:
    BTW, if it is just evenly divided, you can do as so:
    PHP Code:
    public class DepreciationTableModel extends AbstractTableModel
    {
        private 
    double initialValue;
        private 
    int months;
        
        public 
    DepreciationTableModel(double initialValueint months)
        {
            
    this.initialValue initialValue;
            
    this.months months;
        }
        
        private 
    double getDepreciation(int iStep)
        {
            return 
    this.initialValue this.months;
        }
        
        private 
    double getAccumulation(int iStep)
        {
            
    double dResult 0.0;    
            if (
    iStep 0)
            {
                
    dResult += this.getDepreciation(iStep);
                
    dResult += this.getAccumulation(iStep 1);
            }        

            return 
    dResult;
        }
        
        @
    Override
        
    public String getColumnName(int column)
        {
            
    String sName "";
            switch (
    column)
            {
                case 
    0:
                    
    sName "Months";
                    break;
                case 
    1:
                    
    sName "Monthly Depreciation";
                    break;
                case 
    2:
                    
    sName "End-of-Year Value";
                    break;
                case 
    3:
                    
    sName "Accumulated Depreciation";
                    break;
            }
            return 
    sName;
        }
            
        @
    Override
        
    public int getColumnCount()
        {
            return 
    4;
        }

        @
    Override
        
    public int getRowCount()
        {
            return 
    this.months;
        }

        @
    Override
        
    public Object getValueAt(int rowIndexint columnIndex)
        {
            
    Object oResult null;
            
    int iMonth rowIndex 1;
            
    NumberFormat formatter NumberFormat.getCurrencyInstance();
            
            switch (
    columnIndex)
            {
                case 
    0:
                    
    oResult iMonth;
                    break;
                case 
    1:
                    
    oResult formatter.format(this.getDepreciation(iMonth));
                    break;
                case 
    2:
                    
    oResult formatter.format(this.initialValue this.getAccumulation(iMonth));
                    break;
                case 
    3:
                    
    oResult formatter.format(this.getAccumulation(iMonth));
                    break;
            }
            return 
    oResult;
        }

    Otherwise, you can adjust the getDepreciation function to calculate.
    Last edited by Fou-Lu; 11-07-2013 at 06:08 PM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    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
    •