Last active
June 7, 2023 06:35
-
-
Save dkwktm45/760f059523daa1267ec34a44a89d8a98 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.Scanner; | |
// 이진영 | |
// 미니과제 3번 문제 | |
public class ZeroReport03 { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
System.out.println("[입장권 계산]"); | |
System.out.print("나이를 입력해 주세요.(숫자 입력):" ); | |
int age = intCheck(sc); | |
System.out.print("입장시간을 입력해 주세요.(숫자 입력):"); | |
int time = intCheck(sc); | |
System.out.print("국가유공자 여부를 입력해 주세요.(y/n):"); | |
String kYn = YnCheck(sc); | |
System.out.print("복지카드 여부를 입력해 주세요.(y/n):"); | |
String cYn = YnCheck(sc); | |
int result; | |
if(age < 3){ | |
result =0; | |
}else{ | |
if(kYn.equals("y") || cYn.equals("y") || time > 17){ | |
result = 2000; | |
}else if(age < 13){ | |
result = 6000; | |
}else{ | |
result = 10000; | |
} | |
} | |
System.out.print("입장료:" + result); | |
} | |
public static int intCheck(Scanner sc){ | |
String num = sc.next(); | |
boolean checkBoolean = false; | |
do{ | |
try { | |
return Integer.parseInt(num); | |
} catch (NumberFormatException ex) { | |
checkBoolean = true; | |
} | |
System.out.print("나이 즉 숫자만을 입력해주시기 바라겠습니다."); | |
num = sc.next(); | |
}while(checkBoolean); | |
return 0; | |
} | |
public static String YnCheck(Scanner sc){ | |
String str = sc.next(); | |
do{ | |
if(str.equals("y") || str.equals("n")){ | |
return str; | |
}else{ | |
System.out.print("동의 여부만을 입력해주세요!(y/n)"); | |
str = sc.next(); | |
} | |
}while(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment