Results 1 to 2 of 2
  1. #1
    Anime101 is offline Member
    Join Date
    May 2008
    Posts
    3
    Rep Power
    0

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

  2. #2
    derrickD is offline Member
    Join Date
    Apr 2007
    Location
    USA
    Posts
    50
    Rep Power
    0

    Default

    Did you notice what you are doing?
    You are not calculating with the fields that you set.
    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;
    In the above code you are setting "Mortgage" but you are calculating your ration in "mortgage".
    Java is case sensitive.

Similar Threads

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •