Results 1 to 2 of 2
- 05-18-2008, 07:57 PM #1
Member
- Join Date
- May 2008
- Posts
- 3
- Rep Power
- 0
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);
}
}
- 05-23-2008, 08:31 PM #2
Member
- Join Date
- Apr 2007
- Location
- USA
- Posts
- 50
- Rep Power
- 0
Did you notice what you are doing?
You are not calculating with the fields that you set.
In the above code you are setting "Mortgage" but you are calculating your ration in "mortgage".Java 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;
Java is case sensitive.
Similar Threads
-
help with income to debt ratio calculator
By Anime101 in forum New To JavaReplies: 1Last Post: 05-19-2008, 01:44 AM -
Java Calculator
By aapanju in forum New To JavaReplies: 3Last Post: 04-17-2008, 05:33 AM -
calculator not working
By Renegade85 in forum New To JavaReplies: 5Last Post: 03-10-2008, 03:27 PM -
Create a Calculator in Java
By Albert in forum New To JavaReplies: 2Last Post: 07-04-2007, 08:01 AM -
Swing Calculator
By nemo in forum AWT / SwingReplies: 1Last Post: 05-28-2007, 11:07 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks