nonprofitcorporation.java

来自「此程序都是企业级 的数据库开发程序 全面揭示了JAVA对数据库的操作」· Java 代码 · 共 100 行

JAVA
100
字号
import java.util.*;

import org.jlf.log.*;
import org.jlf.dataMap.*;

/**
 * This class hold information for a non-profit corporate
 * customer to give volume discounts for their purchases
 * and also not charge them sales tax.
 */
public class NonProfitCorporation extends Corporation {

  // --------------------------------------------------------------
  // Section 1: DataMappedObject descriptors
  // --------------------------------------------------------------

  // Constants for attributes
  public static final String TAX_EXEMPT_ID_ATTRIBUTE = "TAX_EXEMPT_ID";

  /**
   * Adds attribute descriptors for the current class.
   */
  protected Hashtable basicGetAttributeDescriptors() {

    // Always call the superclass!
    Hashtable descriptors = super.basicGetAttributeDescriptors();
    DataAttributeDescriptor descriptor;

    // Then add class-specific attributes
    descriptor = new DataAttributeDescriptor(TAX_EXEMPT_ID_ATTRIBUTE, 
                                             StringAttribute.class, false);
    descriptor.setMaximumLength(50);
    descriptors.put(TAX_EXEMPT_ID_ATTRIBUTE, descriptor);

    return descriptors;
  } 

  /**
   * Default constructor must be public for the data mapping
   * framework!  However, when creating a new object, look to use
   * a paramterized constructor.
   */
  public NonProfitCorporation() {}


  // --------------------------------------------------------------
  // Section 2: Java bean and business logic methods
  // --------------------------------------------------------------

  /**
   * Main constructor for the class.  Populates all
   * attributes of the class and sets the type accordingly.
   */
  public NonProfitCorporation(String nickname, String emailAddress, 
                              String name, String companyName, 
                              String address, String city, String state, 
                              String zipcode, String taxExemptId) {
    super(nickname, emailAddress, name, companyName, address, city, state, 
          zipcode);
    setTaxExemptId(taxExemptId);
    resetCustomerType(CustomerType.NON_PROFIT_CUSTOMER);
  }

  /**
   * Retrieves the tax exempt id.
   */
  public String getTaxExemptId() {
    return getStringAttribute(TAX_EXEMPT_ID_ATTRIBUTE);
  } 

  /**
   * Sets the tax exempt id.
   */
  public void setTaxExemptId(String id) {
    setStringAttribute(TAX_EXEMPT_ID_ATTRIBUTE, id);
  } 

  /**
   * Return the amount of discount applicable to the volume
   * customer.  Give a 15% discount to all non-profit groups.
   */
  public double discountRate() {
    return 0.15;
  } 

  /**
   * This customer is a non-profit corporation.
   */
  public boolean isNonProfit() {
    return true;
  } 

  /**
   * Add to superclass to output additional
   * volume customer attributes
   */
  public String toString() {
    return super.toString() + "\n  Tax Exempt Id: " + getTaxExemptId();
  } 
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?