There are three sample project 1 implementations in the repository of this lab.
Choose one project and write a code review with the following requirements:
- Read the project carefully and understand the code.
- Briefly describe the functions of at least 3 key variables and 3 key methods in the project, like what you wrote in your project document.
- Explain how the project implements undo and redo.
- Explain how the project implements the winning case that one player will lose if all its animals can't move.
- Demonstrate how can you improve your code by reading the sample code.
The code written by 李向民
is similar to most students' code, with one class and several methods. It's recommended to review his code if you have some problems with undo, redo and the last winning case.
The code written by 邱轶扬
has one more class: Animal
. This is the first step to write the project in object-oriented way. His code is a little bit hard to understand. It's recommended to review his code if you got a 95+ score in PJ1.
The code written by 李逢双
is highly object-oriented. You can review TA's code if you want to challenge yourself.
Dictionary is at the end of this section. (关键单词的翻译在末尾)
In an n-sided regular polygon all sides have the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). Design a class named RegularPolygon
that contains:
-
A private
int
data field namedn
that defines the number of sides in the polygon with default value 3. (一个定义了多边形边数的私有int
型变量n
,默认值为3。) -
A private
double
data field namedside
that stores the length of the side with default value 1. -
A private
double
data field namedx
that defines the x-coordinate of the center of the polygon with default value0
. -
A private
double
data field namedy
that defines the y-coordinate of the center of the polygon with default value0
. -
A no-arg constructor that creates a regular polygon with default values. (一个没有参数的构造函数,用默认值创建正多边形。)
-
A constructor that creates a regular polygon with the specified number of sides and length of side, centered at (
0
,0
). -
A constructor that creates a regular polygon with the specified number of sides, length of side, and x-and y-coordinates.
-
The accessor and mutator methods for all data fields.
-
The method
getPerimeter()
that returns the perimeter of the polygon. -
The method
getArea()
that returns the area of the polygon. The formula for computing the area of a regular polygon iswhere
n
stands for number of sides,s
for length of side andp
equals toπ
.Design and implement the class. The
RegularPolygon
class should not contain amain
method. Write a test program that creates threeRegularPolygon
objects, created using the no-arg constructor, usingRegularPolygon(6, 4)
, and usingRegularPolygon(10, 4, 5.6, 7.8)
. For each object, display its perimeter and area.The test program should look like:
public class TestRegularPolygon { public static void main(String[] args) { // Invoke test methods ... } private static void testWithNoArg() { ... } private static void testWithNumberAndLength() { ... } private static void testWithNumberLengthAndCoordinates() { ... } }
Dictionary:
polygon: 多边形
regular polygon: 正多边形
equilateral: 等边
equiangular: 等角
coordinate: 坐标
accessor methods: 数据字段的访问方法,指
getter
mutator methods: 数据字段的改变方法,指
setter
perimeter: 周长
implement: 实现
formula: 公式
Lab Deadline为本周二晚23:59:59。
将代码打包,以学号_姓名.文件类型
的格式命名,如13302010039_童仲毅.zip
。上传至FTP:
ftp://10.132.141.33/classes/16/161 程序设计A (戴开宇)/WORK_UPLOAD/lab9
PJ1的Code Review文档Deadline为本周五晚23:59:59,上传至:
ftp://10.132.141.33/classes/16/161 程序设计A (戴开宇)/WORK_UPLOAD/Code Review/pj1