📄 volumecustomer.java
字号:
import java.util.*;
import org.jlf.log.*;
import org.jlf.dataMap.*;
/**
* This class is an abstract class used to hold
* information for a volume customer
* to give discounts in reward for their loyalty.
*/
public abstract class VolumeCustomer extends Customer {
// --------------------------------------------------------------
// Section 1: DataMappedObject descriptors
// --------------------------------------------------------------
// Constants for attributes
public static final String NAME_ATTRIBUTE = "NAME";
public static final String ADDRESS_ATTRIBUTE = "ADDRESS";
public static final String CITY_ATTRIBUTE = "CITY";
public static final String STATE_ATTRIBUTE = "STATE";
public static final String ZIP_CODE_ATTRIBUTE = "ZIPCODE";
/**
* 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(NAME_ATTRIBUTE,
StringAttribute.class, false);
descriptor.setMaximumLength(50);
descriptors.put(NAME_ATTRIBUTE, descriptor);
descriptor = new DataAttributeDescriptor(ADDRESS_ATTRIBUTE,
StringAttribute.class, true);
descriptor.setMaximumLength(50);
descriptors.put(ADDRESS_ATTRIBUTE, descriptor);
descriptor = new DataAttributeDescriptor(CITY_ATTRIBUTE,
StringAttribute.class, true);
descriptor.setMaximumLength(20);
descriptors.put(CITY_ATTRIBUTE, descriptor);
descriptor = new DataAttributeDescriptor(STATE_ATTRIBUTE,
StringAttribute.class, true);
descriptor.setMaximumLength(2);
descriptors.put(STATE_ATTRIBUTE, descriptor);
descriptor = new DataAttributeDescriptor(ZIP_CODE_ATTRIBUTE,
StringAttribute.class, true);
descriptor.setMaximumLength(10);
descriptors.put(ZIP_CODE_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 VolumeCustomer() {}
// --------------------------------------------------------------
// Section 2: Java Bean methods
// --------------------------------------------------------------
/**
* Main constructor for the class. Populates all
* attributes of the class.
*/
public VolumeCustomer(String nickname, String emailAddress, String name,
String address, String city, String state,
String zipcode) {
super(nickname, emailAddress);
setName(name);
setAddress(address);
setCity(city);
setState(state);
setZipCode(zipcode);
}
/**
* Retrieves the Customer's name.
*/
public String getName() {
return getStringAttribute(NAME_ATTRIBUTE);
}
/**
* Sets the Customer's name.
*/
public void setName(String name) {
setStringAttribute(NAME_ATTRIBUTE, name);
}
/**
* Retrieves the Customer's address.
*/
public String getAddress() {
return getStringAttribute(ADDRESS_ATTRIBUTE);
}
/**
* Sets the Customer's address.
*/
public void setAddress(String address) {
setStringAttribute(ADDRESS_ATTRIBUTE, address);
}
/**
* Retrieves the Customer's city.
*/
public String getCity() {
return getStringAttribute(CITY_ATTRIBUTE);
}
/**
* Sets the Customer's city.
*/
public void setCity(String city) {
setStringAttribute(CITY_ATTRIBUTE, city);
}
/**
* Retrieves the Customer's state.
*/
public String getState() {
return getStringAttribute(STATE_ATTRIBUTE);
}
/**
* Sets the Customer's state.
*/
public void setState(String state) {
setStringAttribute(STATE_ATTRIBUTE, state);
}
/**
* Retrieves the Customer's zip code.
*/
public String getZipCode() {
return getStringAttribute(ZIP_CODE_ATTRIBUTE);
}
/**
* Sets the Customer's zip code.
*/
public void setZipCode(String zipCode) {
setStringAttribute(ZIP_CODE_ATTRIBUTE, zipCode);
}
/**
* Add to superclass to output additional
* volume customer attributes
*/
public String toString() {
return super.toString() + "\n Name: " + getName() + "\n Address: "
+ getAddress() + "\n " + getCity() + ", " + getState()
+ " " + getZipCode() + "\n Discount Rate: " + discountRate()
+ "\n Is Non-Profit: " + isNonProfit();
}
// --------------------------------------------------------------
// Section 3: Business logic methods
// --------------------------------------------------------------
/**
* Return the amount of discount applicable to the volume
* customer. The value returned is multiplied by the purchase
* price to determine discount.
*/
public abstract double discountRate();
/**
* Tell if the customer is a non-profit corporation.
*/
public boolean isNonProfit() {
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -