Java GUI loan payment calculator

Update....I added the .java with GUI file

Page 1 of 1

3 Replies - 5325 Views - Last Post: 30 April 2009 - 06:25 PM Rate Topic: -----

#1 jrmjen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 30-April 09

Java GUI loan payment calculator

Posted 30 April 2009 - 04:15 PM

I am creating a GUI using GUI builder in NetBeans and I have to have the user enter the Price, Down Payment, Interest Rate (based on which jradio button selected) and Length of Loan. I have to then calculate the monthly payment based on these 4 things. The interest rate is either 5, 10 or 12 percent. I have everything done except for the calculation which I am confused on (not very good at math) and I believe that I need to add some variable designations. Any suggestions? Thanks.

Attached File(s)

  • Attached File  P3IP.zip (34.63K)
    Number of downloads: 471


Is This A Good Question/Topic? 0
  • +

Replies To: Java GUI loan payment calculator

#2 trtherrien  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 17-April 09

Re: Java GUI loan payment calculator

Posted 30 April 2009 - 05:39 PM

	private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {										 

		// First we define float variables.
		float price, down, interest, length, result;
		// We have to parse the text to a type float.
		price = Float.parseFloat(jTextField1.getText());
		down = Float.parseFloat(jTextField2.getText());
		interest = Float.parseFloat(jTextField3.getText());
		length = Float.parseFloat(jTextField4.getText());

		// Now we can perform the calculation
		interest = interest / 100 / 12;
		float ipow = (float)java.lang.Math.pow(1 + interest, length);
		interest = (interest * ipow) / (ipow - 1);

		result = (price - down) * interest;


		// We will now pass the value of result to jTextField3.
	// At the same time, we are going to
	// change the value of result from a float to a string.
		jTextField5.setText(String.valueOf(result));
	}



This seems to work for me. I removed the % sign as the parse will fail. It didn't fail for you, because you were getting interest from the wrong textbox. You may want to add some error trapping for user input, but basically this is how it is done. I also assumed the length was months.

Thanks,
Tom
Was This Post Helpful? 1
  • +
  • -

#3 jrmjen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 30-April 09

Re: Java GUI loan payment calculator

Posted 30 April 2009 - 06:12 PM

Thanks, Tom....your suggestions helped tremendously!
Was This Post Helpful? 0
  • +
  • -

#4 trtherrien  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 17-April 09

Re: Java GUI loan payment calculator

Posted 30 April 2009 - 06:25 PM

You're welcome.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1