User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: May 2008
Posts: 1
Reputation: Anime10112 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Anime10112 Anime10112 is offline Offline
Newbie Poster

Help with Math Class

  #1  
May 18th, 2008
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);
}
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2007
Location: New Hampshire
Posts: 3,366
Reputation: jasimp is on a distinguished road 
Rep Power: 8
Solved Threads: 18
jasimp's Avatar
jasimp jasimp is offline Offline
Nearly a Senior Poster

Re: Help with Math Class

  #2  
May 18th, 2008
Originally Posted by Anime10112 View Post
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.

  1. double index;
  2.  
  3. 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

  1. ratio=(mortgage+autoLoan+otherDebt)/monthlyIncome;
  2. index = ratio;
or
  1. 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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 12:00 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC