•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 423,353 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 5,150 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 220 | Replies: 1
![]() |
•
•
Join Date: May 2008
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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);
}
}
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);
}
}
•
•
Join Date: Aug 2007
Location: New Hampshire
Posts: 3,366
Reputation:
Rep Power: 8
Solved Threads: 18
•
•
•
•
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.
java Syntax (Toggle Plain Text)
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
java Syntax (Toggle Plain Text)
ratio=(mortgage+autoLoan+otherDebt)/monthlyIncome; index = ratio;
java Syntax (Toggle Plain Text)
index=(mortgage+autoLoan+otherDebt)/monthlyIncome;
Last edited by jasimp : May 18th, 2008 at 5:03 pm.
A room without books is like a body without a soul.
Facts are meaningless. They can be used to prove anything that is even remotely true.
Go then, there are other worlds than these.
Facts are meaningless. They can be used to prove anything that is even remotely true.
Go then, there are other worlds than these.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Basic Math class HELP! (Java)
- Issues using Math class (Java)
- how do i use math class .net library class (C++)
- first math class in uni (Geeks' Lounge)
Other Threads in the Java Forum
- Previous Thread: Help with placing images in Java GUI
- Next Thread: JPanel overlapping in swing using netbeans



Linear Mode