carrieoke13
05-10-2006, 05:57 PM
Hi there,
I am extremely new at Java, and I'm working on a program that will calculate estimated tax. I think I have everything right, but I can't figure out how to get the information calculated in TaxReturn.java (see below) to print out. I'm going to post both Tax.java and TaxReturn.java for your review. Can you help? I'm sure this is not very well written, but I'm learning!
tax.java :
import javax.swing.*;
public class Tax
{ static final String SINGLE = "S";
static final String MARRIED = "M";
public static void main(String[] args) throws Exception
{
String inputIncome;
double inputNumber;
String status;
TaxReturn = aTaxReturn;
inputIncome = JOptionPane.showInputDialog(null, "Enter your annual income with no commas or decimals");
inputNumber = Double.parseDouble(inputIncome);
JOptionPane.showMessageDialog(null, "Your annual income is " + inputNumber);
status = JOptionPane.showInputDialog(null, "Enter your marital status: S for single, M for married");
JOptionPane.showMessageDialog(null, "Your status is " + status);
JOptionPane.showMessageDialog(null, "Your estimated tax is " + TaxReturn.getTaxRate());
System.exit(0);
}
}
TaxReturn.java
public class TaxReturn
{
private double inputIncome;
private double estimTaxRate;
private double taxRate;
private String status;
public TaxReturn(double annualIncome, String maritalStatus)
{ inputIncome = annualIncome;
status = maritalStatus;
if(maritalStatus.equals("S") && annualIncome<= 10000)
taxRate = .15;
if(maritalStatus.equals("S") && annualIncome > 10000)
taxRate = .30;
if(maritalStatus.equals("M") && annualIncome < 20000)
taxRate = .15;
if(maritalStatus.equals("M") && annualIncome >=20000)
taxRate = .30;
estimTaxRate = taxRate * annualIncome;
}
public double getTaxRate()
{
return estimTaxRate;
}
}
thanks for any help!
Carrie
I am extremely new at Java, and I'm working on a program that will calculate estimated tax. I think I have everything right, but I can't figure out how to get the information calculated in TaxReturn.java (see below) to print out. I'm going to post both Tax.java and TaxReturn.java for your review. Can you help? I'm sure this is not very well written, but I'm learning!
tax.java :
import javax.swing.*;
public class Tax
{ static final String SINGLE = "S";
static final String MARRIED = "M";
public static void main(String[] args) throws Exception
{
String inputIncome;
double inputNumber;
String status;
TaxReturn = aTaxReturn;
inputIncome = JOptionPane.showInputDialog(null, "Enter your annual income with no commas or decimals");
inputNumber = Double.parseDouble(inputIncome);
JOptionPane.showMessageDialog(null, "Your annual income is " + inputNumber);
status = JOptionPane.showInputDialog(null, "Enter your marital status: S for single, M for married");
JOptionPane.showMessageDialog(null, "Your status is " + status);
JOptionPane.showMessageDialog(null, "Your estimated tax is " + TaxReturn.getTaxRate());
System.exit(0);
}
}
TaxReturn.java
public class TaxReturn
{
private double inputIncome;
private double estimTaxRate;
private double taxRate;
private String status;
public TaxReturn(double annualIncome, String maritalStatus)
{ inputIncome = annualIncome;
status = maritalStatus;
if(maritalStatus.equals("S") && annualIncome<= 10000)
taxRate = .15;
if(maritalStatus.equals("S") && annualIncome > 10000)
taxRate = .30;
if(maritalStatus.equals("M") && annualIncome < 20000)
taxRate = .15;
if(maritalStatus.equals("M") && annualIncome >=20000)
taxRate = .30;
estimTaxRate = taxRate * annualIncome;
}
public double getTaxRate()
{
return estimTaxRate;
}
}
thanks for any help!
Carrie