Codeup 1098_OOP

calis_ws·2023년 5월 9일
0

수업시간에 강사님이 OOP를 이용한 1098문제를 풀이 해주셨다.

import java.util.Arrays;

public class Codeup1098_OOP {
    private int[][] arr;

    public Codeup1098_OOP(boolean printSeparator) {
        this.printSeparator = printSeparator;
    }

    private boolean printSeparator;

    public Codeup1098_OOP(int rowCnt, int colCnt) {
        this.arr = new int[rowCnt][colCnt];
    }

    public Codeup1098_OOP(int[][] arr) {
        this.arr = new int[5][5];
    }

    public void setBeam(int l, int direction, int x, int y) {
        for (int i = 0; i < l; i++) {
            if (direction == 0) {    // 가로
                arr[x - 1][y + i - 1] = 1;
            } else {    // 세로
                arr[x + i - 1][y - 1] = 1;
            }
        }
    }

    public void printArr() {
        for (int i = 0; i < arr.length; i++) {
            System.out.println(Arrays.toString(arr[i]));
        }
        System.out.println("------------------");
    }

    public static void main(String[] args) {
        int rowCnt = 10;
        int colCnt = 10;
        Codeup1098_OOP c1098 = new Codeup1098_OOP(5,5);
        c1098.printArr();
        c1098.setBeam(2, 0, 1, 1);
        c1098.printArr();
        c1098.setBeam(3, 1, 2, 3);
        c1098.printArr();
        c1098.setBeam(4, 1, 2, 5);
        c1098.printArr();
        c1098.setBeam(10, 1, 1, 1);
        c1098.printArr();
    }
}

강사님의 풀이를 보니 내가 못 푼 이유를 알 것 같다. 다시 풀어봐야지 넌 내가 풀고 만다 물론 메소드는 빼고

그나저나 강사님이 이 문제를 메소드를 이용해서 푸는 모습을 보고 처음으로 뻥안치고 멋있다고 생각했다.

간지나는 코딩을 위해선 메소드를 꼭 마스터 해야겠다고 다짐했다.

profile
반갑습니다람지

0개의 댓글