Compute a Tax Amount
Enter Code
Enter the following code in a file named ‘Compute.cs’:
using System;using TaxControls;class Compute{ public static void Main(){ try { CTaxControl tc = new CTaxControl(); tc.DataFilename = "demo.tax"; tc.SelectedTax = "federal income tax"; tc.Earnings = 5000.00; Console.WriteLine(tc.TaxAmount()); } catch (TaxControlException e) { Console.WriteLine(e.Message); } }}
Enter the following code in a file named ‘Compute.java’:
import com.boondocks.taxcontrols.TaxControl;import com.boondocks.taxcontrols.TaxControlException;public class Compute{ public static void main(String[] args){ try{ TaxControl tc = new TaxControl(); tc.setDataFilename("demo.tax"); tc.setSelectedTax("federal income tax"); tc.setEarnings(5000.0); System.out.println(tc.getTaxAmount()); } catch (TaxControlException e){ e.printStackTrace(); } }}
This minimal code chooses the tax table data file, sets the earnings per pay period to $5000, and computes the tax. Default values were taken, which for most properties is zero, except PayPeriodsPerYear which defaults to 12 (monthly).
Compile
Compile the code at the command prompt by executing the following:
csc /reference:TaxControls.dll Compute.cs
javac -classpath .;bigloo_u.zip;TaxControls.jar Compute.java
Run
Run the code by typing:
Compute
java -classpath .;bigloo_u.zip;TaxControls.jar Compute
The program’s output should show the computed federal tax.