Almost all items that we acquire, depreciate in value over several years of usag
ID: 3622983 • Letter: A
Question
Almost all items that we acquire, depreciate in value over several years of usage. The yearly depreciation in value D for an item is often computed using the formula: D = (P - S) / Y where P is the purchase price in S, S is the salvage value in $, and Y is the number of years the item is used. Write a Java program, named C248W2011A1_Q2, which prompts the user to enter the values for all three values in the same order (i.e. P, S, and Y) as a single input separated by spaces between them. The program then computes the yearly depreciation in S, and yearly percentage depreciation, and number of years the value gets depreciated to 10% of purchase price of the item. Your program must print the results in two decimal digits rounded using the Math.round() function. Sample output screen: Welcome to the Depreciation calculator Enter the values (Price, Savage value, and Years used) with spaces between them: 300 25 5 Yearly depreciation = $55 0 Yearly depreciation % = 18.33% Number years for salvage value to become 10% of purchase price = 4.91 yearsExplanation / Answer
import java.util.*;
public class C248W2011A1_Q2
{
public static void main(String[] args)
{
System.out.println("Welcome to the Depreciation calculator ");
// input
Scanner kb = new Scanner(System.in);
System.out.print("Enter the values (Price, Salvage value, and Years used) with spaces between them: ");
double price = kb.nextDouble();
double salvage = kb.nextDouble();
double years = kb.nextDouble();
// calculations
double depreciation = (price - salvage)/years; // D = (P-S)/Y
double percent = depreciation/price*100;
// compute number of years for salvage value to become 10% of purchase price.
// S = 10% * P
// D = (P - 0.1P)/Y
// Y = (P - 0.1P)/D
double tenpercent = (price - 0.1*price)/depreciation;
// output
// Math.round() can round, but so can printf(). Much easier.
// if you want to use Math.round(), multiply by 100, round(), then divide by 100
// you'll have rounded to 2 decimal places
System.out.printf("Yearly depreciation = $%.2f ", depreciation);
System.out.println("Yearly depreciation % = "+String.format("%.2f", percent)+"%");
System.out.println("Number of years for salvage value to become 10% of purchase price: "+String.format("%.2f", tenpercent)+" years ");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.