Below is the java program with comments on what a line do
import java.util.Scanner;
import java.math.*;
import java.text.*;
import java.util.Locale;
//You can name the class as per your requirement
public class YourClass{
public static void main(String []args){
double amount, rate;
Scanner s = new Scanner(System.in);
//To get the locale and we want currency to printed in $ hence “US”
Locale US = new Locale(“en”,”US”);
//To format loan amount
NumberFormat amountFormat = NumberFormat.getCurrencyInstance(Locale.US);
//To format percentage upto three decimal places
NumberFormat percent = NumberFormat.getPercentInstance();
percent.setMaximumFractionDigits(3);
//To format interest amount upto two decimal places
NumberFormat interestFormat = NumberFormat.getCurrencyInstance(Locale.US);
interestFormat.setMaximumFractionDigits(2);
String option = “y”;
while(option.equalsIgnoreCase(“y”))
{
System.out.println(“Enter loan amount”);
amount = s.nextDouble();
System.out.println(“Enter the interest rate”);
rate = s.nextDouble();
//BigDecimal methods to calculate interest
BigDecimal decRate = new BigDecimal(Double.toString(rate));
BigDecimal decAmount = new BigDecimal(Double.toString(amount));
BigDecimal decinterest = decRate.multiply(decAmount);
//rounding off the interest
decinterest = decinterest.setScale(2, RoundingMode.HALF_UP);
System.out.println(“Loan Amount: “+” “+amountFormat.format(decAmount));
System.out.println(“Interest Rate: “+” “+ percent.format(decRate));
System.out.println(“Interest: “+ ” “+ interestFormat.format(decinterest));
System.out.println(“Continue? y/n: “);
option = s.next();
System.out.println();
}
}
}
Output:
https://d2vlcm61l7u1fs.cloudfront.net/media%2F2c3%2F2c30b7cd-dadb-437b-92ce-865f8b1f445b%2Fphp3Ex8tD.png
“Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!”
What Students Are Saying About Us
.......... Customer ID: 12*** | Rating: ⭐⭐⭐⭐⭐"Honestly, I was afraid to send my paper to you, but splendidwritings.com proved they are a trustworthy service. My essay was done in less than a day, and I received a brilliant piece. I didn’t even believe it was my essay at first 🙂 Great job, thank you!"
.......... Customer ID: 14***| Rating: ⭐⭐⭐⭐⭐
"The company has some nice prices and good content. I ordered a term paper here and got a very good one. I'll keep ordering from this website."