java程序设计,求邦邦

img

img

Thank my brother.i wan you to help me.
java 谢谢您了
有详细点的讲解吗 ,

两道题的简单实现:
1、五子棋

public class Gobang {

    private Scanner sc = new Scanner(System.in);
    private String[][] locations = new String[15][15]; // 保存每个棋子
    private int p = 1;  // 记录当前轮到白棋=2,黑棋=1

    /* 开始游戏 */
    public void start() {
        initialize();
        printChessboard();
        while (true) {
            printTip();
            String loc = sc.next();
            String[] locs = handleLocation(loc);
            if (locs == null) {
                System.out.println("输入格式不正确,请按照格式(x,y)输入~");
                continue;
            }
            int x = getLocationInt(locs[0]);
            int y = getLocationInt(locs[1]);
            if (x == -1 && y == -1) {
                System.out.println("game over!");
                break;
            }
            if (x < 1 || x > 15 || y < 1 || y > 15) {
                System.out.println("输入坐标有误,请重新输入~");
                continue;
            }
            x -= 1;
            y -= 1;
            if (!"0".equals(locations[x][y])) {
                System.out.println("输入坐标已有棋子,请重新输入~");
                continue;
            }
            // 落下棋子
            if (p == 1) {
                // 黑子
                locations[x][y] = "@";
                printChessboard();
                if (judgeWinOrLose(x, y)) {

                    System.out.println("黑子获胜!");
                    break;
                }
                p = 2;
            } else {
                // 白子
                locations[x][y] = "*";
                printChessboard();
                if (judgeWinOrLose(x, y)) {

                    System.out.println("白子获胜!");
                    break;
                }
                p = 1;
            }
        }
    }

    /* 初始化 */
    public void initialize() {

        for (int i = 0; i < 15; i++) {

            for (int j = 0; j < 15; j++) {

                locations[i][j] = "0";
            }
        }
        //黑子先行
        p = 1;
    }
    /* 输入提示语 */
    public void printTip() {
        if (p == 1) {
            System.out.println("请黑方输入坐标:");
        } else {
            System.out.println("请白方输入坐标:");
        }
    }
    /* 获取x,y坐标 */
    public int getLocationInt(String loc) {
        switch (loc) {
            case "A":
            case "a":
                return 10;
            case "B":
            case "b":
                return 11;
            case "C":
            case "c":
                return 12;
            case "D":
            case "d":
                return 13;
            case "E":
            case "e":
                return 14;
            case "F":
            case "f":
                return 15;
            default:
                return Integer.valueOf(loc);
        }
    }
    /* 处理输入的坐标并处理 */
    public String[] handleLocation(String loc) {
        String[] strArr = loc.split(",");
        if (strArr.length != 2) {
            return null;
        }
        if (strArr[0].trim().length() < 2 || !strArr[0].startsWith("(")) {
            return null;
        }
        strArr[0] = strArr[0].substring(1);
        if (strArr[1].trim().length() < 2 || !strArr[1].endsWith(")")) {
            return null;
        }
        strArr[1] = strArr[1].substring(0, strArr[1].length() - 1);
        return strArr;
    }


    public boolean judgeWinOrLose(int x, int y) {

        String color = locations[x][y]; // 棋子颜色
        int count = 1;  // 相连数
        // 判断横向棋子
        for (int i = 1; i < 5; i++) {
            if (x + i < 15 && color.equals(locations[x + i][y])) { // 右边
                count++;
            }
            if (x - i >= 0 && color.equals(locations[x - i][y])) { // 左边
                count++;
            }
        }
        if (count >= 5) {
            return true;
        }

        // 判断纵向棋子
        count = 1;
        for (int i = 1; i < 5; i++) {
            if (y + i < 15 && color.equals(locations[x][y + i])) { // 下边
                count++;
            }
            if (y - i >= 0 && color.equals(locations[x][y - i])) { // 上边
                count++;
            }
        }
        if (count >= 5) {
            return true;
        }

        //判断斜向棋子(左上右下)
        count = 1;
        for (int i = 1; i < 5; i++) {
            if (x + i < 15 && y + i < 15 && color.equals(locations[x + i][y + i])) { // 右下
                count++;
            }
            if (x - i >= 0 && y - i >= 0 && color.equals(locations[x - i][y - i])) { // 左上
                count++;
            }
        }
        if (count >= 5) {
            return true;
        }

        //判断斜向棋子(左下右上)
        count = 1;
        for (int i = 1; i < 5; i++) {
            if (x + i < 15 && y - i >= 0 && color.equals(locations[x + i][y - i])) { // 右上
                count++;
            }
            if (x - i >= 0 && y + i < 15 && color.equals(locations[x - i][y + i])) { // 左下
                count++;
            }
        }
        if (count >= 5) {
            return true;
        }
        return false;
    }
    /* 输出棋盘 */
    public void printChessboard() {
        for (int i = 0; i < 15; i++) {

            for (int j = 0; j < 15; j++) {

                System.out.print(locations[i][j] + " ");
            }
            System.out.println();
        }
    }
}

2、计算个税

    /* 个税计算 */
    public static double taxCalculate(double income) {
        // 应纳税所得额
        double taxIncome = income - 5000;
        if (taxIncome <= 3000) {

            return taxIncome * 0.03;
        } else if (taxIncome > 3000 && taxIncome <= 12000) {

            return taxIncome * 0.1 - 210;
        } else if (taxIncome > 12000 && taxIncome <= 25000) {

            return taxIncome * 0.2 - 1410;
        } else if (taxIncome > 25000 && taxIncome <= 35000) {

            return taxIncome * 0.25 - 2660;
        } else if (taxIncome > 35000 && taxIncome <= 55000) {

            return taxIncome * 0.3 - 4410;
        } else if (taxIncome > 55000 && taxIncome <= 80000) {

            return taxIncome * 0.35 - 7160;
        } else {

            return taxIncome * 0.45 - 15160;
        }
    }

第一个问题是什么?围棋吗?怎么判断输赢?

这得用到算法