Is there an easy way for me to combine these two programs? What I am wanting to use an array for the different loans. Display the mortgage payment amount for each loan and then list the loan balance and interest paid for each payment over the term of the loan. Use loops to prevent lists from scrolling off the screen. Here are the two programs I have so far. Any guidance is appreciated.

``````*/
import java.io.*;  // java input output package
import java.text.DecimalFormat; // allows placement of decimal

{
public static void main(String[] args)
{

double Loan, NewBal, MIP;
double Rate, MonthlyInterest, Payments; //double precision variables

//assign values to variables
Loan= 200000; // loan amount
Rate = .0575; //interest rate
MonthlyInterest = Rate / 12; // interest for each month
Payments = Loan * (MonthlyInterest / (1 - Math.pow(1+MonthlyInterest, -360))); //my formula
DecimalFormat twoDigits = new DecimalFormat("\$,000.00"); // declares decimal format
MIP= (Loan * Rate) / 12;
NewBal = Loan -(Payments-MIP);
System.out.println("Monthly Payments Interest Paid This Payment Loan Balance");
System.out.println();//my printout provides extra line
System.out.print("  " + twoDigits.format(Payments)); //my printout
System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
System.out.print("  " + twoDigits.format(Payments)); //my printout
MIP=(NewBal*Rate)/12;
System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
NewBal=NewBal -(Payments-MIP);
System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
System.out.print("  " + twoDigits.format(Payments)); //my printout

while (NewBal > 1) //while loop to make computations continue until gets to \$200000
{

MIP=(NewBal*Rate)/12;
System.out.print("\t\t\t" + twoDigits.format(MIP));//my printout
NewBal=NewBal -(Payments-MIP);
System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
System.out.print("  " + twoDigits.format(Payments)); //my printout

if (NewBal <100000) // tells when this is met to transition to sleep phase

try
{
Thread.sleep (500); //sleep phase needed per change request also states pause is 500 milliseconds
}
catch (InterruptedException e)
{
}

}
}
}``````
``````*/
import java.io.*;  // java input output package
import java.text.DecimalFormat;

{
public static void main(String[] args) //don't know if this is needed or not but here it is
{
double Loan;
double Rate1,Rate2,Rate3, MonthlyInterest1,MonthlyInterest2,MonthlyInterest3,Payment1,Payment2,Payment3; //double precision variables
//assign values to variables
Loan= 200000; // loan amount
Rate1 = 5.75;
Rate2 = 5.5;
Rate3 = 5.35;
MonthlyInterest1 = (Rate1 / 100) / 12;
MonthlyInterest2 = (Rate2 / 100) / 12;
MonthlyInterest3 = (Rate3 / 100) / 12;

Payment1 = Loan * (MonthlyInterest1 / (1 - Math.pow(1+MonthlyInterest1, -360))); //my formula
Payment2 = Loan * (MonthlyInterest2 / (1 - Math.pow(1+MonthlyInterest2, -180))); //my formula
Payment3 = Loan * (MonthlyInterest3 / (1 - Math.pow(1+MonthlyInterest3, -84))); //my formula
DecimalFormat twoDigits = new DecimalFormat("000.00");
System.out.println("\tYour Monthly Payments for 30 years are:\t \$" + twoDigits.format(Payment1)); //my printout
System.out.println("\tYour Monthly Payments for 15 years are:\t \$" + twoDigits.format(Payment2)); //my printout
System.out.println("\tYour Monthly Payments for 7 years are:\t \$" + twoDigits.format(Payment3)); //my printout
}
}``````

Here is my updated code:

``````import java.io.*;  // java input output package
import java.text.DecimalFormat; // java package for the decimal
class PaymentArray3 extends Thread //class name
{
public static void main(String[] arguments)
{
double Loan=200000;
double NewBal;
double amount = 200000; // loan amount with double for
int[]term = {7, 15, 30}; //length of the loans with array string
double[] rate = {.0535, .055, .0575}; //interest rate in decimal format of the loans with array string
DecimalFormat twoDigits = new DecimalFormat("\$000.00"); // tells what format the dedimal must follow

System.out.println("\t\tWith a loan amount of  " +twoDigits.format(amount)); // First line of print out
for (int i = 0; i < term.length; i++) //initializing the array
{
{

System.out.print("for " + term[i] + " years"); // prints out the number of years each loan is for
System.out.print("\tat a rate of " + rate[i]); // prints out the rates of each loans
double payment = (amount*(rate[i]/12))/(1-(Math.pow(1/(1+(rate[i]/12)),(term[i]*12)))); // formula for loans with array pointers
System.out.println("\tThe monthly payment will be " + twoDigits.format(payment)); // printout of actual monthly payments
NewBal = amount -(payment-rate[i]);
while (NewBal > 1) //while loop to make computations continue until gets to \$200000
NewBal = amount -(payment-rate[i]);

rate[i]=(NewBal)(term)/12;
System.out.print("\t\t\t" + twoDigits.format(rate[i]));//my printout
NewBal=NewBal -(payment-rate[i]);
System.out.println("\t\t\t" + twoDigits.format(NewBal));//my printout
System.out.print("  " + twoDigits.format(payment)); //my printout

if (NewBal <100000) // tells when this is met to transition to sleep phase

try
{
Thread.sleep (500); //sleep phase needed per change request also states pause is 500 milliseconds
}
catch (InterruptedException e)
{
}

}
}
}
}``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.