1、一个人(Person)在过河的时候需要使用(useTool())一条船(Boat)。请用类图表示人
1、一个人(Person)在过河的时候需要使用(useTool())一条船(Boat)。请用类图表示人与船的关系。
package 面向对象基本概念综合练习;
//一个人(Person)在过河的时候需要使用(useTool())一条船(Boat)。
public class 课堂练习题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类有一个useTool()方法。
- Boat类有两个方法addPerson()和removePerson()用于添加和移除人。
- Person类与Boat类之间是一对多的关系。