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:
- financingRate and numberOfMonths are initialized as constant.
- Scanner object is used to get purchased item and price.
- monthlyPayment is calculated using the given formula.
- totalPayment is calculated by multiplying monthlyPayment and 12.
- extra is calculated by subtracting purchasePrice from totalPayment.
- 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.