Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-18-2008, 09:57 PM
Member
 
Join Date: May 2008
Posts: 3
Anime101 is on a distinguished road
help with income to debt ratio calculator
Hello, Im new to Java Programming, and Im trying to create a Web Applet of a Income to Debt Ratio calculator. I think Im missing a Math code, because when i run the applet everything works except the when I click calculate it says my debt to ratio income is always 0. Any advice would be greatly appreciated, thanks.


import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class DebtRatioIncome extends Applet implements ActionListener
{
// declare variables
Image logo; //declare an Image object
int Mortgage,AutoLoan,OtherDebt,MonthlyIncome;
double monthlyIncome,mortgage,autoLoan,otherDebt,ratio, index;

// construct components
Label companyLabel = new Label("INCOME TO DEBT RATIO CALCULATOR");
Label monthlyIncomeLabel= new Label("Enter your Monthly Income here:");
TextField monthlyIncomeField = new TextField(10);
Label mortgageLabel = new Label("Enter your Mortgage Payment here: ");
TextField mortgageField = new TextField(10);
Label autoLoanLabel = new Label ("Enter your Auto Loan payment here: ");
TextField autoLoanField = new TextField(10);
Label otherDebtLabel = new Label ("Enter any Other Debt here:");
TextField otherDebtField = new TextField(10);
Button calcButton = new Button("Calculate");
Label outputLabel = new Label("Click the Calculate button to see your Debt to Income Ratio.");

public void init()
{
setForeground(Color.red);
add(companyLabel);
add(mortgageLabel);
add(mortgageField);
add(autoLoanLabel);
add(autoLoanField);
add(otherDebtLabel);
add(otherDebtField);
add(monthlyIncomeLabel);
add(monthlyIncomeField);
add(calcButton);
calcButton.addActionListener(this);
add(outputLabel);
logo = getImage(getDocumentBase(), "logo.gif");
}

public void actionPerformed(ActionEvent e)
{

Mortgage = Integer.parseInt(mortgageField.getText());
AutoLoan = Integer.parseInt(autoLoanField.getText());
OtherDebt = Integer.parseInt(otherDebtField.getText());
MonthlyIncome = Integer.parseInt(monthlyIncomeField.getText());

ratio=(mortgage+autoLoan+otherDebt)/monthlyIncome;

outputLabel.setText("YOUR DEBT TO INCOME RATIO IS" + Math.round(index) + ".");
}

public void paint(Graphics g)
{
g.drawImage(logo,125,160,this);
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-23-2008, 10:31 PM
Member
 
Join Date: Apr 2007
Location: USA
Posts: 50
derrickD is on a distinguished road
Did you notice what you are doing?
You are not calculating with the fields that you set.
Code:
Mortgage = Integer.parseI(mortgageField.getText()); AutoLoan = Integer.parseInt(autoLoanField.getText()); OtherDebt = Integer.parseInt(otherDebtField.getText()); MonthlyIncome = Integer.parseInt(monthlyIncomeField.getText()); ratio = (mortgage + autoLoan + otherDebt) / monthlyIncome;
In the above code you are setting "Mortgage" but you are calculating your ration in "mortgage".
Java is case sensitive.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
help with income to debt ratio calculator Anime101 New To Java 1 05-19-2008 03:44 AM
Java Calculator aapanju New To Java 3 04-17-2008 07:33 AM
calculator not working Renegade85 New To Java 5 03-10-2008 05:27 PM
Create a Calculator in Java Albert New To Java 2 07-04-2007 10:01 AM
Swing Calculator nemo AWT / Swing 1 05-28-2007 01:07 PM


All times are GMT +3. The time now is 07:03 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org