java编写一个测试类_java写一个测试类

一个棋子类的文件代码如下对其写一个测试类跪求解决后微信发红包!publicclassChecker{privatebooleanisRed;privateintrow;privateintcolumn;privatestaticfinalintfirstRow=1;privat...

一个棋子类的文件 代码如下 对其写一个测试类 跪求

解决后微信发红包!

public class Checker

{

private boolean isRed;

private int row;

private int column;

private static final int firstRow = 1;

private static final int lastRow = 8;

private static final int firstColumn = 1;

private static final int lastColumn = 8;

public Checker(boolean paramBoolean)

{

this(paramBoolean, 1, 1);

}

public Checker(boolean paramBoolean, int paramInt1, int paramInt2)

{

this.isRed = paramBoolean;

if (!validSquare(paramInt1, paramInt2))

{

paramInt1 = 1;

paramInt2 = 1;

}

this.row = paramInt1;

this.column = paramInt2;

}

public boolean isRed()

{

return this.isRed;

}

public int getRow()

{

return this.row;

}

public int getColumn()

{

return this.column;

}

public void move(int paramInt1, int paramInt2)

{

moveIfValid(paramInt1, paramInt2, 1);

}

private void moveIfValid(int paramInt1, int paramInt2, int paramInt3)

{

if (validStep(paramInt1, paramInt2, paramInt3))

{

this.row += paramInt1;

this.column += paramInt2;

}

}

private boolean validStep(int paramInt1, int paramInt2, int paramInt3)

{

if ((Math.abs(paramInt1) == paramInt3) && (Math.abs(paramInt2) == paramInt3)) {

if (this.isRed != paramInt1 < 0) {}

}

return validSquare(this.row + paramInt1, this.column + paramInt2);

}

private boolean validSquare(int paramInt1, int paramInt2)

{

return (paramInt1 >= 1) && (paramInt1 <= 8) && (paramInt2 >= 1) && (paramInt2 <= 8) && (paramInt2 % 2 == paramInt1 % 2);

}

}

上面的文件包含以下方法:

Checker(boolean isRed) (constructor) 在一行一列创建一个棋子,如果isRed 是 true, 那么棋子是红色的,否则是白色的。

Checker(boolean isRed, int row, int column) (constructor) 在某行某列创建一个棋子,如果isRed true, 棋子红,否则白。

void move(int rows, int columns) 移动棋子,增加行 到棋子的行,增加列到棋子的列

boolean isRed() 返回true 如果棋子红,否则为false

int getRow, 返回棋子当前的row,

int getRow , 返回棋子当前的column。

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值