20150528_152805_40_UML-实验报告(03)-类图
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
北京信息科技大学
实验(上机)报告
课程名称U M L及建模工具学号2012012194姓名李自然成绩_______
附录:
影片租赁源程序
//租赁类的定义
class Rental
{
private Movie _movie; // 影片
private int _rentDate; // 租赁日期
private int _daysRented; // 租期
public Rental(Movie movie, int daysRented)
{
_movie = movie;
_daysRented = daysRented;
}
public int getDaysRented()
{
return _daysRented;
}
public Movie getMovie()
{
return _movie;
}
double getCharge()
{
return _movie.getCharge(_daysRented);
}
int getFrequentRenterPoints()
{
return _movie.getFrequentRenterPoints(_daysRented);
}
}
//顾客类的定义
class Customer
{
private String _name; // 姓名private String _phone; // 电话号码private Vector _rentals = new Vector(); // 租借纪录
public Customer(String name)
{
_name = name;
}
public void addRental(Rental arg)
{
_rentals.addElement(arg);
}
public String getName()
{
return _name;
}
//输出租赁交易报告
public String statement()
{
Enumeration rentals = _rentals.elements();
String result = "Rental Record for " + getName() + "\n";
while (rentals.hasMoreElements())
{
Rental each = (Rental) rentals.nextElement();
//显示该顾客的每个租赁
result += "\t" + each.getMovie().getTitle()+ "\t" + String.valueOf(each.getCharge()) + "\n";
}
//结尾打印(总费用和积分)
result += "Amount owed is " + String.valueOf(getTotalCharge()) + "\n";
result += "You earned " + String.valueOf(getTotalFrequentRenterPoints()) + " frequent renter points";
return result;
}
//已超文本方式输出租赁交易报告
public String htmlStatement()
{
Enumeration rentals = _rentals.elements();
String result = "
Rentals for " + getName() + "
\n";
while (rentals.hasMoreElements())
{
Rental each = (Rental) rentals.nextElement();
//显示该顾客的每个租赁
result += each.getMovie().getTitle()+ ": "+ String.valueOf(each.getCharge()) + "
\n";
}
//结尾打印(总费用和积分)
result += "
You owe " + String.valueOf(getTotalCharge()) + "
\n";
result += "On this rental you earned " + String.valueOf(getTotalFrequentRenterPoints()) + " frequent renter points
";
return result;
}
// 计算总积分
private int getTotalFrequentRenterPoints()
{
int result = 0;
Enumeration rentals = _rentals.elements();
while (rentals.hasMoreElements())
{
Rental each = (Rental) rentals.nextElement();
result += each.getFrequentRenterPoints();
}
return result;
}
// 计算总费用
private double getTotalCharge()
{
double result = 0;
Enumeration rentals = _rentals.elements();
while (rentals.hasMoreElements()) {
Rental each = (Rental) rentals.nextElement();
result += each.getCharge();
}
return result;
}
}
//抽象价格类的定义
abstract class Price
{
abstract int getPriceCode(); // 取得价格代号
abstract double getCharge(int daysRented); // 根据租期计算费用
int getFrequentRenterPoints(int daysRented) // 根据租期计算积分
{
return 1;