Java Help Take 2

For all coding issues - MODers and programmers, HTML and more.

Moderators: Jeff250, fliptw

Post Reply
Kumba
DBB Ace
DBB Ace
Posts: 176
Joined: Sun Nov 21, 1999 3:01 am
Location: Florida
Contact:

Java Help Take 2

Post by Kumba »

I am writing another program and am having problems as usual. The program is suppose to find the tax status of the user and the income, then calculate the taxes. Once the information displays, it allows the user to choose if they wish to do this for another user. Please take a look at the following:

Code: Select all

import javax.swing.JOptionPane;
public class Taxes
{
	public static void main(String[] args)
	{
		int selection;
		double taxRate1 = .15;
		double taxRate2 = .30;
		selection = JOptionPane.showConfirmDialog(null,
			\"Do you want to continue tax caluculation for another person\");
		while(selection == JOptionPane.YES_OPTION)
		{
			TaxReturn aTaxReturn = new TaxReturn(taxStatus, income);
			aTaxReturn.taxStatus = JOptionPane.showInputDialog(null,
				\"Please enter your tax payer type.  I.E. S for Single, M for Married\");
			taxStatus = aTaxReturn.taxStatus;	
			aTaxReturn.income = JOptionPane.showInputDialog(null,
				\"Please enter your income.\");
			income = Double.parseDouble(incomeString);
		public void calculateTax()
		{
		if(taxStatus = S && income < 10000)
			taxAmount = income * taxRate1;
		else
			taxAmount = income * taxRate2;
		if(taxStatus = M && income < 20000)
			taxAmount = income * taxRate1;
		else
			taxAmount = income * taxRate2;
	JOptionPane.showMessageDialog(null,
		\"The tax status is \" + taxStatus + \". The income is \" + income + \". The tax amount is \" + taxAmount);
	selection = JOptionPane.showConfirmDialog(null,
		\"Do you want to continue tax caluculation for another person\");
		}
		}
	}
}
AND

Code: Select all

public class TaxReturn
{
	private double income;
	private char taxStatus;
	public double getIncome()
	{
		return income;
	}
	public char getStatus()
	{
		return taxStatus;
	}
	public void setIncome(userIncome)
	{
		income = userIncome
	}
	public void setStatus(userStatus)
	{
		taxStatus = userStatus	
	}
}
User avatar
Paul
DBB Ace
DBB Ace
Posts: 73
Joined: Tue Jan 10, 2006 5:15 pm
Location: Ann Arbor, MI, USA
Contact:

Post by Paul »

I didn't run it, so I don't know what every problem you're having is, but I did notice this:
if(taxStatus = S && income < 10000)
taxAmount = income * taxRate1;
else
taxAmount = income * taxRate2;
if(taxStatus = M && income < 20000)
You need to have \"==\" instead of \"=\" in your if statements... right now you're assigning your taxStatus to S every time, then to M a little bit later.
Differentiation is an integral part of calculus.
Post Reply