Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help on my java homework

Status
Not open for further replies.

resh

Technical User
Nov 5, 2003
1
US
Hi Can someone help me.. I have to write a program to calculate tax for single or married taxpayers. I was able to create tax.java file but it also requires TaxReturn.java file.

The necessary classes are a Tax class with a main() method for keyboard entry of income and
code status values, and a TaxReturn class to calculate the tax based on the input. The input
values should be passed from the tax class to the taxs return classs through the
instantiation of a TaxReturn project. The instantiation could take a form such as
TaxReturn aTaxReturn = new TaxReturn(income, status);

Here is my Tax.java file. Can someone send me helpful hints on how to create TaxReturn.java file from this:

import javax.swing.JOptionPane;

import java.lang.String;

public class Tax

{

public static void main(String args[] )

{

double income, tax=0.0;

String input, marital_status;

// int S=1, M=2, mstatus;

char marstatus;


// read input from user as string

input = JOptionPane.showInputDialog("Enter your income " );


//convert income from type string to type double

income= Double.parseDouble(input);


System.out.println();

System.out.println(" Your income is:" + input );


// read marital status from user as string

// String userpromth = " enter 1 if single, 2 if married";

String userpromth = " enter S if single, M if married";


marital_status= JOptionPane.showInputDialog(userpromth);


marstatus = marital_status.charAt(0); // take first character


System.out.println(" Marital status is :"+ marstatus);

JOptionPane.showMessageDialog( null, marital_status, "marital status is :",

JOptionPane.INFORMATION_MESSAGE );


// mstatus = Integer.parseInt(marital_status);


if (!(marital_status.equals ("S" )) && !(marital_status.equals ("M")) ) // to compare string

// if( mstatus != s && mstatus != m)

{

JOptionPane.showMessageDialog( null,

" Invalid Input", "Error",

JOptionPane.ERROR_MESSAGE);

System.out.println("Invalid input, please try again");

}

else

{

if (marital_status.equals ("S"))

if(income <=10000.00)

tax = income* 0.15;

else

if(income >= 10000.00)

tax = income * 0.30;



else

if(income <= 20000.0)

tax = 0.15 * income;

else

if(income >= 200000.0)

tax = income*0.30;



System.out.println(&quot; Tax is: &quot; + tax);

}

System.out.println(&quot; Thank you: &quot;);

}

}

/* Example on Output

Your income is: 10000.0

Marital status is :S

Tax is: 150.00

Thank you:

*/

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top