Amortization Table Run

Can not get Table to display

Page 1 of 1

1 Replies - 3544 Views - Last Post: 01 December 2008 - 04:55 AM Rate Topic: -----

#1 Starling  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 01-December 08

Amortization Table Run

Post icon  Posted 01 December 2008 - 04:20 AM

/* I can not get the amortization table to display. I have encluded error code received to the end of this code*/

import java.text.DecimalFormat;
import java.math.*;
import java.util.*;

public class mortAmorization
//main method
public static void main (String args[])

//create scanner to obtain input from command window
Scanner input=new Scanner(;

//Creates 2 place decimal
DecimalFormat decimalPlaces=new DecimalFormat("0.00");

System.out.print("Starfires Mortgage Amorization Table");
System.out.print("\n for week 2 of class");

//declare variables
double NB;
double MA;
double I;
double Y;
double Pay;
double MonthlyPayment;
double PP;
double IP;
double PA;
int Principal;
int Balance;
int payment;
int year;

//Ask user questions
System.out.print("\nPlease fill in the answers to the following questions.");

System.out.print("\nTotal mortgage:");
MA = input.nextDouble(); //reads number

System.out.print("\nEnter interest rate:");
I = input.nextDouble(); //reads number from user

System.out.print("\nEnter total years of loan:");
Y = input.nextDouble(); //reads number from user

System.out.print("\nNumber of payments per year:");
Pay = input.nextDouble(); //reads number from user

MonthlyPayment = ((MA/(Y * Pay)) + (I/(Y * Pay)));
MonthlyPayment = Math.ceil(MonthlyPayment*100)/100;
System.out.printf("The total is $%2f\n",MonthlyPayment);

System.out.printf("Monthly payments over life of mortgage is $%.2f\n",MonthlyPayment);

NB = MA;


System.out.println("\nYear \tPayment \tPrincipal \tBalance");

IP = NB * (I/Pay); //Interest paid this month
PP = MonthlyPayment - IP; //Principal paid this month

NB = MA*Math.pow(1.0+I,- MA);
PA = MonthlyPayment *Math.pow(1+I,- NB);
IP = PA * Math.pow(1+I,- IP);

//The last payment is greater than the balance so adjust it.
NB-=PP; //subtract this principal payment from the balance

//declare new variables
double PT;
double IT;

for(int number=1;number<=Pay;number+=1);
PT = Pay*PP;
for(int number=1;number<=Pay;number+=1);
IT = Pay*IP;

PT+=PP; //Total up the payments this year
IT+=IP; //Total up interest this year

//print info to amorization table

System.out.printf("Year%s Totals: Principle: %.2fInterest: %.2fBalance: %.2f/n",PT,IT,NB);
System.out.println("----- ----- -----");

//Reset the totals for the year

//End of Loop

/* Error code when I run program:
Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '1'
at java.util.Formatter.checkText(
at java.util.Formatter.parse(
at java.util.Formatter.format(
at mortAmorization.main(

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete. */

Is This A Good Question/Topic? 0
  • +

Replies To: Amortization Table Run

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Amortization Table Run

Posted 01 December 2008 - 04:55 AM


Please post your code examples using - :code:


System.out.printf("Year%s Totals: Principle: %.2fInterest: %.2fBalance: %.2f/n",PT,IT,NB);

Both of these lines have several problems. Each ends in "/n" instead of "\n". Each is missing an argument - the number of format specifiers is one more than the arguments supplied.

The first line is missing a string to match "%s". The second field is "%3d" but the argument supplied is a double. The last field specified in the first line has no argument type - "%15.2f".

The second line is also missing it's first argument - a string.

This post has been edited by n8wxs: 01 December 2008 - 04:56 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1