/* 
   This is the example from class today.

   And this is an example of a multi-line header comment.

   Note that I had an error on the board in converting from
   input String to float. See the line marked ***

*/

public class ex6 {

    public static void main( String[] args ) {

	// declarations
	char   status;
	float  inc;
	double base, rate, offset, tax;

	// check that user entered enough command line arguments
	if ( args.length < 2 ) {
	    System.out.println( "usage: java ex6 <M|S> <income>" );
	    System.exit( 1 );
	}

	// convert command line arguments to data types needed here
	status = args[0].charAt( 0 );
	inc = (Float.valueOf( args[1] )).floatValue(); //***

	// echo input, after it has been converted
	System.out.println( "status=" + status );
	System.out.println( "inc=" + inc );

	// now find base, rate and offset, based on inputs
	if ( status == 'S' ) {
	    if ( inc > 0 ) {
		if ( inc > 21450 ) {
		    if ( inc > 51900 ) {
			base = 11743.50;
			rate = 0.31;
			offset = 51900;
		    } // end if inc > 51900
		    else {
			base = 3217.50;
			rate = 0.28;
			offset = 21450;
		    } // end else 21450 < inc <= 51900
		} // end if inc > 21450
		else {
		    base = 0;
		    rate = 0.15;
		    offset = 0;
		} // end else 0 < inc <= 21450
	    } // end if inc > 0
	    else {
		base = 0;
		rate = 0;
		offset = 0;
	    } // end else inc <= 0
	} // end if status == 'S'
	else {
	    if ( inc > 0 ) {
		if ( inc > 35800 ) {
		    if ( inc > 86500 ) {
			base = 19566.00;
			rate = 0.31;
			offset = 86500;
		    } // end if inc > 86500
		    else {
			base = 5370.00;
			rate = 0.28;
			offset = 35800;
		    } // end else 35800 < inc <= 86500
		} // end if inc > 35800
		else {
		    base = 0;
		    rate = 0.15;
		    offset = 0;
		} // end else 0 < inc <= 35800
	    } // end if inc > 0
	    else {
		base = 0;
		rate = 0;
		offset = 0;
	    } // end else inc <= 0
	} // end else status != 'S' (i.e., status == 'M')

	tax = (inc - offset)*rate + base;

	System.out.println( "tax = " + tax );


    } // end of main()


} // end of class ex6
