@Hubertoo
2017-07-17T05:10:05.000000Z
字数 3267
阅读 781
达内
public class Emp{String name;int age;char gender;double salary;public void sayHi(){sysout("I am" + name);}public void print(){...}}
类Emp
package day02;public class Emp {String name;int age;char gender;double salary;public void printInfo(){System.out.println("------------------------");System.out.println("姓名:" + name);System.out.println("年龄:" + age);System.out.println("性别:" + gender);System.out.println("薪水:" + salary);}}
类EmpManager
package day02;public class EmpManager {public static void main(String[] args) {Emp emp = new Emp();emp.name = "白发魔女";emp.age = 21;emp.salary = 8900;emp.printInfo();Emp emp2 = new Emp();emp2.printInfo();}}
package day02;public class Cell {int row;int col;//下落一行public void drop(){row++;}//左移d列public void moveLeft(int d){col -= d;}//获取格子信息public String getCellInfo(){return row + ",,," + col;}}
package day02;public class CellGame {public static void main(String[] args) {//创建Cell对象,并打印Cell cell = new Cell();cell.row = 15;cell.col = 6;printCell(cell);//调用drop方法并打印cell.drop();printCell(cell);}public static void printCell(Cell cell){int totalRow = 20;int totalCol = 10;//打印场地System.out.println("---------------- 分界线 ---------------");System.out.println("Cell的位置是:" + cell.getCellInfo());for(int row = 0; row<totalRow; row++){for(int col = 0; col<totalCol; col++){//满足条件打印*if(cell.row == row && cell.col == col){System.out.print("* ");}else{System.out.print("- ");}}System.out.println();}}}
public void moveRight(){ col++; }Cell类
package day02;public class Cell {int row;int col;//下落一行public void drop(){row++;}//左移一列public void moveLeft(){col --;}//右移一列public void moveRight(){col++;}//获取格子信息public String getCellInfo(){return row + ",,," + col;}}
CellGamePlus类
package day02;import java.util.Scanner;public class CellGamePlus {public static void main(String[] args) {Scanner scan = new Scanner(System.in);//初始化Cell的位置Cell cell = new Cell();cell.row = 2;cell.col = 3;printCell(cell);while(true){System.out.println("请输入你的操作:(1-下落,2-向左,3-向右,0-退出)");int num = scan.nextInt();if(num == 0){System.out.println("游戏结束");break;}else if(num == 1){cell.drop();printCell(cell);}else if(num == 2){cell.moveLeft();printCell(cell);}else if(num == 3){cell.moveRight();printCell(cell);}}}public static void printCell(Cell cell){int totalRow = 20;int totalCol = 10;//打印场地System.out.println("---------------- 分界线 ---------------");System.out.println("Cell的位置是:" + cell.getCellInfo());for(int row = 0; row<totalRow; row++){for(int col = 0; col<totalCol; col++){//满足条件打印*if(cell.row == row && cell.col == col){System.out.print("* ");}else{System.out.print("- ");}}System.out.println();}}}