Rewrite the following program using DecimalFormat classSolut
Rewrite the following program using DecimalFormat class
Solution
Assign6.java
import java.text.DecimalFormat;
 import java.util.Scanner;
public class Assign6
 {
 public static void main(String[] args)
 {
 final double SVC_CHARGE_RATE = 0.01 * 0.3;
 DecimalFormat df = new DecimalFormat(\"0.00\");
 double investmentAmt,
 svcChargeAmt,
 totalDue;
   
 Scanner keyScan = new Scanner(System.in);
   
 System.out.print(\"Welcome to NIU Investments!\");
   
 System.out.print(\"\ \ Please enter the amount you would like to invest today: \");
 investmentAmt = keyScan.nextDouble();
   
 svcChargeAmt = investmentAmt * SVC_CHARGE_RATE;
 totalDue = investmentAmt + svcChargeAmt;
   
 System.out.println(\"\ \ Total Investment (in dollars): \"+df.format(investmentAmt));
 System.out.println(\" Service Charge (in dollars): \"+df.format(svcChargeAmt));
 System.out.println(\" -----------\");
 System.out.println(\"Total Amount Due (in dollars): \"+df.format(totalDue));
   
 System.out.print(\"\ \ \ Thank you for your investment!\ \ \ \ \ \ \ \");
   
 keyScan.close();
 }
 }
Output:
Welcome to NIU Investments!
Please enter the amount you would like to invest today: 10000
 Total Investment (in dollars): 10000.00
 Service Charge (in dollars): 30.00
 -----------
 Total Amount Due (in dollars): 10030.00
Thank you for your investment!

