C
Cassie
Arrays
I am a student and am learning Java. I am not allowed to use graphical
user interface, at this point. I MUST use an array to display 3
mortgages;
1.) 7 years, 5.35% interest, $200,000 principle
2.) 15 years, 5.5% interest, $200,000 principle
3.) 30 years at 5.75% interest, $200,000 principle
I have accomplished this successfully BUT I also have to "list the
loan balance and interest paid for each payment over the term of the
loan". I am trying to call a payment and amortization method from 3
separate programs (7year.java, 15year.java & 30year.java).
Is this possible? Do the programs need to be merged into one (this is
possible)?
If this is not possible what is while using the array?
This is my program
//importing classes
import java.lang.Math;
import java.text.NumberFormat;
//identifying program
public class Array2exp
{
//calling Currency formatting
static NumberFormat nf = NumberFormat.getCurrencyInstance();
public static void main (String [] args)
{
// Array declration
double mortgages [];
double interest [];
int term [];
double amort [];
double pay [];
//Array creation
mortgages = new double[3];
interest = new double [3];
term = new int [3];
amort = new double [3];
pay = new double [3]
// Array initialization
mortgages [0] = (200000*5.35*(Math.pow((1+5.35/1200),84)))/(1200*(Math.pow((1+5.35/1200),84)-1));
mortgages [1] = (200000*5.5*(Math.pow((1+5.5/1200),180)))/(1200*(Math.pow((1+5.5/1200),180)-1));
mortgages [2] = (200000*5.75*(Math.pow((1+5.75/1200),360)))/(1200*(Math.pow((1+5.75/1200),360)-1));
interest [0] = 5.35;
interest [1] = 5.5;
interest [2] = 5.75;
term [0] = 7;
term [1] = 15;
term [2] = 30;
amort [0] = 7year.amortization();
amort [1] = 15year.amortization();
amort [2] = 30year.amortization();
pay [0] = 7year.payment();
pay [1] = 15year.payment();
pay [2] = 30year.payment();
//for loop, (initialization, expression, update)
for (int MonthlyPayment=0; MonthlyPayment<=2; MonthlyPayment++)
{
//print statement
System.out.print("$200,000 principle, ");
System.out.print(interest[MonthlyPayment]);
System.out.print("% interest, ");
System.out.print(term[MonthlyPayment]);
System.out.print(" years, ");
System.out.println("Payment ");
System.out.print(nf.format(mortgages[MonthlyPayment]));
System.out.println("");
System.out.println(pay[MonthlyPayment]);
System.out.println(amort[MonthlyPayment]);
}
}
}
I'd be grateful for any help. Thank you.
I am a student and am learning Java. I am not allowed to use graphical
user interface, at this point. I MUST use an array to display 3
mortgages;
1.) 7 years, 5.35% interest, $200,000 principle
2.) 15 years, 5.5% interest, $200,000 principle
3.) 30 years at 5.75% interest, $200,000 principle
I have accomplished this successfully BUT I also have to "list the
loan balance and interest paid for each payment over the term of the
loan". I am trying to call a payment and amortization method from 3
separate programs (7year.java, 15year.java & 30year.java).
Is this possible? Do the programs need to be merged into one (this is
possible)?
If this is not possible what is while using the array?
This is my program
//importing classes
import java.lang.Math;
import java.text.NumberFormat;
//identifying program
public class Array2exp
{
//calling Currency formatting
static NumberFormat nf = NumberFormat.getCurrencyInstance();
public static void main (String [] args)
{
// Array declration
double mortgages [];
double interest [];
int term [];
double amort [];
double pay [];
//Array creation
mortgages = new double[3];
interest = new double [3];
term = new int [3];
amort = new double [3];
pay = new double [3]
// Array initialization
mortgages [0] = (200000*5.35*(Math.pow((1+5.35/1200),84)))/(1200*(Math.pow((1+5.35/1200),84)-1));
mortgages [1] = (200000*5.5*(Math.pow((1+5.5/1200),180)))/(1200*(Math.pow((1+5.5/1200),180)-1));
mortgages [2] = (200000*5.75*(Math.pow((1+5.75/1200),360)))/(1200*(Math.pow((1+5.75/1200),360)-1));
interest [0] = 5.35;
interest [1] = 5.5;
interest [2] = 5.75;
term [0] = 7;
term [1] = 15;
term [2] = 30;
amort [0] = 7year.amortization();
amort [1] = 15year.amortization();
amort [2] = 30year.amortization();
pay [0] = 7year.payment();
pay [1] = 15year.payment();
pay [2] = 30year.payment();
//for loop, (initialization, expression, update)
for (int MonthlyPayment=0; MonthlyPayment<=2; MonthlyPayment++)
{
//print statement
System.out.print("$200,000 principle, ");
System.out.print(interest[MonthlyPayment]);
System.out.print("% interest, ");
System.out.print(term[MonthlyPayment]);
System.out.print(" years, ");
System.out.println("Payment ");
System.out.print(nf.format(mortgages[MonthlyPayment]));
System.out.println("");
System.out.println(pay[MonthlyPayment]);
System.out.println(amort[MonthlyPayment]);
}
}
}
I'd be grateful for any help. Thank you.