SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,kenrick Mock
Chapter:
Console Input And Output
Exercise:
Programming Projects
Question:5 | ISBN:9780132830317 | Edition: 5

Question

The straight-line method for computing the yearly depreciation in value D for an item is given by the following formula:

where P is the purchase price, S is the salvage value, and Y is the number of years the item is used. Write a program that takes as input the purchase price of an item, the expected number of years of service, and the expected salvage value. The program should then output the yearly depreciation for the item.


TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Program:

// YearlyDepreciation.java
import java.util.Scanner;
import java.text.DecimalFormat;
public class YearlyDepreciation
{
	public static void main(String[] args)
	{
		Scanner keyboard = new Scanner(System.in);
		
		DecimalFormat pattern0dot00 = new DecimalFormat("0.00");
		
		System.out.print("Enter the purchase price of an item: ");
		double P = keyboard.nextDouble();
		
		System.out.print("Enter the expected number of years of service: ");
		double Y = keyboard.nextDouble();
		
		System.out.print("Enter the expected salvage value: ");
		double S = keyboard.nextDouble();
		
		double D = (P - S) / Y;
		
		System.out.println("\nThe yearly depreciation for the item: " 
								+ pattern0dot00.format(D));	
		
		keyboard.close();		
	}
}

Output:

Enter the purchase price of an item: 65
Enter the expected number of years of service: 6
Enter the expected salvage value: 30

The yearly depreciation for the item: 5.83

 

0 0

Discussions

Post the discussion to improve the above solution.