Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Lab Session 3: Statemachines & complete systems 
(1): Download the new version of the tools (umlrsds1p4a) from 
http://www.dcs.kcl.ac.uk/staff/kcl/uml2web/ and extract the files. 
(2): Run java UmlTool in the extracted tool directory. Select "File" -> "Recent" to load a simple model 
consisting of a Student class, with 2 operations: 
 
 
 
(3): Select "Create" -> "Entity statemachine" and choose the Student class from the list. 
(4): In the statemachine editor, create 3 states, and edit them so that they have names "year1", 
"year2" and "year3", and year1 is initial. Add transitions for progress, so that you have the following 
diagram: 
 
(5): On the class diagram editor, select 
"Transform" -> "Refinement" -> "Express statemachine on class diagram". You should get an 
enhanced class diagram, like this: 
 
(6): Generate Java to see how the statemachine semantics is expressed in code. 
(7): Add self-transitions to the year1 and year2 states for operation "retake", and repeat steps (5) 
and (6). 
 
Creating a complete application 
 
Now we are ready to specify a complete (if small) application using UML. The system will create two 
students, display their data, progress them, and display them again. 
(1) Select "Create" -> "Use case" -> "General use case" and give the use case the name "test". 
(2) Select "Edit use case" and "Add postcondition" for the "test" use case. (Or select "Modify" and 
click on the use case oval in the diagram editor). Set assumption as true, and postcondition as: 
  Student->exists( s | s.name = "Lee" ) &  Student->exists( p | p.name = "Felix" ) 
The entity name (in the dialog after this one) is left blank. 
  
(3) Repeat (2), adding the postcondition 
  ("Student: " + name + " " + studentState)->display()  
with the entity name as Student. 
(4) Now a system can be generated: select "Synthesis" -> "Generate design" and then "Generate 
Java" 
(5) In the output directory, compile the generated code: Controller.java and GUI.java 
(6) Execute the GUI: java GUI, select "test", and you should get the message: 
 
  Student: Lee 0 
  Student: Felix 0 
 
(0 is the numeric value of year1). 
(7) You can add further postconditions to "test": 
    progress() 
 
on Student progresses all students, and  
 
    ("Student: " + name + " " + studentState)->display()  
 
on Student will display them all again. Repeat steps (4), (5) and (6) to see the effect of these 
additions. 
Congratulations: you have now written a 1000-line Java program without touching a line of code!