信安李自然UML实验报告顺序图.docx

上传人:b****7 文档编号:25318169 上传时间:2023-06-07 格式:DOCX 页数:20 大小:67.67KB
下载 相关 举报
信安李自然UML实验报告顺序图.docx_第1页
第1页 / 共20页
信安李自然UML实验报告顺序图.docx_第2页
第2页 / 共20页
信安李自然UML实验报告顺序图.docx_第3页
第3页 / 共20页
信安李自然UML实验报告顺序图.docx_第4页
第4页 / 共20页
信安李自然UML实验报告顺序图.docx_第5页
第5页 / 共20页
点击查看更多>>
下载资源
资源描述

信安李自然UML实验报告顺序图.docx

《信安李自然UML实验报告顺序图.docx》由会员分享,可在线阅读,更多相关《信安李自然UML实验报告顺序图.docx(20页珍藏版)》请在冰豆网上搜索。

信安李自然UML实验报告顺序图.docx

信安李自然UML实验报告顺序图

北京信息科技大学

实验(上机)报告

课程名称UML及建模工具学号2012012194姓名李自然成绩_______

专业名称

信息安全

实验室名称

3-702

实验时间

15.6

实验名称

实验6:

绘制顺序图

1.实验目的:

1)掌握UML顺序图建模的意义。

2)掌握RationalRose或其他工具绘制顺序图的方法。

3)理解顺序图和类图之间的关系。

2.实验内容:

1)根据附录一源程序,绘制顺序图(店员租赁影片用例)。

2)根据上学期的数据库系统开发的试卷题目及答案(见附录二),绘制顺序图(教务员添加课程用例)

3)同步课程设计任务:

小组成员在分层架构和实体类的共同讨论的基础上,对个人负责的用例进行详细设计(用例的界面、界面数据的说明、实现用例的参与类、用例的详细流程的顺序图)。

3.实验要求:

1)直接将顺序图拷贝粘贴到实验报告中提交。

2)正确使用消息。

3)个人独立完成。

4)提交最后期限:

当日提交。

 

4.实验准备:

1)

5.实验过程和结果:

1)根据附录一源程序,绘制顺序图(店员租赁影片用例)

 

2)根据上学期的数据库系统开发的试卷题目及答案(见附录二),绘制顺序图(教务员添加课程用例)

 

6.实验总结:

 

通过这次实验,掌握UML顺序图建模的意义。

掌握了用RationalRose绘制顺序图的方法。

理解顺序图和类图之间的关系

 

附录一:

影片租赁源程序

//租赁类的定义

classRental

{

privateMovie_movie。

//影片

privateint_rentDate。

//租赁日期

privateint_daysRented。

//租期

publicRental(Moviemovie,intdaysRented)

{

_movie=movie。

_daysRented=daysRented。

}

publicintgetDaysRented()

{

return_daysRented。

}

publicMoviegetMovie()

{

return_movie。

}

doublegetCharge()

{

return_movie.getCharge(_daysRented)。

}

intgetFrequentRenterPoints()

{

return_movie.getFrequentRenterPoints(_daysRented)。

}

}

//顾客类的定义

classCustomer

{

privateString_name。

//姓名

privateString_phone。

//电话号码

privateVector_rentals=newVector()。

//租借纪录

publicCustomer(Stringname)

{

_name=name。

}

publicvoidaddRental(Rentalarg)

{

_rentals.addElement(arg)。

}

publicStringgetName()

{

return_name。

}

//输出租赁交易报告

publicStringstatement()

{

Enumerationrentals=_rentals.elements()。

Stringresult="RentalRecordfor"+getName()+"\n"。

while(rentals.hasMoreElements())

{

Rentaleach=(Rental)rentals.nextElement()。

//显示该顾客的每个租赁

result+="\t"+each.getMovie().getTitle()+"\t"+String.valueOf(each.getCharge())+"\n"。

}

//结尾打印(总费用和积分)

result+="Amountowedis"+String.valueOf(getTotalCharge())+"\n"。

result+="Youearned"+String.valueOf(getTotalFrequentRenterPoints())+"frequentrenterpoints"。

returnresult。

}

//已超文本方式输出租赁交易报告

publicStringhtmlStatement()

{

Enumerationrentals=_rentals.elements()。

Stringresult="

Rentalsfor"+getName()+"

\n"。

while(rentals.hasMoreElements())

{

Rentaleach=(Rental)rentals.nextElement()。

//显示该顾客的每个租赁

result+=each.getMovie().getTitle()+":

"+String.valueOf(each.getCharge())+"
\n"。

}

//结尾打印(总费用和积分)

result+="

Youowe"+String.valueOf(getTotalCharge())+"

\n"。

result+="Onthisrentalyouearned"+String.valueOf(getTotalFrequentRenterPoints())+

"frequentrenterpoints

"。

returnresult。

}

//计算总积分

privateintgetTotalFrequentRenterPoints()

{

intresult=0。

Enumerationrentals=_rentals.elements()。

while(rentals.hasMoreElements())

{

Rentaleach=(Rental)rentals.nextElement()。

result+=each.getFrequentRenterPoints()。

}

returnresult。

}

//计算总费用

privatedoublegetTotalCharge()

{

doubleresult=0。

Enumerationrentals=_rentals.elements()。

while(rentals.hasMoreElements()){

Rentaleach=(Rental)rentals.nextElement()。

result+=each.getCharge()。

}

returnresult。

}

}

//抽象价格类的定义

abstractclassPrice

{

abstractintgetPriceCode()。

//取得价格代号

abstractdoublegetCharge(intdaysRented)。

//根据租期计算费用

intgetFrequentRenterPoints(intdaysRented)//根据租期计算积分

{

return1。

}

}

//儿童价格类的定义

classChildrensPriceextendsPrice

{

intgetPriceCode()

{

returnMovie.CHILDRENS。

}

doublegetCharge(intdaysRented)

{

doubleresult=1.5。

if(daysRented>3)

result+=(daysRented-3)*1.5。

returnresult。

}

}

//新片价格类的定义

classNewReleasePriceextendsPrice

{

intgetPriceCode()

{

returnMovie.NEW_RELEASE。

}

doublegetCharge(intdaysRented)

{

returndaysRented*3。

}

intgetFrequentRenterPoints(intdaysRented)

{

return(daysRented>1)?

2:

1。

}

}

//普通片价格类的定义

classRegularPriceextendsPrice

{

intgetPriceCode()

{

returnMovie.REGULAR。

}

doublegetCharge(intdaysRented)

{

doubleresult=2。

if(daysRented>2)

result+=(daysRented-2)*1.5。

returnresult。

}

}

//影片类和主程序

publicclassMovie

{

publicstaticfinalintCHILDRENS=2。

publicstaticfinalintREGULAR=0。

publicstaticfinalintNEW_RELEASE=1。

privateString_title。

//名称

privatePrice_price。

//影片的价格

publicMovie(Stringtitle,intpriceCode)

{

_title=title。

setPriceCode(priceCode)。

}

publicintgetPriceCode()

{

return_price.getPriceCode()。

}

publicvoidsetPriceCode(intarg)

{

switch(arg)

{

caseREGULAR:

//普通片

_price=newRegularPrice()。

break。

caseCHILDRENS:

//儿童片

_price=newChildrensPrice()。

break。

caseNEW_RELEASE:

//新片

_price=newNewReleasePrice()。

break。

default:

thrownewIllegalArgumentException("IncorrectPriceCode")。

}

}

publicStringgetTitle()

{

return_title。

}

//影片租金

doublegetCharge(intdaysRented)

{

return_price.getCharge(daysRented)。

}

//影片积分

intgetFrequentRenterPoints(intdaysRented)

{

return_price.getFrequentRenterPoints(daysRented)。

}

//主程序

usingSystem。

usingSystem.Collections.Generic。

usingSystem.ComponentModel。

usingSystem.Data。

usingSystem.Drawing。

usingSystem.Text。

usingSystem.Windows.Forms。

publicpartialclassRentForm:

Form

{

publicRentForm()

{

InitializeComponent()。

}

privatevoidbutton1_Click(objectsender,EventArgse)

{

Moviem1=newMovie("阿凡达",1)。

Moviem2=newMovie("将爱情进行到底",2)。

Moviem3=newMovie("喜羊羊与灰太郎",3)。

//客户的租赁

Customerc1=newCustomer("张三")。

Rentalr1=newRental(m1,4)。

Rentalr2=newRental(m2,2)。

Rentalr3=newRental(m3,2)。

c1.addRental(r1)。

c1.addRental(r2)。

c1.addRental(r3)。

//输出顾客c1的消费报告

textBox1.Text=c3.statement()。

}

}

附录二:

五、程序题(本题满分37分,共含4道小题)

学校对重点课程建设进行经管,在SQLServer数据库中建立一张表courses,表结构如下:

字段名

含义

数据类型

备注

CourseID

课程编号

int

主键

Name

名称

nVarChar(20)

Hours

学时

int

School

学院

nVarchar(20)

一门课程只能属于一个学院

Web.Config文件中关于数据库连接串的配置代码如下:

    

Database=mydb。

integratedsecurity=true"/>

1.编写一个courses表对应的DTO类,类名为Course,命名空间是Model,额外为该类编写一个只读属性Credit(学分),学分按照学时计算(<=32:

2学分,32~48:

3学分,>48:

4学分)。

(8分)

2.编写一个courses表的数据访问类,类名为CourseDal,命名空间是Dal。

该类包括2个方法intInsert(Coursecourse)和ListSelectCoursesBySchool(stringschool)。

Insert方法将Course对象作为一个新行插入到数据表courses中;SelectCoursesBySchool方法将根据学院从数据表courses检索指定学院的所有课程记录,并返回Course对象集合。

(15分)

提示1:

该类已存在私有方法privateCourseGetCourseFromDataRow(DataRowrow),该方法利用传入的DataRow对象生成一个Course对象并返回,可直接使用该方法。

提示2:

代码中不能使用DBObject对象,要求直接采用ADO.NET对象访问数据库。

3.编写courses表对应的业务逻辑类,类名为CourseBll,命名空间是Bll,包含Add()、GetCoursesBySchool()方法。

请仅为方法intAdd(Coursecourse)编写代码实现一门课程的添加。

业务规则如下:

课程的学时必须大于等于32,小于等于64;每个学院至多有10门课程。

(8分)

4.现有一个AddCourse.aspx页面,在这个页面上有以下控件:

4个TextBox控件(Text1、Text2、Text3、Text4,分别用来输入课程编号、名称、学时、学院)、一个Button控件(名为Button1)。

编写Button1的单击事件处理程序,根据用户的输入调用第3小题中CourseBll类中的Add方法向数据库中添加一门课程(暂不考虑数据验证)。

(6分)

参考答案

1.编写一个courses表对应的DTO类,类名为Course,命名空间是Model,额外为该类编写一个只读属性Credit(学分),学分按照学时计算(<=32:

2学分,32~48:

3学分,>48:

4学分)。

(8分)

答:

命名空间1分,类名定义1分,4个属性每个1分,Credit属性2分。

namespaceModel

{

[Serializable]

publicclassCourse

{

privateint_CourseID。

publicintCourseID

{

get{return_CourseID。

}

set{_CourseID=value。

}

}

privatestring_name。

publicstringName

{

get{return_name。

}

set{_name=value。

}

}

privateint_hours。

publicintHourse

{

get{return_hours。

}

set{_hours=value。

}

}

privatestring_school。

publicstringSchool

{

get{return_school。

}

set{_school=value。

}

}

publicintCredit

{

get{

if(_hours<=32)return2。

elseif(_hours>32and_hours<=48)return3。

elseif(_hours>48)return4。

}

}

}

}

答:

命名空间1分,类名定义1分,数据库连接串1分,Insert方法的Sql语句2分,命令执行3分(使用DBObject得1分),SelectCoursesBySchool方法执行查询3分(使用DBObject得1分),获取结果返回3分。

using导入命名空间Model得1分。

namespaceDAL

{

publicclassCourseDal

{

privatestringconnString。

publicCourseDal()

{

connString=ConfigurationManager.ConnectionStrings["ConnString1"].ConnectionString。

}

publicintInsert(Coursecourse)

{

stringsql="insertintoCourse(CourseID,Name,Hourse,School)values("。

sql+=course.CourseID==""?

"null,":

("'"+course.CourseID+"',")。

sql+=course.Name==""?

"null,":

("'"+course.Name+"',")。

sql+=course.Hours==null?

"null,":

(course.Hours+",")。

sql+=course.School==""?

"null)":

("'"+course.School+"')")。

SqlConnectioncn=newSqlConnection(connString)。

cn.Open()。

SqlCommandcmd=newSqlCommand(sql,cn)。

intresult=cmd.ExecuteNonQuery()

cn.Close()。

return(result)。

}

publicListSelectCoursesBySchool(stringschool)

{

ListCourses=newList()。

stringsql="select*fromCoursewhereSchool='"+school+"'"。

DataSetds=newDataSet()。

SqlDataAdapterda=newSqlDataAdapter(sql,connString)。

da.Fill(ds,"Course")。

for(inti=0。

i

i++)

{

DataRowrow=ds.Tables["Course"].Rows[i]。

Coursecr=GetCourseFromDataRow(row)。

Courses.Add(cr)。

}

returnCourses。

}

privateCourseGetCourseFromDataRow(DataRowrow)

{……

}

}

}

答:

命名空间1分,类名定义1分,学时判断1分,学院课程数判断2分,插入2分,返回值1分。

namespace.BLL

{

publicclassCourseBLL

{

publicintAdd(Coursec1)

{

if(c1.Hours>=32andc1.Hours<=64)

{

CourseDalcDal=newCourseDal()。

Listcourses。

courses=cDal.SelectCoursesBySchool(c1.School)。

if(courses.Count<10)

{

cDal.Insert(c1)。

return1。

}

else

return0。

}

else

return0。

}

}

}

4.现有一个AddCourse.aspx页面,在这个页面上有以下控件:

4个TextBox控件(Text1、Text2、Text3、Text4,分别用来输入课程编号、名称、学时、学院)、一个Button控件(名为Button1)。

编写Button1的单击事件处理程序,根据用户的输入调用第3小题中CourseBll类中的Add方法向数据库中添加一门课程(暂不考虑数据验证)。

(6分)

答:

Course对象构造3分(没有整数类型转换得2分),创建CourseBll1分,调用及结果显示2分。

protectedvoidButton1_Click(objectsender,EventArgse)

{

Coursec1=newCourse()。

c1.CourseID=int.Parse(Text1.Text)。

c1.Name=Text2.Text。

c1.Hours=int.Parse(Text3.Text)。

c1.School=Text4.T

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1