Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2. Asks the user to enter the cost of an item, computes the depreciated value of

ID: 3637829 • Letter: 2

Question

2. Asks the user to enter the cost of an item, computes the depreciated value of the item over a period of N years, and display the depreciation schedule for the item in the format shown in the sample output below. Please format the output to align the values in column as shown below.
The depreciated value of the item should be computed according to the double-declining balance method of depreciation i.e. each year except for the last year, the item depreciates by (2/N)ths of its value at the beginning of that year; in the last year it is depreciated by its value at the beginning of that year.
Sample Output:
Enter package: 1
Enter hours: 20.5
Charges: $30.95
Enter cost of the item: 2000.0
Enter estimated life: 5
Year Start Value Amt Depreciated Total Depreciation
1 $2000.00 $800.00 $800.00
2 $1200.00 $480.00 $1280.00
3 $720.00 $288.00 $1568.00
4 $432.00 $172.80 $1740.80
5 $259.20 $259.20 $2000.00

REMEMBER THIS IS FOR JAVA

Explanation / Answer

Hi, you don't explain much about the package, hours and charges part to I assume it isn't essential to the progam and didn't include it in the code. If it is relevant, then I'm sure you can easily add it or explain their part in the depreciation process further. I added plenty of comments to the code to make it easy to understand, don't just copy-paste it and expect it to work right away. Give it a read and run it a couple of times to understand its components and what they d. If there's something missing or unclear, let le know by PM or comment on the response.

I hope this is heplful, please remember to rate :)

/* import class to use for user input and decimal formatting */
import java.text.DecimalFormat;
import java.util.Scanner;

public class Depreciation {

    /* the main executin method */
    public static void main(String[] args) {

        /* scanner object to read user input */
        Scanner scan = new Scanner(System.in);
       
        /* a format to display doubles for currency */
        DecimalFormat money = new DecimalFormat("$0.00");


        /* variables for cost and years */
        double cost = 0.0;
        int years;

        /* other helper varialbes */
        double amtDep = 0.0;
        double totalDep = 0.0;

        /* prompt user for item cost and estimated life */
        System.out.print(" Enter cost of the item: ");
        cost = scan.nextDouble();
        System.out.print(" Enter estimated life: ");
        years = scan.nextInt();

        /* print the header of the depreciation table */
        System.out.println(" Years Start Value Amt Depreciated Total Depreciation");
        for (int i = 1; i <= years; i++) {

            /* print Year */
            System.out.print(" " + i);
            /* print Start value*/
            System.out.print(" " + money.format(cost) + "   "); /* extra space at the end is just to get the following column to behave */
           
            /* compute depreciation */
            /* if not the last year - compute this way */
            if (i < years)
            {
                /* cast division to double to preserve decimal precision*/
                amtDep = cost * (2.0 / (double) years);
            }
            /* if it is the last year - dep = cost left */
            else {
                amtDep = cost;
            }
            /* accumulate in total depreciation */
            totalDep = totalDep + amtDep;
            /* update the cost*/
            cost = cost - amtDep;

            /* display Amt depreciated */
            System.out.print(" " + money.format(amtDep) + "    ");

            /* display total Depreciation */
            System.out.print(" " + money.format(totalDep));

        } /* end of display for-loop for all years */

    } /* end of main execution method */
} /* end of depreciation class*/