Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

NEED HELP! The program must read the data from the input file and then output th

ID: 3556717 • Letter: N

Question

NEED HELP! The program must read the data from the input file and then output the amortization reports in a scrolling pane in a window. Write this program by breaking up the problem into smaller methods. The program cannot be written so all the work is done in the main method. Define at least 2 other method definitions (to break up the work into smaller chunks).

The input file is a file of records with customer information. Each record contains the homeowner's name, address, city, state, and zip code. It also includes the month, day, and year the loan was made, the total amount borrowed, the annual percentage rate at which the money was lent, and a number indicating the payment amount.

Copy the text below into notepad to save as a .txt file. Name that file "fcrc loan data.txt" This will be the import file. Place the text file into the root directory of the program.

"Bill Olsen" "914 8th Street" "Salt Lake City" UT 84112 2 25 2012 1250.00 .0325 2

"Mary Henderson" "1374 Oak Lane" "Love Canal" NY 10035 3 28 2012 7000.00 .0625 3

"Austin Powers" "10 Downing St." "Pittsburg" PA 13417 4 1 2012 12800.00 .0700 5

This is a link to the hosted text file:

http://m.uploadedit.com/b034/1398779649583.txt

Explanation / Answer

import amortization.InputFile;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class Amortization {
static String name, address1, city, state;
static int zip, month, day, year, code;
static double amount=0, rate=0;

public static void main(String[] args) {

InputFile loaninfo;
loaninfo = new InputFile("fcrc loan data.txt");

JFrame jf;
JTextArea jta;
JScrollPane jsp;

jf = new JFrame();
jta = new JTextArea();
jsp = new JScrollPane(jta);

jf.setSize(1200,350);
jf.setLocation(400,250);

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

jf.add(jsp);
jf.setVisible(true);

while (!loaninfo.eof()) {
name = loaninfo.readString();
address1 = loaninfo.readString();
city = loaninfo.readString();
state = loaninfo.readString();
zip = loaninfo.readInt();
month = loaninfo.readInt();
day = loaninfo.readInt();
year = loaninfo.readInt();
amount = loaninfo.readDouble();
rate = loaninfo.readDouble();
code = loaninfo.readInt();
displayHeading(name, address1, city, state, zip, month, day, year, amount, code, rate);
displayTable(amount);
}
}
public static void displayTable(double amount)
{
int paymentNumber;
double payment=0, interest, principal, balance;
JFrame jf;
JTextArea jta;
JScrollPane jsp;

jf = new JFrame();
jta = new JTextArea();
jsp = new JScrollPane(jta);
jf.setSize(1200,350);
jf.setLocation(400,250);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.add(jsp);
jf.setVisible(true);
DecimalFormat numFormat;
numFormat = new DecimalFormat("0.00");
NumberFormat currencyFormat;
currencyFormat = NumberFormat.getCurrencyInstance();
balance = amount;
paymentNumber = 0;
double totalPayment = 0;
double totalIntPaid = 0;
while (balance > 0)
{
++paymentNumber;
String dueDate = calcDueDate(month, day, year, paymentNumber - 1);
interest = calcInterest(balance, rate);
if (balance<=payment)
{
payment = balance;
principal = balance;
balance = 0;
}
else
{
payment = calcPayment(code, amount);
principal = calcPrincipal(payment, interest);
balance = calcBalance(balance, principal);
}
totalPayment = totalPayment + payment;
totalIntPaid = totalIntPaid + interest;
jta.append(paymentNumber + " " + dueDate + " $" + numFormat.format(payment) + " " + currencyFormat.format(interest) + " " + currencyFormat.format(principal) + " " + currencyFormat.format(balance)+ " ");

}
jta.append(" ");
jta.append(" " + " " + " " + " " + "Totals: " +currencyFormat.format(totalPayment)+ " " + currencyFormat.format(totalIntPaid) + " ");
jta.append(" ");
}
public static void displayHeading(String name, String address1, String city, String state, int zip, int month, int day, int year, double amount, int code, double rate)
{
DecimalFormat numFormat;
numFormat = new DecimalFormat("0.00");
NumberFormat currencyFormat;
currencyFormat = NumberFormat.getCurrencyInstance();
  
JFrame jf;
JTextArea jta;
JScrollPane jsp;
jf = new JFrame();
jta = new JTextArea();
jsp = new JScrollPane(jta);
jf.setSize(1200,350);
jf.setLocation(400,250);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.add(jsp);
jf.setVisible(true);
jta.append("First Community Redevelopment Corporation ");
jta.append("101 1st Street ");
jta.append("Bloomington, TN 41663 ");
jta.append(" ");
jta.append(" " + name + " ");
jta.append(" " + address1 + " ");
jta.append(" " + city + ", " + state + ", " + zip + " ");
jta.append(" ");
jta.append("LOAN AMOUNT: " + currencyFormat.format(amount) + " ");
jta.append("INTEREST RATE: " + numFormat.format(rate) + "% ");
jta.append(" ");
jta.append("Payment # Due Date Payment Interest Principal Balance ");
jta.append("--------------------------------------------------------------------------------------------------- ");
}
public static double calcPayment(int code, double amount)
{
double payment;
payment = 0;
switch (code) {
case 0:
payment = 50.00;
break;
case 1:
payment = 55.00;
break;
case 2:
payment = 75.00;
break;
case 3:
payment = 100.00;
break;
case 4:
payment = .05 * amount;
break;
case 5:
payment = .06 * amount;
break;
case 6:
payment = .05 * amount;
break;
case 7:
payment = .04 * amount;
break;
case 8:
payment = .03 * amount;
break;
case 9:
payment = .02 * amount;
break;
default:
System.out.println("Bad payment code");
}
return payment;
}
public static double calcInterest(double balance, double rate)
{
double interest;
interest = rate / 12 * balance;
return interest;
}
public static double calcPrincipal(double payment, double interest)
{
double principal;
principal = payment - interest;
return principal;
}
public static double calcBalance(double balance, double principal)
{
balance = balance - principal;
return balance;
}
public static String calcDueDate(int month, int day, int year, int payNum)
{
String monthStr = "";
month = month + payNum -1;
year = year + (month /12);
month = month % 12;
if(month ==0)year--;
switch (month)
{
case 1:
monthStr = "Jan.";
break;
case 2:
monthStr = "Feb.";
break;
case 3:
monthStr = "Mar.";
break;
case 4:
monthStr = "Apr.";
break;
case 5:
monthStr = "May.";
break;
case 6:
monthStr = "Jun.";
break;
case 7:
monthStr = "Jul.";
break;
case 8:
monthStr = "Aug.";
break;
case 9:
monthStr = "Sept.";
break;
case 10:
monthStr = "Oct.";
break;
case 11:
monthStr = "Nov.";
break;
case 0:
monthStr = "Dec.";
break;
default:
System.out.println("Invalid month: "+month);
}
return monthStr + " " + day + ", " + year;
}
}