I am writing an asset monthly depreciation system and i have written a code which works but i want to set the values such that the user enters the value manually into the system. Currently the values have been declared with a variable. this is my code

 // declare an integer (array) array with 6 rows (6 assets)  
    // & 5 columns (5 attributes for each asset)
        int assetInfo[][] = new int [6][5];

    // populate the first row with asset#100 information
        assetInfo[0][0] = 100;        //asset number(how do i set this to a jtextfield?)
        assetInfo[0][1] = 3000;        //acquisitionCost(how do i set this to a jtextfield?)
        assetInfo[0][2] = 300;        //approximateSalvageValue(how do i set this to a jtextfield?) 
        assetInfo[0][3] = 6;        //numberOfYearsUsefulLife(how do i set this to a jtextfield?)
        assetInfo[0][4] = 1;        //deprecationMethod(how do i set this to a jComboBox?)    

        // populate the second row with asset#101 information
        assetInfo[1][0] = 101;        //asset number(how do i set this to a jtextfield?)
        assetInfo[1][1] = 25000;    //acquisitionCost(how do i set this to a jtextfield?)
        assetInfo[1][2] = 1000;        //approximateSalvageValue (how do i set this to a jtextfield?)
        assetInfo[1][3] = 3;        //numberOfYearsUsefulLife(how do i set this to a jtextfield?)
        assetInfo[1][4] = 2;        //deprecationMethod(how do i set this to a jComboBox?)    

        // populate the third row with asset#102 information
        assetInfo[2][0] = 102;        //asset number(how do i set this to a jtextfield?)
        assetInfo[2][1] = 9000;        //acquisitionCost(how do i set this to a jtextfield?)
        assetInfo[2][2] = 500;        //approximateSalvageValue(how do i set this to a jtextfield?) 
        assetInfo[2][3] = 5;        //numberOfYearsUsefulLife(how do i set this to a jtextfield?)
        assetInfo[2][4] = 1;        //deprecationMethod(how do i set this to a jComboBox?)     

        // populate the fourth row with asset#103 information
        assetInfo[3][0] = 103;        //asset number(how do i set this to a jtextfield?)
        assetInfo[3][1] = 7500;        //acquisitionCost(how do i set this to a jtextfield?)
        assetInfo[3][2] = 1500;        //approximateSalvageValue(how do i set this to a jtextfield?) 
        assetInfo[3][3] = 7;        //numberOfYearsUsefulLife(how do i set this to a jtextfield?)
        assetInfo[3][4] = 2;        //deprecationMethod(how do i set this to a jComboBox?)     

        // populate the fifth row with asset#104 information
        assetInfo[4][0] = 104;        //asset number(how do i set this to a jtextfield?)
        assetInfo[4][1] = 21000;    //acquisitionCost(how do i set this to a jtextfield?)
        assetInfo[4][2] = 1000;        //approximateSalvageValue (how do i set this to a jtextfield?)
        assetInfo[4][3] = 6;        //numberOfYearsUsefulLife(how do i set this to a jtextfield?)
        assetInfo[4][4] = 2;        //deprecationMethod(how do i set this to a jComboBox?)    

        // populate the sixth row with asset#105 information
        assetInfo[5][0] = 105;        //asset number(how do i set this to a jtextfield?)
        assetInfo[5][1] = 22000;    //acquisitionCost(how do i set this to a jtextfield?)
        assetInfo[5][2] = 2000;        //approximateSalvageValue (how do i set this to a jtextfield?)
        assetInfo[5][3] = 5;        //numberOfYearsUsefulLife(how do i set this to a jtextfield?)
        assetInfo[5][4] = 3;        //deprecationMethod(how do i set this to a jComboBox?)  



    // loop does rows one at a time for each asset
        for(int row = 0; row <= 5; row++)
        {
        int assetNumber = assetInfo[row][0];
        double acquisitionCost = assetInfo[row][1];
        double salvageValue = assetInfo[row][2];
        double numberOfYears = assetInfo[row][3];
        int depreciationMethod = assetInfo[row][4]; 


         System.out.println (" asset number = " + assetNumber);
         System.out.println (" acquisition cost of asset = " + (int)acquisitionCost);
        System.out.println (" salvage value = " + (int)salvageValue);
        System.out.println (" number of years = " + (int)numberOfYears);
         System.out.println (" depreciation method  = " + depreciationMethod);

        // switch statement (page 51 in book) checks for depreciation method

        for(int y=1; y<=3 ; y++) {
                switch (depreciationMethod)
                    {

                    case 1: System.out.println (" straight line depreciation ");
                                double StraightLineDepreciation = ((acquisitionCost-salvageValue)/numberOfYears);
                                 double AccumulatedDeprecaitionSL = (StraightLineDepreciation*y);                                     
                                System.out.println ("Asset number " + assetNumber + " uses straight line depreciation");
             System.out.println (" depreciation charge for asset number " + assetNumber + " in year " + y + "=" + StraightLineDepreciation);
                                System.out.println ("accumulated depreciation is " + AccumulatedDeprecaitionSL);    
                            break;
                    case 2: System.out.println (" sum of years digits depreciation ");
                                int SumofYears = (5);
                            break;    

                    }
            }

            System.out.println (); // print a blank line
        } // end of loop for each asset

And please how can this be implemented using Java and MySql
thank You

You should first create the textfield by declaring them obviously. ( JTextField fieldinput, fieldoutput; ) No idea how many fields you want.

Also what -stultuske' mentioned, you can use the setText method like: fieldinput.getText(fieldinput) and fieldoutput.setText(fieldinput).

You need buttons to make them operate. You have to use the ActionListener for that.

I hope this helps.

that is my interface so i want to the user to enter the "cost of acquisition","residual value", and the "cost of acquistion" but currently it the values are declared in the code

Attachments ###.jpg 59.15 KB

Yes, like i said, JTextField, JButton(Along with a ActionListener) and methods(Inserting 'fieldinput.getText(fieldinput)' ) to do the insertion.

This article has been dead for over six months. Start a new discussion instead.