Last active
January 5, 2023 14:09
-
-
Save FeelingXD/a487b0b6b549ad0cbd7863eb91ba5cd8 to your computer and use it in GitHub Desktop.
입장권 계산 프로그램
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
작성자: 고지민 | |
*/ | |
//놀이동산 입장권 계산 프로그램 | |
import java.util.*; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
System.out.println("[입장권 계산]"); | |
int age=check_int("나이를 입력해 주세요.(숫자):",input,1); | |
int time=check_int("입장시간을 입력해 주세요.(숫자입력):",input,0,24); | |
boolean merit = check_char("국가유공자 여부를 입력해 주세요.(y/n):",input); | |
boolean hasCard = check_char("복지카드 여부를 입력해 주세요.(y/n):",input); | |
input.close(); | |
System.out.printf("입장료: %d",entry_fee(age,time,merit,hasCard)); | |
} | |
public static int check_int(String message,Scanner input,int min){// 최솟값 제한 | |
int value; | |
try { | |
System.out.print(message); | |
value=input.nextInt(); | |
if(value<min){ | |
throw new Exception(); | |
} | |
return value; | |
}catch (Exception e){ | |
System.out.println("다시입력해 주세요."); | |
return check_int(message, input,min); | |
} | |
} | |
public static int check_int(String message,Scanner input,int min,int max){// min/ max 최소 /최댓값 제한 | |
int value; | |
try { | |
System.out.print(message); | |
value = input.nextInt(); | |
if(value<min||value>max){ | |
throw new Exception(); | |
} | |
return value; | |
}catch (Exception e){ | |
System.out.println("다시입력해 주세요."); | |
return check_int(message, input,min,max); | |
} | |
} | |
public static boolean check_char(String message,Scanner input) {// 입력값 char check | |
char value = ' '; | |
try { | |
System.out.print(message); | |
value=input.next().charAt(0); | |
if(value!='y' && value!='n'){ | |
throw new Exception(); | |
} | |
}catch (Exception e){ | |
System.out.println("다시입력해 주세요."); | |
return check_char(message, input); | |
} | |
return value=='y'? true:false; | |
} | |
public static int entry_fee(int age, int time, boolean service,boolean card){//입장권 | |
int pay= 10000; | |
if (age<3){ | |
pay=0; | |
return pay; | |
} | |
if(time>=17 || age<13){ | |
pay=4000; | |
return pay; | |
} | |
if(service||card){ | |
pay=8000; | |
return pay; | |
} | |
return pay; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment