Question: Can you re-write the following codes using GUI Applications in Java? //Loan amount table generator //Loan.java import java.text.DecimalFormat; import java.util.Scanner; public class Loan { public

Can you re-write the following codes using GUI Applications in Java?

//Loan amount table generator //Loan.java import java.text.DecimalFormat; import java.util.Scanner; public class Loan { public static void main(String[] args) { //Scanner class object Scanner scanner = new Scanner(System.in); //prompt loan amount System.out.print("Loan Amount: "); double loanAmount = scanner.nextDouble(); //prompt number of years System.out.print("Number of Years: "); int numYears = scanner.nextInt(); //prompt annual interest rate System.out.print("Annual Interest Rate (in %): "); double annualInterestRate = scanner.nextDouble(); System.out.println(); //call method printTable printTable(loanAmount, annualInterestRate, numYears); } /**The method printTable that takes principal, annual interest rate and years * and generates a table of monthly payment on console.*/ public static void printTable(double principal, double annualInterestRate, int numYears) { double amount=principal; double interestPaid, principalPaid, newBalance; double monthlyInterestRate, monthlyPayment; int month; int numMonths = numYears * 12; double totalInterest=0; // calculate monthly rate monthlyInterestRate = annualInterestRate / 12; monthlyPayment = monthlyPayment(principal, monthlyInterestRate, numYears); // Print the table header System.out.printf("%10s%10s%10s%10s%15s ","","","", "Unpaid","Total Interest"); System.out.printf("%10s%10s%10s%10s%15s ","Payment","Principal","Interest", "Balance","to Date"); //generate a tabel of values for payment, principal, interest ,unpaid balance //interest to date for (month = 1; month <= numMonths; month++) { // calculate interest paid interestPaid = principal * (monthlyInterestRate / 100); //calculate the principal paid principalPaid = monthlyPayment - interestPaid; //calculate the new balance newBalance = principal - principalPaid; totalInterest+=interestPaid; if(newBalance<=0) System.out.format("%8d%10.2f%10.2f%12.2f%12.2f ", month,principalPaid, interestPaid, 0.00,totalInterest); else System.out.format("%8d%10.2f%10.2f%12.2f%12.2f ", month,principalPaid, interestPaid, newBalance,totalInterest); // set newbalance to principal principal = newBalance; if(month%12==0 && month!=numMonths) System.out.println(" Continuing on Next Page "); } DecimalFormat df=new DecimalFormat("#,###.00"); //print total amount paid to the loan with interest System.out.printf("Total amount paid = "+df.format(amount+totalInterest)); } /**The method monthlyPayment that returns the monthly payment of the loan amount, * monthly interest rate and number of years*/ static double monthlyPayment(double loanAmount, double monthlyInterestRate, int numberOfYears) { //convert interest rate to decimal value monthlyInterestRate =monthlyInterestRate/ 100.0; return loanAmount * monthlyInterestRate / ( 1 - 1 / Math.pow(1 + monthlyInterestRate, numberOfYears * 12) ); } }//end of class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!