1、一個(gè)人(Person)在過(guò)河的時(shí)候需要使用(useTool())一條船(Boat)。請(qǐng)用類圖表示人
1、一個(gè)人(Person)在過(guò)河的時(shí)候需要使用(useTool())一條船(Boat)。請(qǐng)用類圖表示人與船的關(guān)系。
?
?
package?面向?qū)ο蠡靖拍罹C合練習(xí);
//一個(gè)人(Person)在過(guò)河的時(shí)候需要使用(useTool())一條船(Boat)。
public?class?課堂練習(xí)題1 {
?
public?static?void?main(String[] args) {
// TODO?Auto-generated method stub
class?Person?{
????
????????// code to use the boat to cross the river
????}
}
?
class?Boat {
????// code for the boat class
}
?
}
?
?
```
+---------+ +---------+
| Person | | Boat |
+---------+ +---------+
| | | |
+---------+ +---------+
| |
| |
useTool() addPerson()
|
removePerson()
```
注釋:
- Person類有一個(gè)useTool()方法。
- Boat類有兩個(gè)方法addPerson()和removePerson()用于添加和移除人。
- Person類與Boat類之間是一對(duì)多的關(guān)系。
?
標(biāo)簽: