Hello, this is my first post here and I noticed that other people have been struggling with this assignment too. It is the mortgage calculator program for UOP PRG420. So I am sure you all are probably about sick of this by now, but I need help. The book is helpful but does not show how to get the calculations to display. Actually, after I correct this code I will need to go back and change it again because the assignment wants it in the command window and I have it written so far using javax.swing.JOptionPane. The reason is because that is how the text shows me. I can follow along with the text with ease but when it comes to doing things differently than the text I struggle a bit. So here is my code so far.....

import javax.swing.JOptionPane;
import java.text.DecimalFormat;
import java.io.*;

public class NewMortgage
{
	public static void main(String[] args)
	{
		//class variables
		double interest, payment, amount;
		int term;


		amount=getLoan();
		interest=getRate();
		term=getTerm();
		output(amount, interest, term, payment);
		payment=(amount*((interest/12)/(1-Math.pow((1+(interest/12)),-(term*12)))));

	}

	//getLoan method to ge the amount of the loan
	public static double getLoan()
	{
		double amount=0.0;
		boolean done = false;

		while (!done)
		{

		String answer = JOptionPane.showInputDialog(null,
		"Enter the amount of the loan: $");

		if (answer == null) finish();

		try
		{

		amount = Double.parseDouble(answer);
		if(amount <=0) throw new NumberFormatException();
		else done = true;
	}
	catch(NumberFormatException e)
	{
		JOptionPane.showMessageDialog(null, "Your amount was not entered in the correct format.",
		"Error",JOptionPane.INFORMATION_MESSAGE);
	}
	}
		return amount;
	}

	public static double getRate()
		{
			double interest=0.0;
			boolean done = false;

			while (!done)
			{

			String answer = JOptionPane.showInputDialog(null,
			"Enter the interest rate of the loan: ");

			if (answer == null) finish();

			try
			{

			interest = Double.parseDouble(answer);
			if(interest <=0) throw new NumberFormatException();
			else done = true;
		}
		catch(NumberFormatException e)
		{
			JOptionPane.showMessageDialog(null, "Your interest amount was not entered in the correct format.",
			"Error",JOptionPane.INFORMATION_MESSAGE);
		}
		}
			return interest;
	}

	public static int getTerm()
		{
			int term=0;
			boolean done = false;

			while (!done)
			{

			String answer = JOptionPane.showInputDialog(null,
			"Enter the term of the loan in years:");

			if (answer == null) finish();

			try
			{

			term = Integer.parseInt(answer);
			if(term <=0) throw new NumberFormatException();
			else done = true;
		}
		catch(NumberFormatException e)
		{
			JOptionPane.showMessageDialog(null, "Please tell me the correct length of the loan. IE enter 30 for a 30 year mortgage",
			"Error",JOptionPane.INFORMATION_MESSAGE);
		}
		}
			return term;
	}

		public static void output(double amount, double interest, double payment, int term)
		{

			payment=(amount*((interest/12)/(1-Math.pow((1+(interest/12)),-(term*12)))));


			DecimalFormat twoDigits = new DecimalFormat ("$#,000.00");
			JOptionPane.showMessageDialog(null, "The Monthly Payment for a" + twoDigits.format(amount) + "loan with an interest rate of" + twoDigits.format(interest) + "for"+ twoDigits.format(term) + "is" + payment, JOptionPane.INFORMATION_MESSAGE);

	}

	//finish method to end program
	public static void finish()
	{
		System.exit(0);




	}
}

Everything was working fine with the code until I tried to enter in the output method and get a calculation displayed. So I have tried for about 4 hours now and still get error after error. The first error is:

output(double,double,double,int) in NewMortgage cannot be applied to (double,double,int,double)
output(amount, interest, term, payment);

I tried to change up the variables inside the output() declaration but that just made more errors. The second is:

cannot find symbol
symbol : method showMessageDialog(<nulltype>,java.lang.String,int)
location: class javax.swing.JOptionPane
JOptionPane.showMessageDialog(null, "The Monthly Payment for a" + twoDigits.format(amount) + "loan with an interest rate of" + twoDigits.format(interest) + "for"+ twoDigits.format(term) + "is" + payment, JOptionPane.INFORMATION_MESSAGE);

I can't understand this error either because the showMessageDialog worked just fine in all the other methods.

Any help would be appreiciated here. And I will probably be back because there is more to the assignment that I haven't gotten to yet. I can't question what I haven't tried though so that will wait, I just want this program to work, I have spent way too much time on this. Please.

JOptionPane.showMessageDialog(...); takes two strings, you are only using one really long string after +payment, add "",

That only made it worse. Yu were saying to add " " after the +payment right? When I did that it took it to 5 errors.

First error is that you have defined
output(double amount, double interest, double payment, int term)
but you call it with
output(amount, interest, term, payment);
ie params in wrong order.
Second error is because you have a message and a type but no title - that combination doesn't exist in the API. Check the API.

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.