Created
March 6, 2023 16:19
-
-
Save zhyunk/ed36b194fafb856bb9d49a395375c224 to your computer and use it in GitHub Desktop.
과제 3 피드백 반영!
This file contains hidden or 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. 놀이동산 입장권 계산 프로그램] 의 피드백 반영! | |
* | |
* 작성자 : 김지현 | |
* 작성일 : 2023-03-06 | |
* */ | |
public class MiniAssignment03InFeedback { | |
public static void main(String[] args) { | |
// 입력값을 저장할 변수 | |
int age = 0; | |
int ibJangHour = 0; | |
String yuGongJaYN = ""; | |
String bokJiCardYN = ""; | |
// 할인 된 요금 | |
int defaultPrice = 10000; | |
int specialDiscount = 4000; | |
int defaultDiscount = 8000; | |
int ibJangRyo = defaultPrice; | |
MyScanner my = new MyScanner(); | |
System.out.println("[입장권 계산]"); | |
age = my.getScannerReturnInt("나이를 입력해 주세요.(숫자):"); | |
ibJangHour = my.getScannerReturnIntRange("입장시간을 입력해 주세요.(숫자입력):", 0, 24); | |
yuGongJaYN = my.getScannerReturnString("국가유공자 여부를 입력해 주세요.(y/n):", "[Y,y,N,n]"); | |
bokJiCardYN = my.getScannerReturnString("복지카드 여부를 입력해 주세요.(y/n):", "[Y,y,N,n]"); | |
my.close(); | |
if (age < 3) { | |
// 3세 이하 공짜 | |
ibJangRyo = 0; | |
} else if (age < 13 || ibJangHour >= 17) { | |
// 특별할인 조건 : 13세 미만 , 저녁 17시 이후 | |
ibJangRyo = specialDiscount; | |
} else if ("y".equals(bokJiCardYN) || "Y".equals(bokJiCardYN) || "y".equals(yuGongJaYN) || "Y".equals(yuGongJaYN)) { | |
// 일반할인 조건 : 복지카드 . 유공자 카드 할인 | |
ibJangRyo = defaultDiscount; | |
} | |
System.out.println("입장료:" + ibJangRyo); | |
} | |
static class MyScanner { | |
String str; | |
Scanner scan; | |
MyScanner() { | |
scan = new Scanner(System.in); | |
} | |
public int getScannerReturnIntRange(String text, int min, int max) { | |
// min = 최소(포함) 범위 , max = 최대(포함) 범위 | |
str = ""; | |
while (true) { | |
System.out.print(text); | |
str = scan.nextLine(); | |
if (str.replaceAll("[0-9]", "").isEmpty()) { | |
if (Integer.parseInt(str) < max + 1 && Integer.parseInt(str) > min - 1) | |
break; | |
} | |
} | |
return Integer.parseInt(str); | |
} | |
public int getScannerReturnInt(String text) { | |
str = ""; | |
while (true) { | |
System.out.print(text); | |
str = scan.nextLine(); | |
if (!str.replaceAll(" ", "").isEmpty() && str.replaceAll("[0-9]", "").isEmpty()) { | |
break; | |
} | |
} | |
return Integer.parseInt(str); | |
} | |
public String getScannerReturnString(String text, String regex) { | |
// regex = 해당되는 문자를 제거할 정규식, 문자, 문자열 | |
str = ""; | |
while (true) { | |
System.out.print(text); | |
str = scan.nextLine(); | |
if (str.replaceAll(regex, "").isEmpty()) { | |
break; | |
} | |
} | |
return str; | |
} | |
public void close() { | |
scan.close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment