ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 클래스 omr || 영화관 좌석 || 숫자이동 || 기억력 || 틱택토
    과거⚰️ 2020. 12. 3. 17:20
    package day050;
    
    /*
     * # OMR카드 : 클래스 + 변수
     * 1. 배열 answer는 시험문제의 정답지이다.
     * 2. 배열 hgd에 1~5 사이의 랜덤 숫자 5개를 저장한다.
     * 3. answer와 hgd 값을 비교해 정오표를 출력한다.
     * 4. 한 문제당 20점이다.
     * 예)
     * answer = {1, 3, 4, 2, 5}
     * hgd    = {1, 1, 4, 4, 3}
     * 정오표     = {O, X, O, X, X}
     * 성적        = 40점
     */
    
    import java.util.Random;
    
    class Ex06{
        int[] answer = {1, 3, 4, 2, 5};		// 시험답안
        int[] hgd = new int[5];				// 학생답안
    
        int cnt = 0;						// 정답 맞춘 개수
        int score = 0;						// 성적
    }
    
    public class Day04906클래스OMR문제 {
        public static void main(String[] args) {
            Random ran = new Random();
            Ex06 e = new Ex06();
    
            for (int i=0; i<5; i++){
                e.hgd[i]=ran.nextInt(5)+1;
            }
            for (int i=0; i<5; i++){
                if(e.hgd[i]==e.answer[i]){
                    e.cnt++;
                }
            }
            e.score = e.cnt * 10;
            System.out.println(e.score);
        }
    }
    
    
    package day050;
    
    import java.util.Scanner;
    
    /*
     * # 영화관 좌석예매 : 클래스 + 변수
     * 1. 사용자로부터 좌석번호(index)를 입력받아 예매하는 시스템이다.
     * 2. 예매가 완료되면 해당 좌석 값을 1로 변경한다.
     * 3. 이미 예매가 완료된 좌석은 재구매할 수 없다.
     * 4. 한 좌석당 예매 가격은 12000원이다.
     * 5. 프로그램 종료 후, 해당 영화관의 총 매출액을 출력한다.
     * 예)
     * seat = 0 0 0 0 0 0 0
     *
     * 좌석선택 : 1
     * seat = 0 1 0 0 0 0 0
     *
     * 좌석선택 : 3
     * seat = 0 1 0 1 0 0 0
     *
     * 좌석선택 : 3
     * seat = 0 1 0 1 0 0 0
     * 이미 예매가 완료된 자리입니다.
     * ----------------------
     * 매출액 : 24000원
     */
    
    class Ex07{
        int[] seat = new int[7];
        int money = 0;
    }
    
    public class Day04907클래스영화관좌석예매문제 {
        public static void main(String[] args) {
    
            Scanner scan = new Scanner(System.in);
    
            Ex07 e = new Ex07();
    
            while(true) {
    
                System.out.println("[GREEN MOVIE]");
                System.out.println("[1]좌석예매");
                System.out.println("[2]종료하기");
    
                System.out.print("메뉴 선택 : ");
                int sel = scan.nextInt();
    
                if(sel == 1) {
                    for (int i=0; i<7; i++){
                       if(e.seat[i]==0){
                           System.out.print("[ ]");
                       }
                    }
                    System.out.println("");
                    System.out.println("좌석 선택");
                    int x = scan.nextInt();
                    if(e.seat[x]==0) {
                        e.seat[x] = 1;
                    }else{
                        System.out.println("이미 예매된 좌석입니다.");
                    }
                }
                else if(sel == 2) {
                    break;
                }
            }
    
        }
    }
    
    
    package day050;
    
    /*
     * # 숫자이동[3단계] : 클래스 + 변수
     * 1. 숫자2는 캐릭터이다.
     * 2. 숫자1을 입력하면, 캐릭터가 왼쪽으로
     * 	    숫자2를 입력하면, 캐릭터가 오른쪽으로 이동한다.
     * 3. 숫자 1은 벽이다. 벽을 만나면 이동할 수 없다.
     * 4. 단, 숫자3을 입력하면, 벽을 격파할 수 있다.
     * 5. 좌우 끝에 도달해도 계속 반대편으로 이동이 가능하다.
     * 예)
     *  0 0 0 0 0 0 0 2
     *  왼쪽(1) 오른쪽(2) : 2
     *
     *  2 0 0 0 0 0 0 0
     */
    
    import java.util.Scanner;
    
    class Ex08{
        int[] game = {0, 0, 1, 0, 2, 0, 0, 1, 0};
    }
    
    public class Day04908클래스숫자이동문제 {
        public static void main(String[] args) {
    
            Ex08 e = new Ex08();
            Scanner sc = new Scanner(System.in);
    
            while (true){
                int p1 =0;
                for (int i=0; i<e.game.length; i++){
                    System.out.print(e.game[i]+" ");
                    if(e.game[i]==2){
                        p1 = i;
                    }
                }
                System.out.println();
                System.out.println("1. left   2. right ");
                int dir = sc.nextInt();
                if(dir == 1){
                    if(p1-1 < 0 ){
                        System.out.println("impossible");
                       continue;
                    }
                    if(e.game[p1-1]==0){
                        e.game[p1-1]=2;
                        e.game[p1] = 0;
                        p1 -=1;
                    }else if(e.game[p1-1]==1){
                        System.out.println("wall!!  enter 3 ");
                        int num = sc.nextInt();
                        if(num ==3){
                            e.game[p1-1]=2;
                            e.game[p1] = 0;
                            p1 -=1;
                        }else{
                            System.out.println("retry");
                        }
                    }
                }else if(dir == 2){
                    if(p1+1 < 0 ){
                        System.out.println("impossible");
                        continue;
                    }
                    if(e.game[p1+1]==0){
                        e.game[p1+1]=2;
                        e.game[p1] = 0;
                        p1 +=1;
                    }else if(e.game[p1+1]==1){
                        System.out.println("wall!!  enter 3 ");
                        int num = sc.nextInt();
                        if(num ==3){
                            e.game[p1+1]=2;
                            e.game[p1] = 0;
                            p1 +=1;
                        }else{
                            System.out.println("retry");
                        }
                    }
                }
                else{
                    System.out.println("retry");
                }
            }
        }
    }
    
    
    package day050;
    
    /*
     * # 기억력 게임 : 클래스 + 변수
     * 1. front 배열 카드 10장을 섞는다.
     * 2. front 배열에서 같은 카드를 골라 카드의 위치를 입력한다.
     * 3. 선택한 2장의 카드가 같은 카드이면, back 배열에 표시한다.
     * 4. 모든 카드가 뒤집히면(back배열의 0이 사라지면) 게임은 종료된다.
     */
    
    import java.util.Random;
    import java.util.Scanner;
    
    class Ex09 {
        int[] front = {1, 1, 2, 2, 3, 3, 4, 4, 5, 5};
        int[] back = new int[10];
    
        int cnt = 0;        // 정답을 맞춘 횟수
    }
    
    public class Day04909클래스기억력게임문제 {
        public static void main(String[] args) {
            Random ran = new Random();
            Scanner sc = new Scanner(System.in);
            Ex09 e = new Ex09();
            for (int i = 0; i < 100; i++) {
                int r = ran.nextInt(10);
                int r1 = ran.nextInt(10);
                int tmp = e.front[r];
                e.front[r] = e.front[r1];
                e.front[r1] = tmp;
            }
            int cnt = 0;
            while (true) {
                for (int i = 0; i < e.front.length; i++) {
                    System.out.print(e.front[i] + " ");
                }
                System.out.println();
                for (int i = 0; i < e.front.length; i++) {
                    System.out.print(e.back[i] + " ");
                }
                System.out.println();
                System.out.println("index1 ");
                int index1 = sc.nextInt();
                System.out.println("index2 ");
                int index2 = sc.nextInt();
                index1 -= 1;
                index2 -= 1;
                if (e.front[index1] == e.front[index2]) {
                    e.back[cnt] = e.front[index1];
                    e.back[cnt + 1] = e.front[index2];
                    cnt += 2;
                }else{
                    System.out.println("retry");
                }
            }
        }
    }
    
    
    
    package day050;
    
    /*
     * # 틱택토
     * === 틱택토 ===
     * [X][X][O]
     * [ ][O][ ]
     * [ ][ ][ ]
     * [p1]인덱스 입력 : 6
     * === 틱택토 ===
     * [X][X][O]
     * [ ][O][ ]
     * [O][ ][ ]
     * [p1]승리
     *
     */
    
    import java.util.Scanner;
    
    class Ex10 {
        String[][] game = new String[3][3];
    
        int turn = 0;
        int win = 0;
    }
    
    public class Day04910클래스틱택토문제 {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            Ex10 e = new Ex10();
            for (int i = 0; i < e.game.length; i++) {
                for (int j = 0; j < e.game[i].length; j++) {
                    e.game[i][j] = "[ ]";
                }
            }
            while (true) {
                for (int i = 0; i < e.game.length; i++) {
                    for (int j = 0; j < e.game[i].length; j++) {
                        System.out.print(e.game[i][j] + " ");
                    }
                    System.out.println();
                }
                if(e.win==1){
                    System.out.println("p1 win");
                    break;
                }else if(e.win==2){
                    System.out.println("p2 win");
                    break;
                }else if(e.turn==9&&e.win==0){
                    System.out.println("draw");
                    break;
                }
                if (e.turn % 2 == 0) {
                    System.out.println("y : ");
                    int y = sc.nextInt();
                    System.out.println("x : ");
                    int x = sc.nextInt();
                    if(e.game[y][x].equals("[ ]")){
                       e.game[y][x] = "[o]";
                       e.turn++;
                    }else {
                        System.out.println("retry");
                    }
                } else {
                    System.out.println("y : ");
                    int y = sc.nextInt();
                    System.out.println("x : ");
                    int x = sc.nextInt();
                    if(e.game[y][x].equals("[ ]")) {
                        e.game[y][x] = "[x]";
                        e.turn++;
                    }else {
                        System.out.println("retry");
                    }
                }
    
                for(int i=0; i<e.game.length; i++) {
                    if(e.game[i][0].equals("[O]") && e.game[i][1].equals("[O]") && e.game[i][2].equals("[O]")) {
                        e.win = 1;
                    }
                    if(e.game[i][0].equals("[X]") && e.game[i][1].equals("[X]") && e.game[i][2].equals("[X]")) {
                        e.win = 2;
                    }
                }
    
                for(int i=0; i<e.game.length; i++) {
                    if(e.game[0][i].equals("[O]") && e.game[1][i].equals("[O]") && e.game[2][i].equals("[O]")) {
                        e.win = 1;
                    }
                    if(e.game[0][i].equals("[X]") && e.game[1][i].equals("[X]") && e.game[2][i].equals("[X]")) {
                        e.win = 2;
                    }
                }
    
                if(e.game[0][0].equals("[O]") && e.game[1][1].equals("[O]") && e.game[2][2].equals("[O]")) {
                    e.win = 1;
                }
                if(e.game[0][0].equals("[X]") && e.game[1][1].equals("[X]") && e.game[2][2].equals("[X]")) {
                    e.win = 2;
                }
    
                if(e.game[0][2].equals("[O]") && e.game[1][1].equals("[O]") && e.game[2][0].equals("[O]")) {
                    e.win = 1;
                }
                if(e.game[0][2].equals("[X]") && e.game[1][1].equals("[X]") && e.game[2][0].equals("[X]")) {
                    e.win = 2;
                }
    
            }
        }
    }

    '과거⚰️' 카테고리의 다른 글

    css 선택자  (0) 2020.12.05
    클래스 1 to 50 || 사다리 || 더하기  (0) 2020.12.04
    클래스 문제  (0) 2020.12.02
    클래스 이론  (0) 2020.12.01
    숫자이동 되감기 || 학생정보 || 합구하기 1 2  (0) 2020.11.30
Designed by Tistory.