Skip to content

List tax names

One of the steps you’ll address when developing a payroll-related application is to determine which taxes should be applied for a given employer and employee. The most basic way to do this is to list all the tax names available in the tax table data file. This is the task we’ll tackle in this section.

  1. Enter Code

Enter the following code in a file named ‘List.cs’:

using System;
using System.Collections;
using TaxControls;
class Test{
public static void Main(){
try {
CTaxControl tc = new CTaxControl();
tc.DataFilename = "demo.tax";
Taxes txs = tc.Taxes;
foreach(Tax t in txs) {
Console.WriteLine(t.Name);
}
} catch (TaxControlException e) {
Console.WriteLine(e.Message);
}
}
}

Enter the following code in a file named ‘List.java’:

import com.boondocks.taxcontrols.TaxControl;
import com.boondocks.taxcontrols.Taxes;
import com.boondocks.taxcontrols.Tax;
import com.boondocks.taxcontrols.TaxControlException;
import java.util.Enumeration;
public class List{
public static void main(String[] args){
TaxControl tc = new TaxControl();
tc.setDataFilename("demo.tax");
try{
for (Tax t: tc.getTaxes()) {
System.out.println(t.getName());
}
} catch (TaxControlException e){
e.printStackTrace();
}
}
}
  1. Compile

Compile the code at the command prompt by executing the following:

Terminal window
\...\csc.exe /reference:TaxControls.dll List.cs
Terminal window
javac -classpath .;bigloo_u.zip;TaxControls.jar List.java
  1. Run

Run the code by typing:

Terminal window
List
Terminal window
java -classpath .;bigloo_u.zip;TaxControls.jar List