From ffb32c380ca82af169f9fe73debf943ae7ab3525 Mon Sep 17 00:00:00 2001 From: arinming Date: Thu, 8 Feb 2024 16:17:00 +0900 Subject: [PATCH] =?UTF-8?q?[Week3][Chap12]=20=EB=AC=B8=EC=A0=9C=EC=99=80?= =?UTF-8?q?=20=ED=92=80=EC=9D=B4=20(#27)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inspectionProfiles/Project_Default.xml" | 10 +++++++ .../src/poly/ex/pay0/KakaoPay.java" | 10 +++++++ .../src/poly/ex/pay0/NaverPay.java" | 10 +++++++ .../src/poly/ex/pay0/PayMain0.java" | 19 ++++++++++++++ .../src/poly/ex/pay0/PayService.java" | 22 ++++++++++++++++ .../src/poly/ex/pay1/DefaultPay.java" | 9 +++++++ .../src/poly/ex/pay1/KakaoPay.java" | 11 ++++++++ .../src/poly/ex/pay1/NaverPay.java" | 11 ++++++++ .../java-basic/src/poly/ex/pay1/NewPay.java" | 10 +++++++ .../java-basic/src/poly/ex/pay1/Pay.java" | 5 ++++ .../src/poly/ex/pay1/PayMain1.java" | 24 +++++++++++++++++ .../src/poly/ex/pay1/PayMain2.java" | 26 +++++++++++++++++++ .../src/poly/ex/pay1/PayService.java" | 20 ++++++++++++++ .../src/poly/ex/pay1/PayStore.java" | 17 ++++++++++++ .../src/poly/ex/sender/EmailSender.java" | 9 +++++++ .../src/poly/ex/sender/FaceBookSender.java" | 9 +++++++ .../src/poly/ex/sender/SendMain.java" | 10 +++++++ .../src/poly/ex/sender/Sender.java" | 5 ++++ .../src/poly/ex/sender/SmsSender.java" | 9 +++++++ 19 files changed, 246 insertions(+) create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/.idea/inspectionProfiles/Project_Default.xml" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay0/KakaoPay.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay0/NaverPay.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay0/PayMain0.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay0/PayService.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/DefaultPay.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/KakaoPay.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/NaverPay.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/NewPay.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/Pay.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/PayMain1.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/PayMain2.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/PayService.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/PayStore.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/EmailSender.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/FaceBookSender.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/SendMain.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/Sender.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/SmsSender.java" diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/.idea/inspectionProfiles/Project_Default.xml" "b/\352\271\200\354\225\204\353\246\260/java-basic/.idea/inspectionProfiles/Project_Default.xml" new file mode 100644 index 0000000..5993e43 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/.idea/inspectionProfiles/Project_Default.xml" @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay0/KakaoPay.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay0/KakaoPay.java" new file mode 100644 index 0000000..cfd3912 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay0/KakaoPay.java" @@ -0,0 +1,10 @@ +package poly.ex.pay0; + +public class KakaoPay { + + public boolean pay(int amount) { + System.out.println("카카오페이 시스템과 연결합니다."); + System.out.println(amount + "원 결제를 시도합니다."); + return true; + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay0/NaverPay.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay0/NaverPay.java" new file mode 100644 index 0000000..c577b7b --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay0/NaverPay.java" @@ -0,0 +1,10 @@ +package poly.ex.pay0; + +public class NaverPay { + + public boolean pay(int amount) { + System.out.println("네이버페이 시스템과 연결합니다."); + System.out.println(amount + "원 결제를 시도합니다."); + return true; + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay0/PayMain0.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay0/PayMain0.java" new file mode 100644 index 0000000..4effdd8 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay0/PayMain0.java" @@ -0,0 +1,19 @@ +package poly.ex.pay0; + +public class PayMain0 { + public static void main(String[] args) { + PayService payService = new PayService(); + + String payOption1 = "kakao"; + int amount1 = 5000; + payService.processPay(payOption1, amount1); + + String payOption2 = "naver"; + int amount2 = 10000; + payService.processPay(payOption2, amount2); + + String payOption3 = "bad"; + int amount3 = 15000; + payService.processPay(payOption3, amount3); + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay0/PayService.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay0/PayService.java" new file mode 100644 index 0000000..a497bf6 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay0/PayService.java" @@ -0,0 +1,22 @@ +package poly.ex.pay0; + +public class PayService { + public void processPay(String option, int amount) { + boolean result; + System.out.println("결제를 시작합니다: option=" + option + ", amount=" + amount); + if (option.equals("kakao")) { + KakaoPay kakaoPay = new KakaoPay(); + result = kakaoPay.pay(amount); + } else if (option.equals("naver")) { + NaverPay naverPay = new NaverPay(); + result = naverPay.pay(amount); + } else { + System.out.println("결제 수단이 없습니다."); result = false; + } + if (result) { + System.out.println("결제가 성공했습니다."); + } else { + System.out.println("결제가 실패했습니다."); + } + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/DefaultPay.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/DefaultPay.java" new file mode 100644 index 0000000..cf8769b --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/DefaultPay.java" @@ -0,0 +1,9 @@ +package poly.ex.pay1; + +public class DefaultPay implements Pay{ + @Override + public boolean pay(int amount) { + System.out.println("결제 수단이 없습니다."); + return false; + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/KakaoPay.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/KakaoPay.java" new file mode 100644 index 0000000..f8e7924 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/KakaoPay.java" @@ -0,0 +1,11 @@ +package poly.ex.pay1; + +public class KakaoPay implements Pay { + + @Override + public boolean pay(int amount) { + System.out.println("카카오페이 시스템과 연결합니다."); + System.out.println(amount + "원 결제를 시도합니다."); + return true; + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/NaverPay.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/NaverPay.java" new file mode 100644 index 0000000..b689169 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/NaverPay.java" @@ -0,0 +1,11 @@ +package poly.ex.pay1; + +public class NaverPay implements Pay { + + @Override + public boolean pay(int amount) { + System.out.println("네이버페이 시스템과 연결합니다."); + System.out.println(amount + "원 결제를 시도합니다."); + return true; + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/NewPay.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/NewPay.java" new file mode 100644 index 0000000..2dacc55 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/NewPay.java" @@ -0,0 +1,10 @@ +package poly.ex.pay1; + +public class NewPay implements Pay { + @Override + public boolean pay(int amount) { + System.out.println("NewPay 시스템과 연결합니다."); + System.out.println(amount + "원 결제를 시도합니다."); + return true; + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/Pay.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/Pay.java" new file mode 100644 index 0000000..19153fc --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/Pay.java" @@ -0,0 +1,5 @@ +package poly.ex.pay1; + +public interface Pay { + boolean pay(int amount); +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/PayMain1.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/PayMain1.java" new file mode 100644 index 0000000..570f626 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/PayMain1.java" @@ -0,0 +1,24 @@ +package poly.ex.pay1; + +public class PayMain1 { + public static void main(String[] args) { + PayService payService = new PayService(); + + String payOption1 = "kakao"; + int amount1 = 5000; + payService.processPay(payOption1, amount1); + + String payOption2 = "naver"; + int amount2 = 10000; + payService.processPay(payOption2, amount2); + + String payOption3 = "bad"; + int amount3 = 15000; + payService.processPay(payOption3, amount3); + + String payOption4 = "new"; + int amount4 = 10000; + payService.processPay(payOption4, amount4); + + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/PayMain2.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/PayMain2.java" new file mode 100644 index 0000000..86f66bd --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/PayMain2.java" @@ -0,0 +1,26 @@ +package poly.ex.pay1; + +import java.util.Scanner; + +public class PayMain2 { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + PayService payService = new PayService(); + + while (true) { + System.out.println("결제 수단을 입력하세요."); + String payOption = scanner.nextLine(); + + if (payOption.equals("exit")) { + System.out.println("프로그램을 종료합니다."); + return; + } + + System.out.println("결제 금액을 입력하세요"); + int amount = scanner.nextInt(); + scanner.nextLine(); + + payService.processPay(payOption, amount); + } + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/PayService.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/PayService.java" new file mode 100644 index 0000000..2cbd288 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/PayService.java" @@ -0,0 +1,20 @@ +package poly.ex.pay1; + +public class PayService { + + // 변하지 않는 부분 + public void processPay(String option, int amount) { + + System.out.println("결제를 시작합니다: option=" + option + ", amount=" + amount); + + Pay pay = PayStore.findPay(option); + boolean result = pay.pay(amount); + + + if (result) { + System.out.println("결제가 성공했습니다."); + } else { + System.out.println("결제가 실패했습니다."); + } + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/PayStore.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/PayStore.java" new file mode 100644 index 0000000..df78ad4 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/pay1/PayStore.java" @@ -0,0 +1,17 @@ +package poly.ex.pay1; + +public abstract class PayStore { + + // 변하는 부 + public static Pay findPay(String option) { + if (option.equals("kakao")) { + return new KakaoPay(); + } else if (option.equals("naver")) { + return new NaverPay(); + } else if(option.equals("new")) { + return new NewPay(); + } else { + return new DefaultPay(); + } + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/EmailSender.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/EmailSender.java" new file mode 100644 index 0000000..52d05ee --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/EmailSender.java" @@ -0,0 +1,9 @@ +package poly.ex.sender; + +public class EmailSender implements Sender{ + + @Override + public void sendMessage(String message) { + System.out.println("메일을 발송합니다 : " + message); + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/FaceBookSender.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/FaceBookSender.java" new file mode 100644 index 0000000..512b76a --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/FaceBookSender.java" @@ -0,0 +1,9 @@ +package poly.ex.sender; + +public class FaceBookSender implements Sender{ + + @Override + public void sendMessage(String message) { + System.out.println("페이스북에 발송합니다 : " + message); + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/SendMain.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/SendMain.java" new file mode 100644 index 0000000..4551a97 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/SendMain.java" @@ -0,0 +1,10 @@ +package poly.ex.sender; + +public class SendMain { + public static void main(String[] args) { + Sender[] senders = {new EmailSender(), new SmsSender(), new FaceBookSender()}; + for (Sender sender : senders) { + sender.sendMessage("환영합니다!"); + } + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/Sender.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/Sender.java" new file mode 100644 index 0000000..25a21c5 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/Sender.java" @@ -0,0 +1,5 @@ +package poly.ex.sender; + +public interface Sender { + void sendMessage(String message); +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/SmsSender.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/SmsSender.java" new file mode 100644 index 0000000..cc204ae --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/ex/sender/SmsSender.java" @@ -0,0 +1,9 @@ +package poly.ex.sender; + +public class SmsSender implements Sender{ + + @Override + public void sendMessage(String message) { + System.out.println("SMS를 발송합니다 : " + message); + } +}