4 Replies - 537 Views - Last Post: 08 February 2010 - 05:24 PM Rate Topic: -----

#1 willyv2k  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 08-February 10

Help with An Amortization Table.

Posted 08 February 2010 - 06:45 AM

Hello New here.
I'm having issues with the code i made for a Amortization chart.Calculations Work but cant figure out how to set it to make a chart displaying the total amounts owed and a monthly and yearly basis.

import java.util.*;
import java.lang.Math.*;
import java.text.DecimalFormat;


public class testCSCI112Assignment2{
    static Scanner console = new Scanner(System.in);

        public static void main(String[] args){
DecimalFormat df = new DecimalFormat("0.00");
double dblr; //rate
double dbli; //interest per month
double dbll; //loan amount
double dblt; //years
int intm; //# payments per year
double dblR; //periodic payment
double dblu; //Unpaid loan balance
double dblk; //# payments made
int inty;

//input
System.out.println("What is the Loan Amount:$");
dbll = console.nextDouble();
System.out.println("What is starting Year?");
inty = console.nextInt();
System.out.println("What is the interest rate(decimal Form:");
dblr = console.nextDouble();
System.out.println("What is the length of the loan(Years):");
dblt = console.nextDouble();
System.out.println("Payments Per Year:");
intm = console.nextInt();
System.out.println("Number of payments made");
dblk = console.nextDouble();

//calc
dbli = (dblr/intm);
dblR = ((dbll * dbli) / (1 - Math.pow((1 + dbli), (-intm * dblt))));

Formatter fmt = new Formatter();
            fmt.format("%.2f", dblR);
System.out.println("Your periodic payment is $" + fmt);



    //Loan Balance
    do{
    dblu = (dblR * (1 - Math.pow((1 + dbli), (-(intm * dblt - dblk))))) / dbli;
    }
    while (dblk < 0);
Formatter fmt2 = new Formatter();
    fmt2.format("%.2f", dblu);
    System.out.println("Your remaining balance is $" + fmt2);


    for(int year = inty; year <= dblt; year ++){
    System.out.println("\nYear \tPayment \tPrincipal \tInterest \tBalance");
    System.out.println("****************************************************************");
    System.out.println("::: ::: :::");

        for (int payment = 1; payment <= intm; payment++){


}
            }

        }
}




thank you for your time.

Is This A Good Question/Topic? 0
  • +

Replies To: Help with An Amortization Table.

#2 SwiftStriker00  Icon User is offline

  • No idea why my code works
  • member icon

Reputation: 432
  • View blog
  • Posts: 1,596
  • Joined: 25-December 08

Re: Help with An Amortization Table.

Posted 08 February 2010 - 07:25 AM

you need to rework your print statement to print the variables, then update them in the loop like this (in pseduo code):
for( int i=0; i < number of payments; i++ ){
System.out.println("\nYear \tPayment \tPrincipal \tInterest \tBalance");
System.out.println("****************************************************************");
System.out.print(": " + (startYear) + ": :" + payment + ": :" + etc... );
Modify all variables to increment to next payment
}


Was This Post Helpful? 0
  • +
  • -

#3 willyv2k  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 08-February 10

Re: Help with An Amortization Table.

Posted 08 February 2010 - 07:33 AM

ok thnx
Was This Post Helpful? 0
  • +
  • -

#4 willyv2k  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 08-February 10

Re: Help with An Amortization Table.

Posted 08 February 2010 - 05:03 PM

now the issue im having is that it wont print per line.Ill just Print 1 line and loop it over any ideas?

import java.util.*;
import java.lang.Math.*;
import java.text.DecimalFormat;
public class testCSCI112Assignment2{
    static Scanner console = new Scanner(System.in);
static Double dblj;
static Double dble;
static int intf;
        public static void main(String[] args){
DecimalFormat df = new DecimalFormat("0.000");
double dblr; //rate
double dbli; //interest per month
double dbll; //loan amount
double dblt; //years
int intm; //# payments per year
double dblR; //periodic payment
double dblu; //Unpaid loan balance
double dblk; //# payments made
int inty;
//input
System.out.println("What is the Loan Amount:$");
dbll = console.nextDouble();
System.out.println("What is the interest rate(decimal Form):");
dblr = console.nextDouble();
System.out.println("What is the length of the loan(Years):");
dblt = console.nextDouble();
System.out.println("Payments Per Year:");
intm = console.nextInt();
System.out.println("Number of payments made");
dblk = console.nextDouble();
System.out.println("What is starting Year?");
inty = console.nextInt();
//calc
dbli = (dblr/intm);
Formatter fmt3 = new Formatter();
            fmt3.format("%.3f", dbli);
dblR = ((dbll * dbli) / (1 - Math.pow((1 + dbli), (-intm * dblt))));
Formatter fmt = new Formatter();
            fmt.format("%.2f", dblR);
System.out.println("Your periodic payment is $" + fmt);

    //Loan Balance
    do{
    dblu = (dblR * (1 - Math.pow((1 + dbli), (-(intm * dblt - dblk))))) / dbli;
   
    }

    while (dblk < 0);
	Formatter fmt2 = new Formatter();
    fmt2.format("%.2f", dblu);
    System.out.println("Your remaining balance is $" + fmt2);


		for( int i=-1; i < dblk; i++){
			dblj = dbll * dbli;
			dble = dbll+dblj;
			Formatter fmt4 = new Formatter();
            fmt4.format("%.2f", dble);
			intf+=1;
			inty++;
		System.out.println(inty+"\nYear \tPayment \tPrincipal \tInterest \tBalance");
		System.out.println("****************************************************************");
        System.out.println(":" + (intf) + ":     :" + fmt + ":        :" + fmt4 +":           :" + fmt3 + ":           :" + fmt2);
																
}

            }

        }


Was This Post Helpful? 0
  • +
  • -

#5 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: Help with An Amortization Table.

Posted 08 February 2010 - 05:24 PM

a you see, this do\while loop:
 do{    
dblu = (dblR * (1 - Math.pow((1 + dbli), (-(intm * dblt - dblk))))) / dbli;       
}    
while (dblk < 0);


will loop as long as dblk is smaller than 0.
but why aren't you increasing dblk? it will remain with the same value.
so i assume dblk is bigger or equal to 0, or else you would get an infinite loop :)

in the for llop, where you say it prints the same line, is because you never changes the values inside the loop. the values remain the same for each iteration of the loop. (dble and dblj will always have the same value). however intf does change the value, and it is shown.

also, if i may suggest somethong, please name your variables with meaningfull names.
it seems unimportant, but it is very important.
imagine you leave your code for a week. then go back and try to read it.
writing the code again will take you less time than trying to understand it :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1