728x90
반응형
🃏랜덤 카드 추출 게임
랜덤으로 카드를 뽑고, 그 카드의 모양과 숫자를 표시하시오.
가로는 100, 세로는 200으로 고정한다.
카드의 모양 = {"heart", "diamond", "clover", "spade"}
카드의 숫자 범위 = 1~13
💾소스코드
public class CardTest {
public static void main(String[] args) {
String arr[] = { "heart", "diamond", "clover", "spade" };
Card arr_card[] = new Card[5];
int num = 0;
int index = 0;
for (int i = 0; i < arr_card.length; i++) {
num = (int) (Math.random() * 13) + 1;
index = (int) (Math.random() * 4);
arr_card[i] = new Card(arr[index], num);
arr_card[i].printCardInfo();
}
}
}
class Card {
String shape;
int number;
int height;
int width;
Card() {
}
Card(String shape, int number, int height, int width) {
this.shape = shape;
this.number = number;
this.height = height;
this.width = width;
}
Card(String shape, int number) {
this(shape,number,200,100);
}
void printCardInfo() {
System.out.println("모양 : " + this.shape + "\t숫자 : " + this.number +
" 가로 : " + this.width + " 세로 : " + this.height);
}
}
728x90
반응형
'Project > Study | etc' 카테고리의 다른 글
Team Project - 계산기 프로그램 (0) | 2022.07.01 |
---|---|
상품 구매 프로그램 (0) | 2022.06.29 |
성적 관리 프로그램 + 설계, 메소드 구현 (0) | 2022.06.28 |
Cat 클래스 만들기 (0) | 2022.06.23 |
성적 관리 프로그램 (0) | 2022.06.23 |
댓글