I have my program with my amoritization list in it, but I need to remove it and replace it with an array, which I also made up. The problem is that i am not sure how to remove the list, and add the array. Can someone tell me what the best way to do it is?

Here is the program

import java.text.*; // Needed for NumberFormat
import java.io.*; // Needed for user input

class MortgagePayment {

public static void main(String[] arguments) throws IOException {

/* All static variables are located at the end of the main as private static
final variables. */

/* Pay calculations are figured within the static final variable for MonthlyPayment[] at the end
of the main. */
System.out.println("\nThe following is the possible results on a home costing "
+ nf.format(InitialLoanAmount) + ".\n\n"
+ "Mortgage\t\tTerm\t\tInterest Rate\t\tMonthly Payment\n\n"
+ "Mortgage 1\t\t" + LoanTerm[0] + " years\t\t" + (AnnualInterestRate[0] * 100));

System.out.println("Please select  mortgage to see an amortization list.\n\n"
+ "Type a \"1\" for Mortgage 1.\n");

/* The next three variables are used as transitional variables which are assigned different
values according to which array position it is pulled from in the  user's input. */
double SelectedMonthlyPayment = 0.0;
int SelectedLoanTerm = 0;
double SelectedInterestRate = 0.0;

try {
// Prompt the user
System.out.print( "Enter a mortgage number from above: " );
// Gets user input and converts to integer
int input1 = Integer.parseInt( STDIN.readLine() );

switch (input1) {
case 1: System.out.println("\nYou have selected Mortgage " + input1 + ".\n" );
SelectedMonthlyPayment = MonthlyPayment[0];
SelectedLoanTerm = LoanTerm[0];
SelectedInterestRate = AnnualInterestRate[0];
System.out.println("If these payments are made on a monthly basis,\n"
+ "your amortization schedule will look as follows:\n");
System.out.println("\nPayment\t\t\tLoan Balance\tPrinciple Paid\tInterest Paid\n");
pause1();
break;


default: System.out.println("\nI am sorry, this is not a valid Mortgage seletion."
+ " Please try again.\n" );
System.exit(1);
} // End of switch

} // End of try

// Tests user input to be an integer and prints error message if it is not
catch ( NumberFormatException e ) {
System.out.println("\nI am sorry, this is not a valid Mortgage seletion."
+ " Please try again.\n" );
System.exit(1);
} // End of catch

// Declares and initializes variables used for the amortization list
int PaymentNumber = 1;
double InterestRate = 0.0;
double InterestPayment = 0.0;
double PrinciplePayment = 0.0;
double LoanBalance = InitialLoanAmount;

// while loop to control amortization loop environment and keep it true
while (true) {
/* if for some reason the loop fails to quit this if loop will break
out of the while loop when LoanBalance is ZERO */
if (LoanBalance <= 0) {
break;
}

// Loop for amortization list
for (int count = 1; PaymentNumber <= (SelectedLoanTerm * 12) ; count++) {

// Calculations to determine amortization
InterestRate = SelectedInterestRate / 12;
InterestPayment = LoanBalance * InterestRate;
PrinciplePayment = SelectedMonthlyPayment - (LoanBalance * InterestRate);
LoanBalance = LoanBalance - PrinciplePayment;

// This is to reduce final LoanBalace figure if <= $5.00 and help break out of the loop
if (LoanBalance <= 5.00) {
LoanBalance = 0.00;
}

System.out.println(+PaymentNumber + ". " + nf.format(SelectedMonthlyPayment)
+ "\t\t" + nf.format(LoanBalance)
+ " \t" + nf.format(PrinciplePayment) + "\t\t"
+ nf.format(InterestPayment) + "\n");
PaymentNumber++;

// Progresses 10 lines of the amortization after a brief pause
if (count == 10) {
// Prompts user for input.
System.out.println("Enter a \"C\" to CONTINUE or a \"Q\" to QUIT.");

// Initializes input2 (the second user's input) as an empty String.
String input2 = null;

/* Gets user's input, returns it to UPPERCASE, and tests it to see if
it is a 'C', a 'Q', or a bogus input. */
try {
input2 = STDIN.readLine();
input2 = input2.toUpperCase();

if (input2.equals(S1)) {
break;
}
else if (input2.equals(S2)) {
System.exit(0);
}
else {
System.exit(0);
}
} catch (IOException ioe) {
System.out.println("IO error!");
System.exit(1);
}

count = 1;

} // End of 'if' loop

} // End of 'for' loop

} // End of 'while' loop


} // End of main

// Declares STATIC FINAL variables used within the MAIN
private static final float InitialLoanAmount = 200000;
private static final int LoanTerm[] = { 7, 15, 30 };
private static final float AnnualInterestRate[] = { 0.0535f, 0.055f, 0.0575f };
private static final double MonthlyPayment[] = { (InitialLoanAmount * (AnnualInterestRate[0]/12)) / (1 - (Math.pow
(1/(1 + (AnnualInterestRate[0]/12)), (LoanTerm[0] * 12)))) , (InitialLoanAmount * (AnnualInterestRate[1]/12)) / (1 - (Math.pow
(1/(1 + (AnnualInterestRate[1]/12)), (LoanTerm[1] * 12)))) , (InitialLoanAmount * (AnnualInterestRate[2]/12)) / (1 - (Math.pow
(1/(1 + (AnnualInterestRate[2]/12)), (LoanTerm[2] * 12)))) };
private static NumberFormat nf = NumberFormat.getCurrencyInstance();
private static BufferedReader STDIN = new BufferedReader( new InputStreamReader( System.in ) );
private static final String S1 = "C";
private static final String S2 = "Q";

/* Below are two independent pausing 'void' functions allowing for pausing intervals
according to the value set in the 'Thread.sleep()' parenthesis. */

// First delay function for user to read screen
private static void pause1() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {}
} // End of pause1

} // End of program

Here is the array

import java.io.*;  // java input output package
 import java.text.DecimalFormat;
class PaymentArray2
{
 public static void main(String[] arguments)
 {
  double amount = 200000;
  int[]term = {7, 15, 30};
  double[] rate = {.0535, .055, .0575};
   DecimalFormat twoDigits = new DecimalFormat("$000.00");
 
   System.out.println("With a loan amount of  " +twoDigits.format(amount));

   for (int i = 0; i < rate.length; i++)
   {
   	System.out.print("for " + term[i] + " years");
    System.out.print("\tat a rate of " + rate[i]);
    double payment = (amount*(rate[i]/12))/(1-(Math.pow(1/(1+(rate[i]/12)),(term[i]*12))));
    System.out.println("\tThe monthly payment will be " + twoDigits.format(payment));
   }
  }
 }

Recommended Answers

All 2 Replies

ExcessiveUseOfStaticError, redo from start

I have to remove the amoritization list and add the array so i am not sure how I can do that

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.