Created
March 6, 2023 16:19
-
-
Save zhyunk/53835611d898bee598810f179d53d09c to your computer and use it in GitHub Desktop.
과제 2 피드백 반영!
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; | |
/* | |
* [과제 2. 결제 금액 캐시백 계산 프로그램] 의 피드백 반영! | |
* | |
* 작성자 : 김지현 | |
* 작성일 : 2023-03-06 | |
* */ | |
public class MiniAssignment02InFeedback { | |
public static void main(String[] args) { | |
int cash, cashBack; | |
MyScanner my; | |
System.out.println("[캐시백 계산]"); | |
my = new MyScanner(); | |
cash = my.getScannerReturnInt("결제 금액을 입력해 주세요.(금액):"); | |
my.close(); | |
cashBack = (int)(cash * 0.1) > 300 ? 300 : (((int)(cash * 0.1) / 100) * 100); | |
System.out.println(String.format("결제 금액은 %d원이고, 캐시백은 %d원 입니다.", cash, cashBack)); | |
} | |
static class MyScanner { | |
Scanner scan; | |
MyScanner() { | |
scan = new Scanner(System.in); | |
} | |
public int getScannerReturnInt(String text) { | |
String str = ""; | |
while (true) { | |
System.out.print(text); | |
str = scan.next(); | |
if (str.replaceAll("[0-9]", "").isEmpty()) { | |
break; | |
} | |
} | |
return Integer.parseInt(str); | |
} | |
public void close() { | |
scan.close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment