Answer:
import java.util.Scanner;
public class Appliance
{
public static void main(String[] args) {
final double financingRate = 0.03;
final int numberOfMonths = 12;
Scanner input = new Scanner(System.in);
System.out.print("Enter the item you want to purchase: ");
String itemPurchased = input.nextLine();
System.out.print("Enter the price for the item: ");
double purchasePrice = input.nextDouble();
double monthlyPayment = ((purchasePrice * financingRate) + purchasePrice) / numberOfMonths;
double totalPayment = monthlyPayment * numberOfMonths;
double extra = totalPayment - purchasePrice;
System.out.print("You purchased "+ itemPurchased+ "\nYour monthly payment is: "+ (String.format("%.2f",monthlyPayment)) + "\nYour total payment is: "+ (String.format("%.2f",totalPayment)) + "\nYour extra payment is: "+ (String.format("%.2f",extra)));
}
}
Explanation:
- <em>financingRate</em> and <em>numberOfMonths</em> are initialized as constant.
- <em>Scanner object</em> is used to get <em>purchased item and price</em>.
- <em>monthlyPayment</em> is calculated using the given formula.
- <em>totalPayment</em> is calculated by multiplying <em>monthlyPayment </em>and 12.
- <em>extra</em> is calculated by subtracting <em>purchasePrice</em> from <em>totalPayment</em>.
- All the required things are printed out. Be aware that since numbers are required to have two decimal points, String.format("%.2f", variableName) is used.