Show TOC Start of Content Area

Syntax documentation TaxUIController Class  Locate the document in its SAP Library structure

This is the source code of the Java class TaxUIController:

package org.example.tax.web;

 

import java.text.NumberFormat;

import java.util.Locale;

import org.example.tax.ITaxCalculator;

import org.example.tax.TaxFactory;

 

public class TaxUIController {

   private static NumberFormat usCurrencyFormatter =

      NumberFormat.getCurrencyInstance(Locale.US);

   private double income = 0;

   private double tax = 0;

 

   public void setIncome(String s) {

      if (s == null) {

         income = 0;

      } else {

         try {

            if ((s.charAt(0) == '$') && (s.length() > 1)) {

               s = s.substring(1);

            }

            s = s.trim();

            income = Double.parseDouble(s);

         } catch (Exception e) {

            income = 0;

         }

      }

      ITaxCalculator calculator = TaxFactory.createInstance();

      tax = calculator.calculateTax(income);

   }

 

   public double getIncome() {

      return income;

   }

 

   public double getTax() {

      return tax;

   }

 

   public String formatIncome() {

      return usCurrencyFormatter.format(income);

   }

 

   public String formatTax() {

      return usCurrencyFormatter.format(tax);

   }

}

 

 

 

 

End of Content Area