📄 corporation.java
字号:
import java.util.*;
import org.jlf.log.*;
import org.jlf.dataMap.*;
/**
* This class hold information for a corporate
* customer to give volume discounts for their purchases.
*/
public class Corporation extends VolumeCustomer {
// --------------------------------------------------------------
// Section 1: DataMappedObject descriptors
// --------------------------------------------------------------
// Constants for attributes
public static final String COMPANY_NAME_ATTRIBUTE = "COMPANY_NAME";
/**
* 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(COMPANY_NAME_ATTRIBUTE,
StringAttribute.class, false);
descriptor.setMaximumLength(50);
descriptors.put(COMPANY_NAME_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 Corporation() {}
// --------------------------------------------------------------
// 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 Corporation(String nickname, String emailAddress, String name,
String companyName, String address, String city,
String state, String zipcode) {
super(nickname, emailAddress, name, address, city, state, zipcode);
setCompanyName(companyName);
resetCustomerType(CustomerType.CORPORATE_CUSTOMER);
}
/**
* Retrieves the Corporation's name.
*/
public String getCompanyName() {
return getStringAttribute(COMPANY_NAME_ATTRIBUTE);
}
/**
* Sets the Corporation's name.
*/
public void setCompanyName(String name) {
setStringAttribute(COMPANY_NAME_ATTRIBUTE, name);
}
/**
* Return the amount of discount applicable to the volume
* customer. Give a 10% discount to all corporations.
*/
public double discountRate() {
return 0.10;
}
/**
* Add to superclass to output additional
* volume customer attributes
*/
public String toString() {
return super.toString() + "\n Company Name: " + getCompanyName();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -