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 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);
}
}

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 0. Any advice would be greatly appreciated, thanks.

double index;

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

Those are the only two places index exists in your applet. You never gave index a value, besides 0 when you created it.
I think you should say

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

or

index=(mortgage+autoLoan+otherDebt)/monthlyIncome;
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.