package com.chinanetcenter.example.charge.version6;
import java.net.URL;
import java.util.*;
public class User {
private String name;
private Vector<Bill> bills = new Vector<Bill>();
public User(String name) {
this.name = name;
}
public void addBill(Bill bill) {
this.bills.addElement(bill);
}
public String getName() {
return this.name;
}
public String report() {
Enumeration<Bill> bills = this.bills.elements();
String result = getName() + "被收取的服务费用:\n";
while (bills.hasMoreElements()) {
Bill bill = (Bill) bills.nextElement();
result += "\t" + bill.getService().getAddress() + "\t"
+ String.valueOf(bill.getCharge()) + "\n";
}
result += "\n\t收费总额是\t" + String.valueOf(getTotalCharge()) + "元\n";
result += "\t重要性指数\t" + String.valueOf(getTotalAbility()) + "\n";
return result;
}
private int getTotalAbility() {
int totalAbility = 0;
Enumeration<Bill> bills = this.bills.elements();
while (bills.hasMoreElements()) {
Bill bill = (Bill) bills.nextElement();
totalAbility += bill.getAbility();
}
return totalAbility;
}
private double getTotalCharge() {
double totalCharge = 0;
Enumeration<Bill> bills = this.bills.elements();
while (bills.hasMoreElements()) {
Bill bill = (Bill) bills.nextElement();
totalCharge += bill.getCharge();
}
return totalCharge;
}
}
class Bill {
private Service service;
private double trafficAccount;
public Bill(Service service, double trafficAccount) {
this.service = service;
this.trafficAccount = trafficAccount;
}
public double getTrafficAccount() {
return trafficAccount;
}
public void setTrafficAccount(double trafficAccount) {
this.trafficAccount = trafficAccount;
}
public Service getService() {
return this.service;
}
public int getAbility() {
return service.getAbility(getTrafficAccount());
}
public double getCharge() {
return service.getCharge(getTrafficAccount());
}
}
class Service {
private URL address;
private ServiceType type;
public Service(URL address,int type) {
this.address = address;
this.setType(ServiceType.getServiceType(type));
}
public ServiceType getType() {
return this.type;
}
public void setType(ServiceType type) {
this.type = type;
}
public URL getAddress() {
return address;
}
public void setAddress(URL address) {
this.address = address;
}
public int getAbility(double trafficAccount) {
return getType().getAbility(trafficAccount);
}
public double getCharge(double trafficAccount) {
return getType().getCharge(trafficAccount);
}
}
abstract class ServiceType {
public static final int WEB = 0;
public static final int STREAM = 1;
public static final int DOWNLOAD = 2;
abstract int getTypeCode();
abstract double getCharge(double trafficAccount);
abstract int getAbility(double trafficAccount);
public static ServiceType getServiceType(int code) {
switch (code) {
case ServiceType.WEB:
return new Web();
case ServiceType.STREAM:
return new Stream();
case ServiceType.DOWNLOAD:
return new Download();
default:
throw new IllegalArgumentException("不存在的类型");
}
}
}
class Web extends ServiceType {
public Web() {
}
@Override
public int getTypeCode() {
return ServiceType.WEB;
}
@Override
public double getCharge(double trafficAccount) {
return trafficAccount * 1000;
}
@Override
public int getAbility(double trafficAccount) {
return (int)trafficAccount/100;
}
}
class Stream extends ServiceType {
public Stream() {
}
@Override
public int getTypeCode() {
return ServiceType.STREAM;
}
@Override
public double getCharge(double trafficAccount) {
return trafficAccount * 0.7 * 1000;
}
@Override
int getAbility(double trafficAccount) {
return (int)trafficAccount/600;
}
}
class Download extends ServiceType {
public Download() {
}
@Override
public int getTypeCode() {
return ServiceType.DOWNLOAD;
}
@Override
public double getCharge(double trafficAccount) {
return trafficAccount * 0.5 * 1000;
}
@Override
int getAbility(double trafficAccount) {
return (int)trafficAccount/600;
}
}

wunglee
- 粉丝: 1
最新资源
- matlab演示:一种用于弥合彩色图像与人类场景观察之间差距的多尺度Retinex__a matlab demo for
- MIMO OFDM Matlab MIMO_MIMO OFDM Matlab实现书中MIMO部分的代码实现.zip
- 一个Python库,用于评估对象检测的平均精度(mAP)。提供与PASCAL VOC的matlab代码相同的输出。_A
- PNAS视觉模式完成的循环计算_人类遮挡图像的分类和循环神经网络_[PNAS'18] Recurrent computa
- 高维数据统计(均匀性、球形、独立性、球形均匀性)_Statistics for high-dimensional dat
- 一组MATLAB包装脚本,用于帮助对断层扫描数据进行预处理。_A set of MATLAB wrapper scrip
- HistoSketch和D HistoSketching在MATLAB中的实现_Implementation of Hi
- nVidia GPU的C和Matlab API GPU反卷积库_GPU Deconvolution Library wi
- 关于EKF、AEKF、HIF和PF的Matlab代码,用于估计电池单元的SoC_Matlab codes about E
- SIMToolbox MATLAB代码的所有发布版本_All released versions of SIMToolb
- Caiafa论文演示——多维压缩传感及其应用。由于我们无法在中国打开MEGA,matlab代码的副本被推送到GitHub
- 自定义霍夫曼代码字典生成器、编码器和解码器功能_Custom Huffman code dictionary gener
- This is a matlab implementation of J.Park's work _High Quali
- Myo MATLAB数据流接口依赖于从Python更新的文本文件中读取的实时数据。Python用于与Myo Connec
- 软件_Matlab数字音频处理系统.zip
- 这是论文IEEE TCSVT的Matlab代码,_This is the Matlab code of paper _D
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


