Skip to content

Instantly share code, notes, and snippets.

@minjeCoding
Created February 9, 2025 08:09
Show Gist options
  • Save minjeCoding/3332a3fedc48a1a8b6a261e9dd7432b7 to your computer and use it in GitHub Desktop.
Save minjeCoding/3332a3fedc48a1a8b6a261e9dd7432b7 to your computer and use it in GitHub Desktop.
// 제로베이스 BE_정민제
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int MAX_CASHBACK_AMOUNT = 300;
Scanner scanner = new Scanner(System.in);
String paragraph = String.format(
"[캐시백 계산] %n" +
"결제 금액을 입력해 주세요.(금액): "
);
while (true) {
System.out.print(paragraph);
int purchaseAmount;
int calculatedCashback;
try {
purchaseAmount = scanner.nextInt();
} catch (Exception e) {
scanner.next();
System.out.println("입력값이 정확하지 않습니다. 정수 단위로 입력해주세요.");
continue;
}
calculatedCashback = purchaseAmount / 10;
if (calculatedCashback > MAX_CASHBACK_AMOUNT) {
System.out.printf("결제금액은 %d이고 캐시백은 %d원입니다.%n", purchaseAmount, MAX_CASHBACK_AMOUNT);
return;
} else {
int roundedCashback = (calculatedCashback / 100) * 100;
System.out.printf("결제금액은 %d이고 캐시백은 %d원입니다.%n", purchaseAmount, roundedCashback);
return;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment