Tuesday 15 June 2010

java - How do I format my results with DecimalFormat if I'm using a separate class? -


I am very new to Java, and I am currently trying to create a driver class which is my mortgage To compute a mortgage, I have everything working to calculate a mortgage, except that my output does not format the result of two decimal places (0.00), even if I have the code. Here is a piece of my driver code:

  Mortgage Mortgage 1 = New Mortgage (Annual Insertate, Numbers, Debt Shi); Decimalable df = new substitute ("0.00"); Employmentpan Show Messagedig (empty, "Your monthly payment is:" + Mortgage 1. Monthly payment () + "\ n" + "Your total payment is:" + Mortgage 1 voter payment ());  

It works perfectly, and outputs the correct numbers, but does not format them correctly. Thank you for your help.

OK you are not actually using DF at all. You must pass the result of calling monthly payment () and total payment () to the format method. For example:

  Mortgage Mortgage 1 = New Mortgage (AnnualInndrebet, Number, Year, Loan Amount); Decimalable df = new substitute ("0.00"); Employmentpan Show Message Dialogue (empty, "Your monthly payment is:" + df.format (mortgage1.monthlyPayment ()) "" \ n "+" Your total payment is: + df.format (mortgage1.totalpayment ()));  

No comments:

Post a Comment