qq_36691241 2017-02-16 01:33 采纳率: 29.2%
浏览 787

关于一个Java小项目的问题

package Tetris;

public class TandJProject {

public static void main(String[] args) {
    //创建T对象
    T t = new T(0,1);
    //原始坐标
    System.out.println("t的原始坐标是:");
    t.print();
    //测试T下落
    t.drop();
    System.out.println("下落后的位置是:");
    t.print();
    //测试T左移
    t.leftMove();
    System.out.println("左移后的位置是:");
    t.print();
    //测试T右移
    t.rightMove();
    System.out.println("右移后的位置是:");
    t.print();
    //创建J对象
    J j = new J(0,1);
    System.out.println("原始坐标是:");
    j.print();
    //测试J下落
    j.drop();
    System.out.println("下落后的位置是:");
    j.print();
    //测试J左移
    j.leftMove();
    System.out.println("左移后的位置是:");
    j.print();
    //测试J右移
    j.rightMove();
    System.out.println("右移后的位置是:");

    j.print();
    //创建O对象


}

}
//构建T类
class T {
Cell[] cells;
//无参的构造方法
public T() {
this(0,0);
}
//有参的构造方法
public T(int row,int col) {
cells = new Cell[4];
cells[0] = new Cell(row,col);
cells[1] = new Cell(row,col + 1);
cells[2] = new Cell(row,col + 2);
cells[3] = new Cell(row + 1,col + 1);
}
//打印的方法
public void print() {
String str = "";
for(int i=0;i<=cells.length-1;i++) {
str += "(" + cells[i].getCellInfo() + ")";
}
System.out.println(str);
}
//左移的方法
public void leftMove() {
for(int i=0;i<=cells.length-1;i++) {
cells[i].leftMove();
}
}
//右移的方法
public void rightMove() {
for(int i=0;i<=cells.length-1;i++) {
cells[i].rightMove();
}
}
//下落的方法
public void drop() {
for(int i=0;i<=cells.length-1;i++) {
cells[i].drop();
}
}

}
//构建J类
class J {
Cell[] cells;
//无参的构造方法
public J() {
this(0,0);
}
//有参的构造方法
public J(int row,int col) {
cells = new Cell[4];
cells[0] = new Cell(row,col);
cells[1] = new Cell(row,col + 1);
cells[2] = new Cell(row,col + 2);
cells[3] = new Cell(row + 1,col + 2);
}
//打印的方法
public void print() {
String str = "";
for(int i=0;i<=cells.length-1;i++) {
str += "(" + cells[i].getCellInfo() + ")";
}
System.out.println(str);
}
//左移的方法
public void leftMove() {
for(int i=0;i<=cells.length-1;i++) {
cells[i].leftMove();
}
}
//右移的方法
public void rightMove() {
for(int i=0;i<=cells.length-1;i++) {
cells[i].rightMove();
}
}
//下降的方法
public void drop() {
for(int i=0;i<=cells.length-1;i++) {
cells[i].drop();
}
}
//创建O类
class O {
Cell[] cells;
//定义构造方法
public O() {
this(0,0);
}
//有参的构造方法
public O(int row,int col) {
cells = new Cell[4];
cells[0] = new Cell(row,col);
cells[1] = new Cell(row,col + 1);
cells[2] = new Cell(row + 1,col);
cells[3] = new Cell(row + 1,col + 1);
}
//打印的方法
public void print() {
String str = "";
for(int i=0;i<=cells.length-1;i++) {
str += "(" + cells[i].getCellInfo() + ")";
}
System.out.println(str);
}
//定义下落
public void drop() {
for(int i=0;i<=cells.length-1;i++) {
cells[i].drop();
}
}
//定义左移
public void leftMove() {
for(int i=0;i<=cells.length-1;i++) {
cells[i].leftMove();
}
}
//定义右移
public void rightMove() {
for(int i=0;i<=cells.length-1;i++) {
cells[i].rightMove();
}
}

}
//构建方格
class Cell {
int row;
int col;

public Cell() {
    this(0,0);
}

public Cell(int row,int col) {
    this.row = row;
    this.col = col;
}

public void leftMove() {
    col--;
}

public void rightMove() {
    col++;
}

public void drop() {
    row++;
}

public String getCellInfo() {
    return row + "," + col;
}

}
图片说明
这是错误信息、
错在哪里?错了那又该怎样改正呢?

  • 写回答

5条回答 默认 最新

  • viewgroup 2017-02-16 01:48
    关注

    你把你完整代码贴出来,我手打的没有错误啊。。

    评论

报告相同问题?

悬赏问题

  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误