Skip to content

Instantly share code, notes, and snippets.

@kingseungil
Last active August 2, 2023 01:26
Show Gist options
  • Save kingseungil/75a13d07d93acc474834fd2f39e4e0e8 to your computer and use it in GitHub Desktop.
Save kingseungil/75a13d07d93acc474834fd2f39e4e0e8 to your computer and use it in GitHub Desktop.
Zerobase-miniproject
import java.util.Scanner;
public class Miniproject3 {
public static void main(String[] args) {
System.out.println("[입장권 계산]");
try (Scanner sc = new Scanner(System.in)) { // try-with-resources 문으로 Scanner 객체 자동 닫기
System.out.print("나이를 입력해 주세요.(숫자):");
int age = sc.nextInt();
System.out.print("입장시간을 입력해 주세요.(숫자입력):");
int time = sc.nextInt();
System.out.print("국가유공자 여부를 입력해 주세요.(y/n):");
String isVeteran = sc.next();
System.out.print("복지카드 여부를 입력해 주세요.(y/n):");
String isWelfare = sc.next();
int price = 0;
final int BASE_PRICE = 10000;
final int NORMAL_DISCOUNT = 8000;
final int SPECIAL_DISCOUNT = 4000;
if(age < 3){
price = 0;
} else if(age < 13 || time >= 17) {
price = SPECIAL_DISCOUNT;
} else if (isVeteran.equalsIgnoreCase("y") || isWelfare.equalsIgnoreCase("y")) {
price = NORMAL_DISCOUNT;
} else {
price = BASE_PRICE;
}
System.out.print("입장료: " + price);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment