Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a Java Expert!

Join 244,287 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 972 people online right now. Registration is fast and FREE... Join Now!




Amortization Table Run

 
Reply to this topicStart new topic

Amortization Table Run, Can not get Table to display

Starling
1 Dec, 2008 - 03:20 AM
Post #1

New D.I.C Head
*

Joined: 1 Dec, 2008
Posts: 1

/* 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.io.*;
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(System.in);

//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.");

//prompts
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

//formula
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.
if(PP>NB)
{
PP=NB;
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("%s\t%3d%11.2f\t%12.2f\t%15.2/n",MA,PP,IP,NB);

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

//Reset the totals for the year
PT=0;
IT=0;

//End of Loop
}
}
}
}



/* Error code when I run program:
Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '1'
at java.util.Formatter.checkText(Formatter.java:2502)
at java.util.Formatter.parse(Formatter.java:2484)
at java.util.Formatter.format(Formatter.java:2413)
at java.io.PrintStream.format(PrintStream.java:920)
at java.io.PrintStream.printf(PrintStream.java:821)
at mortAmorization.main(mortAmorization.java:100)

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


User is offlineProfile CardPM
+Quote Post


n8wxs
RE: Amortization Table Run
1 Dec, 2008 - 03:55 AM
Post #2

--... ...-- -.. . -. ---.. .-- -..- ...
Group Icon

Joined: 6 Jan, 2008
Posts: 1,609



Thanked: 223 times
My Contributions
Welcome!

Please post your code examples using - code.gif

java

System.out.printf("%s\t%3d%11.2f\t%12.2f\t%15.2/n",MA,PP,IP,NB);

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: 1 Dec, 2008 - 03:56 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 03:21PM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month