欢迎光临散文网 会员登陆 & 注册

1、一个人(Person)在过河的时候需要使用(useTool())一条船(Boat)。请用类图表示人

2023-03-09 11:45 作者:酸奶公园  | 我要投稿

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类之间是一对多的关系。

 


1、一个人(Person)在过河的时候需要使用(useTool())一条船(Boat)。请用类图表示人的评论 (共 条)

分享到微博请遵守国家法律