과거⚰️
영화관좌석예매 || 복권 || 중복금지 ||값교체하기
아무루
2020. 10. 23. 14:44
package day020;
import java.util.Scanner;
public class Day02001영화관좌석예매문제 {
/*
* 영화관 좌석얘먀
* 1.사용자로부터 좌석번호(index)를 입력받아 예매
* 2. 예매가 완료되면 해당 좌석값으 1로 변경
* 2. 이미 예매가 끝난 좌석은 재구매 불가
* 4. 한좌석당 예매 가격은 12000원
* 5. 프로그램 종료 후 해당 영화관의 총 매출액 출력
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] seat = {0, 0, 0, 0, 0, 0, 0};
int x = 0;
int y =0;
int money=0;
int total = 0;
boolean run = true;
while(run) {
for(int i = 0; i<7; i++) {
if(seat[i] == 0) {
System.out.print("[ ]");
}else {
System.out.print("[o]");
}
}
System.out.println();
System.out.println("[그린 영화관]");
System.out.println("1) 좌석예매");
System.out.println("2) 종료");
x = sc.nextInt();
if(x ==1 ) {
System.out.println("좌석 번호 선택");
y= sc.nextInt()-1;
if(seat[y]==0) {
System.out.println("금액을 넣으세요");
money = sc.nextInt();
if(money<12000) {
System.out.println("금액이 부족합니다");
}else if(money>=12000) {
total++;
System.out.println("거스름돈"+(money-12000)+"원");
System.out.println("예매 완료");
seat[y]=1;
}
}else {
System.out.println("예매 불가");
}
}
if(x == 2) {
System.out.println("종료");
System.out.println("영화관 매출액 "+total*12000+" 원");
run = false;
}
}
}
}
package day020;
import java.util.Scanner;
public class Day02002즉석복권 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] lotto = {0,0,7,7,7,0,0,0};
int x = 0;
int y= 0;
boolean run = true;
while(run) {
System.out.println("1)복권결과 확인");
System.out.println("2)종료");
x = sc.nextInt();
if(x==1) {
int c = -1;
for(int i =0; i<6; i++) {
if(lotto[i]==7&&lotto[i+1]==7&&lotto[i+2]==7) {
System.out.println("당첨");
c = 1;
}
if(c== -1) {
System.out.println("꽝");
}
}
}else {
System.out.println("end");
}
}
}
}
package day020;
import java.util.Random;
public class Day02003중복숫자금지 {
public static void main(String[] args) {
/*
* 중복 숫자 금지[1단계]
* 1. 0 ~ 4사이의 숫자를 arr배열에 저장
* 2.단, 중복되는 숫자는 없어야 한다.
* 힌트 랜덤숫자를 check배열의 인덱스로 활용한다.
*/
Random ran = new Random();
int[] check = new int[5];
int[] arr = new int[5];
int x = 0;
while(x<5) {
int r = ran.nextInt(5);
if(check[r]==0) {
arr[x]=r;
check[r]=1;
x++;
}
}
for(int i = 0; i<5; i++) {
System.out.print(arr[i]+" ");
}
}
}
package day020;
import java.util.Scanner;
/*1. 인덱스2개를 입력받아 값 교체하기
* 인덱스1입력 : 1
* 인덱스 2 입력 : 3
* arr = {10, 30, 20, 40 , 50}
*
*/
public class Day02004값교체하기 {
public static void main(String[] args) {
int[] arr= {10, 20, 30, 40, 50};
Scanner sc = new Scanner(System.in);
System.out.println("인덱스입력");
int x = sc.nextInt();
int z = arr[x]; // 30
System.out.println("인덱스입력");
int y= sc.nextInt();//40
arr[x]=arr[y]; // => 40
System.out.print(arr[x]);
arr[y]=z; // 30 = z 10
System.out.println(arr[y]);
for(int i=0; i<5; i++) {
System.out.print(arr[i]+" ");
}
System.out.println();
// 문제 2) 값 2개를 입력받아 값 교체하기
// 예 2)
// 값 입력 : 20, 값 입력 : 40
int value1 = 20;
int value2 = 40;
// 2-1) value1의 위치값 검색
for(int i=0; i<5; i++) {
if(arr[i] == value1) { x = i; }
}
// 2-2) value2의 위치값 검색
for(int i=0; i<5; i++) {
if(arr[i] == value2) { y = i; }
}
// 2-3) 값 교체하기
z = arr[x];
arr[x] = arr[y];
arr[y] = z;
for(int i=0; i<5; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
int[] hakbuns = { 1001, 1002, 1003, 1004, 1005};
int[] scores = {32, 28, 100, 98, 12};
System.out.println("학번 입력");
x = sc.nextInt();
System.out.println("학번 입력");
y= sc.nextInt();
for(int i=0; i<5; i++) {
if(hakbuns[i]==x) {
z = scores[i];
x=i;
}
}
for(int i=0; i<5; i++) {
if(hakbuns[i]==y) {
y = i;
}
}
scores[x] = scores[y];
scores[y] = z;
System.out.println("학번");
for(int i=0; i<5; i++) {
System.out.print(hakbuns[i]+" ");
}
System.out.println();
System.out.println("점수");
for(int i=0; i<5; i++) {
System.out.print(scores[i]+" ");
}
}
}