From ea2bede883ba08c58bbb6179240811da3021dd40 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Fri, 7 Oct 2022 11:09:57 +0900 Subject: [PATCH 001/307] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=EC=9D=BD=EA=B8=B0=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=AA=A8=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_07/Project/PopulationMethod.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 git/Lion-Java/src/Date10_07/Project/PopulationMethod.java diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java new file mode 100644 index 0000000..1e8f02b --- /dev/null +++ b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java @@ -0,0 +1,68 @@ +package Date10_07.Project; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +public class PopulationMethod { + static String address = "C:\\Users\\qowhx\\OneDrive\\바탕 화면\\인구\\2021_인구관련연간자료_20221006_47106.csv"; + + + public static void ReadByChar() throws IOException { // 1글자씩 읽기 + FileReader fileReader = new FileReader(address); + + String fileContents =""; + while(fileContents.length()<1_000_000) { + char c = (char) fileReader.read(); // read()는 반환을 int형으로 하기 때문에 형변환이 필요 + fileContents += c; + System.out.println(fileContents); + } + System.out.println(fileContents); + } + + public static String ReadByOneLine() throws IOException{ // 1줄 읽기 + BufferedReader reader = new BufferedReader( + new FileReader(address) + ); + String str = reader.readLine(); + reader.close(); + return str; + } + + public static void ReadByLine() throws IOException{ // 1줄씩 전부 읽기 + BufferedReader reader = new BufferedReader( + new FileReader(address) + ); + String str; + while ((str = reader.readLine()) != null) { + System.out.println(str); + } + reader.close(); + } + + public static void ReadByLine2() { // 1줄씩 전부 읽기 (2) + try (BufferedReader br = Files.newBufferedReader( + Paths.get(address), StandardCharsets.UTF_8)) { + String line; + while ((line = br.readLine()) != null) { + System.out.println(line); + } + } catch (IOException ex) { + throw new RuntimeException(ex); + } + } + + public static PopulationMove parse(String data) throws IOException { // 원하는 값 추출 + + String[] str = data.split(","); + int FromSido = Integer.parseInt(str[0]); + int ToSido = Integer.parseInt(str[6]); + + return new PopulationMove(FromSido,ToSido); + } +} From 4639a661e6778d75d284ee232957d996c6f95b60 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Fri, 7 Oct 2022 11:10:19 +0900 Subject: [PATCH 002/307] FileReadMain --- .../Project/PopulationStatistics.java | 74 ++----------------- 1 file changed, 5 insertions(+), 69 deletions(-) diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationStatistics.java b/git/Lion-Java/src/Date10_07/Project/PopulationStatistics.java index 2e48637..0efb2f5 100644 --- a/git/Lion-Java/src/Date10_07/Project/PopulationStatistics.java +++ b/git/Lion-Java/src/Date10_07/Project/PopulationStatistics.java @@ -1,77 +1,13 @@ package Date10_07.Project; - - -import java.io.BufferedReader; -import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; public class PopulationStatistics { - - static String address = "C:\\Users\\qowhx\\OneDrive\\바탕 화면\\인구\\2021_인구관련연간자료_20221006_47106.csv"; - - - public static void ReadByChar() throws IOException{ // 1글자씩 읽기 - FileReader fileReader = new FileReader(address); - - String fileContents =""; - while(fileContents.length()<1_000_000) { - char c = (char) fileReader.read(); // read()는 반환을 int형으로 하기 때문에 형변환이 필요 - fileContents += c; - System.out.println(fileContents); - } - System.out.println(fileContents); - } - - public static String ReadByOneLine() throws IOException{ // 1줄 읽기 - BufferedReader reader = new BufferedReader( - new FileReader(address) - ); - String str = reader.readLine(); - reader.close(); - return str; - } - - public static void ReadByLine() throws IOException{ // 1줄씩 전부 읽기 - BufferedReader reader = new BufferedReader( - new FileReader(address) - ); - String str; - while ((str = reader.readLine()) != null) { - System.out.println(str); - } - reader.close(); - } - - public static void ReadByLine2() { // 1줄씩 전부 읽기 (2) - try (BufferedReader br = Files.newBufferedReader( - Paths.get(address), StandardCharsets.UTF_8)) { - String line; - while ((line = br.readLine()) != null) { - System.out.println(line); - } - } catch (IOException ex) { - throw new RuntimeException(ex); - } - } - - public static PopulationMove parse(String data) throws IOException { - String[] str = data.split(","); - int FromSido = Integer.parseInt(str[0]); - int ToSido = Integer.parseInt(str[6]); - - return new PopulationMove(FromSido,ToSido); - } - public static void main(String[] args) throws IOException { - // ReadByChar(); - // ReadByLine(); - // ReadByLine2(); - System.out.println(parse(ReadByOneLine())); + PopulationMethod method = new PopulationMethod(); + // method.ReadByChar(); + // method.ReadByLine(); + // method.ReadByLine2(); + System.out.println(method.parse(method.ReadByOneLine())); } } From b7668fc608571dbb08fb20f2cfe42d6142cdf9d3 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Fri, 7 Oct 2022 11:11:03 +0900 Subject: [PATCH 003/307] File parse/Mapping --- .../src/Date10_07/Project/PopulationMove.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationMove.java b/git/Lion-Java/src/Date10_07/Project/PopulationMove.java index de2caa0..640c7c9 100644 --- a/git/Lion-Java/src/Date10_07/Project/PopulationMove.java +++ b/git/Lion-Java/src/Date10_07/Project/PopulationMove.java @@ -5,6 +5,9 @@ 3. 이사하기 전 도시와 이사하고 난 후 도시의 값만 가져온다 */ +import java.util.HashMap; +import java.util.Map; + public class PopulationMove { private int fromSido; private int toSido; @@ -26,8 +29,31 @@ public int getToSido() { return toSido; } + public String Mapping(int num){ + + Map map = new HashMap<>(); + map.put(11,"서울"); + map.put(21,"부산"); + map.put(22,"대구"); + map.put(23,"인천"); + map.put(24,"광주"); + map.put(25,"대전"); + map.put(26,"울산"); + map.put(29,"세종"); + map.put(31,"경기도"); + map.put(32,"강원도"); + map.put(33,"충북"); + map.put(34,"충남"); + map.put(35,"전북"); + map.put(36,"전남"); + map.put(37,"경북"); + map.put(38,"경남"); + map.put(39,"제주"); + + return map.get(num); + } @Override public String toString() { - return fromSido+"에서 "+toSido+"로 이사갔습니다."; + return Mapping(fromSido)+"에서 "+Mapping(toSido)+"로 이사갔습니다."; } } From bdcf37bb713e2d0f574788da2eeda57e8863dd9d Mon Sep 17 00:00:00 2001 From: qowl880 Date: Fri, 7 Oct 2022 11:12:53 +0900 Subject: [PATCH 004/307] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EB=AA=A8=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_07/Project/PopulationMethod.java | 1 + 1 file changed, 1 insertion(+) diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java index 1e8f02b..6d56bd3 100644 --- a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java +++ b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java @@ -57,6 +57,7 @@ public static void ReadByLine2() { // 1줄씩 전부 읽기 } } + public static PopulationMove parse(String data) throws IOException { // 원하는 값 추출 String[] str = data.split(","); From e3cbe4cba6685e40101ceecbeb2dc22adbc5154e Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Fri, 7 Oct 2022 11:16:57 +0900 Subject: [PATCH 005/307] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EB=AA=A8=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_07/Project/PopulationMethod.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java index 1e8f02b..496d41d 100644 --- a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java +++ b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java @@ -10,7 +10,7 @@ import java.util.Map; public class PopulationMethod { - static String address = "C:\\Users\\qowhx\\OneDrive\\바탕 화면\\인구\\2021_인구관련연간자료_20221006_47106.csv"; + static String address = "파일위치"; public static void ReadByChar() throws IOException { // 1글자씩 읽기 From 53b055a17b8583da8e648d6d436edd82d12c03ea Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Fri, 7 Oct 2022 11:25:38 +0900 Subject: [PATCH 006/307] Update README.md --- README.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4c8a22f..e28acdd 100644 --- a/README.md +++ b/README.md @@ -1 +1,25 @@ -# 자바 공부 +### 🦁 멋쟁이사자처럼 백엔드 + +# 🗓 공부 일정 +- 2022-10-04 : Git + 알고리즘 + https://velog.io/@qowl880/%EB%A9%8B%EC%9F%81%EC%9D%B4%EC%82%AC%EC%9E%90%EC%B2%98%EB%9F%BC-%EB%B0%B1%EC%97%94%EB%93%9C-11%EC%9D%BC%EC%B0%A8 + +- 2022-10-05 : Intellij Git 사용 + 자바란? + interface 의존성과 다형성을 통한 예제 문제 + https://velog.io/@qowl880/%EB%A9%8B%EC%9F%81%EC%9D%B4%EC%82%AC%EC%9E%90%EC%B2%98%EB%9F%BC-%EB%B0%B1%EC%97%94%EB%93%9C-12%EC%9D%BC%EC%B0%A8 + +- 2022-10-06 : List/Set/Map + File(파일 입출력) + https://velog.io/@qowl880/%EB%A9%8B%EC%9F%81%EC%9D%B4%EC%82%AC%EC%9E%90%EC%B2%98%EB%9F%BC-%EB%B0%B1%EC%97%94%EB%93%9C-13%EC%9D%BC%EC%B0%A8 + +- 2022-10-07 : Project(대용량데이터처리) + +
+ +# ⚙️ 기술 스택 +
+ Java +
+ +
+ +## ☁️ 프로젝트 주요 기능 + From 91c2310cbfaba1dc72293a4a2d6ac8e39de088e7 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Fri, 7 Oct 2022 11:26:12 +0900 Subject: [PATCH 007/307] Update README.md --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index e28acdd..f041cee 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,10 @@ # 🗓 공부 일정 - 2022-10-04 : Git + 알고리즘 - https://velog.io/@qowl880/%EB%A9%8B%EC%9F%81%EC%9D%B4%EC%82%AC%EC%9E%90%EC%B2%98%EB%9F%BC-%EB%B0%B1%EC%97%94%EB%93%9C-11%EC%9D%BC%EC%B0%A8 - 2022-10-05 : Intellij Git 사용 + 자바란? + interface 의존성과 다형성을 통한 예제 문제 - https://velog.io/@qowl880/%EB%A9%8B%EC%9F%81%EC%9D%B4%EC%82%AC%EC%9E%90%EC%B2%98%EB%9F%BC-%EB%B0%B1%EC%97%94%EB%93%9C-12%EC%9D%BC%EC%B0%A8 - 2022-10-06 : List/Set/Map + File(파일 입출력) - https://velog.io/@qowl880/%EB%A9%8B%EC%9F%81%EC%9D%B4%EC%82%AC%EC%9E%90%EC%B2%98%EB%9F%BC-%EB%B0%B1%EC%97%94%EB%93%9C-13%EC%9D%BC%EC%B0%A8 - 2022-10-07 : Project(대용량데이터처리) From 0ee810932c3ddfb58b1ff344a86e109b0c92f543 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Fri, 7 Oct 2022 13:23:30 +0900 Subject: [PATCH 008/307] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EB=AA=A8=EC=9D=8C(=ED=8C=8C=EC=9D=BC=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1,=20=ED=8C=8C=EC=9D=BC=20=EC=93=B0=EA=B8=B0=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_07/Project/PopulationMethod.java | 49 ++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java index 6d56bd3..bb8c1f8 100644 --- a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java +++ b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java @@ -1,18 +1,16 @@ package Date10_07.Project; -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; +import java.io.*; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; +import java.util.ArrayList; +import java.util.List; public class PopulationMethod { static String address = "C:\\Users\\qowhx\\OneDrive\\바탕 화면\\인구\\2021_인구관련연간자료_20221006_47106.csv"; - + static String saveaddress = "C:\\Users\\qowhx\\AppData\\Roaming\\SPB_Data\\git\\Java-Study\\file.txt"; public static void ReadByChar() throws IOException { // 1글자씩 읽기 FileReader fileReader = new FileReader(address); @@ -66,4 +64,43 @@ public static PopulationMove parse(String data) throws IOException { // return new PopulationMove(FromSido,ToSido); } + + public static List ReadByLineParse() throws IOException{ // 1줄씩 전부 읽어서 파싱하기 + List pml = new ArrayList<>(); // PopulationMove arraylist 객체 초기화 + BufferedReader reader = new BufferedReader( + new FileReader(address) + ); + String str; + while ((str = reader.readLine()) != null) { // 파일의 마지막 데이터까지 반복 + PopulationMove pm = parse(str); // pm 참조변수에 parse(한줄 읽기)값 저장 + pml.add(pm); // 리스트에 pm 값 저장 + } + reader.close(); + return pml; // 리스트 출력 + } + + public void CreateFile(){ // 파일 생성 + File file = new File(saveaddress); + try{ + System.out.println("파일 생성"); + file.createNewFile(); + }catch (IOException e){ + System.out.println("파일 생성 못함"); + throw new RuntimeException(); + } + } + + public void Filewrite(Liststrs){ + File file = new File(saveaddress); + + try{ + BufferedWriter writer = new BufferedWriter(new FileWriter(file)); + for(PopulationMove str:strs){ + writer.write(String.valueOf(str)+"\n"); + } + writer.close(); + }catch (IOException e){ + e.printStackTrace(); + } + } } From eefef2bcafa0d857e32e41eac1df44dafcc22b91 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Fri, 7 Oct 2022 13:23:41 +0900 Subject: [PATCH 009/307] FileReadMain --- .../src/Date10_07/Project/PopulationStatistics.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationStatistics.java b/git/Lion-Java/src/Date10_07/Project/PopulationStatistics.java index 0efb2f5..7f72fa3 100644 --- a/git/Lion-Java/src/Date10_07/Project/PopulationStatistics.java +++ b/git/Lion-Java/src/Date10_07/Project/PopulationStatistics.java @@ -1,13 +1,18 @@ package Date10_07.Project; import java.io.IOException; +import java.util.List; public class PopulationStatistics { public static void main(String[] args) throws IOException { PopulationMethod method = new PopulationMethod(); - // method.ReadByChar(); - // method.ReadByLine(); - // method.ReadByLine2(); - System.out.println(method.parse(method.ReadByOneLine())); + // method.ReadByChar(); // 파일 한글자씩 읽기 + // method.ReadByLine(); // 파일 한줄씩 읽기 + // method.ReadByLine2(); // 파일 한줄씩 읽기(2) + // System.out.println(method.parse(method.ReadByOneLine())); // 파일 한줄만 읽어서 파싱 후 한글로 Mapping + // System.out.println(method.ReadByLineParse()); + + method.CreateFile(); + method.Filewrite(method.ReadByLineParse()); } } From 6651d06f6512170aceac94f85bfbbe86d00f876c Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Fri, 7 Oct 2022 13:25:59 +0900 Subject: [PATCH 010/307] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EB=AA=A8=EC=9D=8C(=ED=8C=8C=EC=9D=BC=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1,=20=ED=8C=8C=EC=9D=BC=20=EC=9E=91=EC=84=B1=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_07/Project/PopulationMethod.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java index 611fcf9..3325376 100644 --- a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java +++ b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java @@ -78,7 +78,7 @@ public static List ReadByLineParse() throws IOException{ reader.close(); return pml; // 리스트 출력 } - + public void CreateFile(){ // 파일 생성 File file = new File(saveaddress); try{ From c6300164fb4d8c5588b6af998cd4aa8bc70ecbf1 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Fri, 7 Oct 2022 13:31:00 +0900 Subject: [PATCH 011/307] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EB=AA=A8=EC=9D=8C(=ED=8C=8C=EC=9D=BC=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1,=20=EC=9E=91=EC=84=B1=20=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_07/Project/PopulationMethod.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java index 611fcf9..9063d9a 100644 --- a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java +++ b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java @@ -8,7 +8,7 @@ import java.util.List; public class PopulationMethod { - static String address = "파일위치"; + static String address = "C:\\Users\\qowhx\\OneDrive\\바탕 화면\\인구\\2021_인구관련연간자료_20221006_47106.csv"; static String saveaddress = "C:\\Users\\qowhx\\AppData\\Roaming\\SPB_Data\\git\\Java-Study\\file.txt"; public static void ReadByChar() throws IOException { // 1글자씩 읽기 @@ -80,7 +80,7 @@ public static List ReadByLineParse() throws IOException{ } public void CreateFile(){ // 파일 생성 - File file = new File(saveaddress); + File file = new File(saveaddress); // 파일 생성 위치및 파일 이름 try{ System.out.println("파일 생성"); file.createNewFile(); @@ -90,13 +90,13 @@ public void CreateFile(){ // 파일 생성 } } - public void Filewrite(Liststrs){ - File file = new File(saveaddress); + public void Filewrite(Liststrs){ // 파일 작성 + File file = new File(saveaddress); try{ BufferedWriter writer = new BufferedWriter(new FileWriter(file)); - for(PopulationMove str:strs){ - writer.write(String.valueOf(str)+"\n"); + for(PopulationMove str:strs){ // 매개변수로 받은 리스트만큼 반복 + writer.write(String.valueOf(str)+"\n"); // 매개변수로 받은 리스트의 값+"\n" 으로 파일에 작성 } writer.close(); }catch (IOException e){ From 2b7b13016fbbcd966878ad8f012b48b63a2d8b62 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Fri, 7 Oct 2022 13:31:45 +0900 Subject: [PATCH 012/307] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EB=AA=A8=EC=9D=8C(=ED=8C=8C=EC=9D=BC=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1,=20=EC=9E=91=EC=84=B1=20=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_07/Project/PopulationMethod.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java index 5098bed..37ca09e 100644 --- a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java +++ b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java @@ -8,9 +8,9 @@ import java.util.List; public class PopulationMethod { - static String address = "C:\\Users\\qowhx\\OneDrive\\바탕 화면\\인구\\2021_인구관련연간자료_20221006_47106.csv"; + static String address = "파일 저장 위치"; - static String saveaddress = "C:\\Users\\qowhx\\AppData\\Roaming\\SPB_Data\\git\\Java-Study\\file.txt"; + static String saveaddress = "파일 생성 "; public static void ReadByChar() throws IOException { // 1글자씩 읽기 FileReader fileReader = new FileReader(address); From 28da1dda8eeb9a7b88566a77829cb2fa839a3a84 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Fri, 7 Oct 2022 13:32:35 +0900 Subject: [PATCH 013/307] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EB=AA=A8=EC=9D=8C(=ED=8C=8C=EC=9D=BC=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1,=20=EC=9E=91=EC=84=B1=20=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_07/Project/PopulationMethod.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java index 37ca09e..c4a48ef 100644 --- a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java +++ b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java @@ -95,8 +95,8 @@ public void Filewrite(Liststrs){ // 파일 작성 try{ BufferedWriter writer = new BufferedWriter(new FileWriter(file)); - for(PopulationMove str:strs){ // 매개변수로 받은 리스트만큼 반복 - writer.write(String.valueOf(str)+"\n"); // 매개변수로 받은 리스트의 값+"\n" 으로 파일에 작성 + for(PopulationMove str:strs){ // 참조변수로 받은 리스트만큼 반복 + writer.write(String.valueOf(str)+"\n"); // 참조변수로 받은 리스트의 값+"\n" 으로 파일에 작성 } writer.close(); }catch (IOException e){ From f3ce963025632d77b4add02af9ca0f42b69fba6a Mon Sep 17 00:00:00 2001 From: qowl880 Date: Sat, 8 Oct 2022 16:02:01 +0900 Subject: [PATCH 014/307] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EB=AA=A8=EC=9D=8C(=ED=8C=8C=EC=9D=BC=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1,=20=EC=9E=91=EC=84=B1=20=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_07/Project/PopulationMethod.java | 47 +++++++++++++------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java index 5098bed..093d77e 100644 --- a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java +++ b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java @@ -4,8 +4,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; +import java.util.*; public class PopulationMethod { static String address = "C:\\Users\\qowhx\\OneDrive\\바탕 화면\\인구\\2021_인구관련연간자료_20221006_47106.csv"; @@ -56,26 +55,45 @@ public static void ReadByLine2() { // 1줄씩 전부 읽기 } - public static PopulationMove parse(String data) throws IOException { // 원하는 값 추출 + public static PopulationMove parse(String data){ // 원하는 값 추출을 위한 파싱 String[] str = data.split(","); - int FromSido = Integer.parseInt(str[0]); - int ToSido = Integer.parseInt(str[6]); + int FromSido = Integer.parseInt(str[0]); // 11 + int ToSido = Integer.parseInt(str[6]); // 41 - return new PopulationMove(FromSido,ToSido); + return new PopulationMove(FromSido,ToSido); // 맵핑한 값 반환 "서울에서 경기도로 이사합니다" } - public static List ReadByLineParse() throws IOException{ // 1줄씩 전부 읽어서 파싱하기 - List pml = new ArrayList<>(); // PopulationMove arraylist 객체 초기화 + public static String Heatparse(String data){ // heat에 넣기 위한 파싱 + String[] str = data.split(","); + String FromSido = str[0]; // 11 + String ToSido = str[6]; // 41 + String result = FromSido + ","+ToSido; + return result; + } + + + public static Map ReadByLineParse() throws IOException{ // 1줄씩 전부 읽어서 파싱하기 + Map pml = new HashMap<>(); // PopulationMove arraylist 객체 초기화 + Map mapcount = new HashMap<>(); // 카운트 저장할 Map + BufferedReader reader = new BufferedReader( new FileReader(address) ); String str; while ((str = reader.readLine()) != null) { // 파일의 마지막 데이터까지 반복 - PopulationMove pm = parse(str); // pm 참조변수에 parse(한줄 읽기)값 저장 - pml.add(pm); // 리스트에 pm 값 저장 + String pm = String.valueOf(parse(str)); // pm 참조변수에 parse,mapping한(한줄 읽기)값 저장 + + // 횟수 구하기 + if(mapcount.get(pm) == null) { // 처음 들어오는 값이면 1초기화 + mapcount.put(pm,1); + } + mapcount.put(pm,mapcount.get(pm)+1); // 2번째 부터 들어오는 값은 키,키값을 불러와 +1 + + pml.put(pm,mapcount.get(pm)); // 해쉬 pm키, 키에 따른 카운트 값 저장(중복 제거) 저장 결과 : "서울에서 경기도로 이사했습니다", 1 } reader.close(); + return pml; // 리스트 출력 } @@ -90,13 +108,14 @@ public void CreateFile(){ // 파일 생성 } } - public void Filewrite(Liststrs){ // 파일 작성 - File file = new File(saveaddress); + public void Filewrite(Mapstrs){ // 파일 작성 + File file = new File(saveaddress); try{ BufferedWriter writer = new BufferedWriter(new FileWriter(file)); - for(PopulationMove str:strs){ // 매개변수로 받은 리스트만큼 반복 - writer.write(String.valueOf(str)+"\n"); // 매개변수로 받은 리스트의 값+"\n" 으로 파일에 작성 + + for(String str:strs.keySet()){ // 참조변수로 받은 리스트만큼 반복 + writer.write(String.valueOf(str)+","+strs.get(str)+"\n"); // 참조변수로 받은 리스트의 값+"\n" 으로 파일에 작성 } writer.close(); }catch (IOException e){ From 26bbd9eb9ada7687a34b25b5b2fbd588127a42bb Mon Sep 17 00:00:00 2001 From: qowl880 Date: Sat, 8 Oct 2022 16:02:40 +0900 Subject: [PATCH 015/307] File Mapping --- .../src/Date10_07/Project/PopulationMove.java | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationMove.java b/git/Lion-Java/src/Date10_07/Project/PopulationMove.java index 640c7c9..4851d0f 100644 --- a/git/Lion-Java/src/Date10_07/Project/PopulationMove.java +++ b/git/Lion-Java/src/Date10_07/Project/PopulationMove.java @@ -11,7 +11,9 @@ public class PopulationMove { private int fromSido; private int toSido; + String coments; // ReadByLineParse() 메서드에서 파싱한 문자열을 저장할 변수 + int num; public PopulationMove(){ } @@ -29,31 +31,34 @@ public int getToSido() { return toSido; } - public String Mapping(int num){ + + public String Mapping(int num){ // 숫자입력시 해당하는 지역이름 반환 Map map = new HashMap<>(); map.put(11,"서울"); - map.put(21,"부산"); - map.put(22,"대구"); - map.put(23,"인천"); - map.put(24,"광주"); - map.put(25,"대전"); - map.put(26,"울산"); - map.put(29,"세종"); - map.put(31,"경기도"); - map.put(32,"강원도"); - map.put(33,"충북"); - map.put(34,"충남"); - map.put(35,"전북"); - map.put(36,"전남"); - map.put(37,"경북"); - map.put(38,"경남"); - map.put(39,"제주"); + map.put(26,"부산"); + map.put(27,"대구"); + map.put(28,"인천"); + map.put(29,"광주"); + map.put(30,"대전"); + map.put(31,"울산"); + map.put(36,"세종"); + map.put(41,"경기도"); + map.put(42,"강원도"); + map.put(43,"충북"); + map.put(44,"충남"); + map.put(45,"전북"); + map.put(46,"전남"); + map.put(47,"경북"); + map.put(48,"경남"); + map.put(50,"제주"); return map.get(num); } + @Override public String toString() { - return Mapping(fromSido)+"에서 "+Mapping(toSido)+"로 이사갔습니다."; + return Mapping(fromSido)+","+Mapping(toSido); } + } From d9286df7b853ee1e6e192a3ae7e7d890fdba6019 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Sat, 8 Oct 2022 16:02:55 +0900 Subject: [PATCH 016/307] =?UTF-8?q?[CodeUp]=201024=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_06/CodeUp/No_1024.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 git/Lion-Java/src/Date10_06/CodeUp/No_1024.java diff --git a/git/Lion-Java/src/Date10_06/CodeUp/No_1024.java b/git/Lion-Java/src/Date10_06/CodeUp/No_1024.java new file mode 100644 index 0000000..6a92d67 --- /dev/null +++ b/git/Lion-Java/src/Date10_06/CodeUp/No_1024.java @@ -0,0 +1,20 @@ +package Date10_06.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + + +public class No_1024 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + String s = bf.readLine(); + char[] str = new char[s.length()]; + + for(int i =0; i Date: Sat, 8 Oct 2022 16:03:02 +0900 Subject: [PATCH 017/307] =?UTF-8?q?[CodeUp]=201025=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_06/CodeUp/No_1025.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 git/Lion-Java/src/Date10_06/CodeUp/No_1025.java diff --git a/git/Lion-Java/src/Date10_06/CodeUp/No_1025.java b/git/Lion-Java/src/Date10_06/CodeUp/No_1025.java new file mode 100644 index 0000000..c076dde --- /dev/null +++ b/git/Lion-Java/src/Date10_06/CodeUp/No_1025.java @@ -0,0 +1,22 @@ +package Date10_06.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1025 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + String s = bf.readLine(); + + String[] cmd = s.split(""); + + System.out.println("["+Integer.parseInt(cmd[0]) * 10000+"]"); + System.out.println("["+Integer.parseInt(cmd[1]) * 1000+"]"); + System.out.println("["+Integer.parseInt(cmd[2]) * 100+"]"); + System.out.println("["+Integer.parseInt(cmd[3]) * 10+"]"); + System.out.println("["+Integer.parseInt(cmd[4]) * 1+"]"); + + } +} From fc7e675f31ebceea0d41c083dabbbea7770dc071 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Sat, 8 Oct 2022 16:03:07 +0900 Subject: [PATCH 018/307] =?UTF-8?q?[CodeUp]=201026=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_06/CodeUp/No_1026.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 git/Lion-Java/src/Date10_06/CodeUp/No_1026.java diff --git a/git/Lion-Java/src/Date10_06/CodeUp/No_1026.java b/git/Lion-Java/src/Date10_06/CodeUp/No_1026.java new file mode 100644 index 0000000..71ce27e --- /dev/null +++ b/git/Lion-Java/src/Date10_06/CodeUp/No_1026.java @@ -0,0 +1,16 @@ +package Date10_06.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1026 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + String s = bf.readLine(); + + String[] str = s.split(":"); + + System.out.println(Integer.parseInt(str[1])); + } +} From 2a5d9cb8ea326102d00800e4a5cb79db66273001 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Sat, 8 Oct 2022 16:03:12 +0900 Subject: [PATCH 019/307] =?UTF-8?q?[CodeUp]=201027=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_06/CodeUp/No_1027.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 git/Lion-Java/src/Date10_06/CodeUp/No_1027.java diff --git a/git/Lion-Java/src/Date10_06/CodeUp/No_1027.java b/git/Lion-Java/src/Date10_06/CodeUp/No_1027.java new file mode 100644 index 0000000..c732ed2 --- /dev/null +++ b/git/Lion-Java/src/Date10_06/CodeUp/No_1027.java @@ -0,0 +1,22 @@ +package Date10_06.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1027 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + String s = bf.readLine(); + + String[] str = s.split("[.]"); + + for(int i=str.length-1; i>=0; i--){ + if(i!=0) + System.out.print(str[i]+"-"); + else + System.out.println(str[i]); + } + } +} From bd9c3144bbc6121170729779aa66483fba772d2f Mon Sep 17 00:00:00 2001 From: qowl880 Date: Sat, 8 Oct 2022 16:03:17 +0900 Subject: [PATCH 020/307] =?UTF-8?q?[CodeUp]=201028=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_06/CodeUp/No_1028.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 git/Lion-Java/src/Date10_06/CodeUp/No_1028.java diff --git a/git/Lion-Java/src/Date10_06/CodeUp/No_1028.java b/git/Lion-Java/src/Date10_06/CodeUp/No_1028.java new file mode 100644 index 0000000..636b030 --- /dev/null +++ b/git/Lion-Java/src/Date10_06/CodeUp/No_1028.java @@ -0,0 +1,16 @@ +package Date10_06.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1028 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + String s = bf.readLine(); + long num = Long.parseLong(s); + + System.out.println(num); + } +} From d71ab512497c4820b7aaffe6c800ca1a2da99468 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Sat, 8 Oct 2022 16:03:21 +0900 Subject: [PATCH 021/307] =?UTF-8?q?[CodeUp]=201029=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_06/CodeUp/No_1029.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 git/Lion-Java/src/Date10_06/CodeUp/No_1029.java diff --git a/git/Lion-Java/src/Date10_06/CodeUp/No_1029.java b/git/Lion-Java/src/Date10_06/CodeUp/No_1029.java new file mode 100644 index 0000000..057b926 --- /dev/null +++ b/git/Lion-Java/src/Date10_06/CodeUp/No_1029.java @@ -0,0 +1,17 @@ +package Date10_06.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1029 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + String s = bf.readLine(); + + double num = Double.parseDouble(s); + + System.out.printf("%.11f",num); + } +} From 6fe28f3af9ecb94d44a789527284d610cbe2641b Mon Sep 17 00:00:00 2001 From: qowl880 Date: Sat, 8 Oct 2022 16:03:28 +0900 Subject: [PATCH 022/307] =?UTF-8?q?[CodeUp]=201030=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_06/CodeUp/No_1030.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 git/Lion-Java/src/Date10_06/CodeUp/No_1030.java diff --git a/git/Lion-Java/src/Date10_06/CodeUp/No_1030.java b/git/Lion-Java/src/Date10_06/CodeUp/No_1030.java new file mode 100644 index 0000000..2018940 --- /dev/null +++ b/git/Lion-Java/src/Date10_06/CodeUp/No_1030.java @@ -0,0 +1,16 @@ +package Date10_06.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1030 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + String s = bf.readLine(); + + long num = Long.parseLong(s); + System.out.println(s); + } +} From 9d86123b2c4f348e8d6a7c3e4acab281995f39d4 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Sat, 8 Oct 2022 16:03:32 +0900 Subject: [PATCH 023/307] =?UTF-8?q?[CodeUp]=201031=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_07/Project/CodeUp/No_1031.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 git/Lion-Java/src/Date10_07/Project/CodeUp/No_1031.java diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1031.java b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1031.java new file mode 100644 index 0000000..64f4ab8 --- /dev/null +++ b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1031.java @@ -0,0 +1,17 @@ +package Date10_07.Project.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1031 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + String s = bf.readLine(); + + int num = Integer.parseInt(s); + + System.out.printf("%o",num); // %o 2진수로 출력 + } +} From 0482a4be3633fe0fff115dc45c8b2b4dcb4c96d6 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Sat, 8 Oct 2022 16:03:37 +0900 Subject: [PATCH 024/307] =?UTF-8?q?[CodeUp]=201032=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_07/Project/CodeUp/No_1032.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 git/Lion-Java/src/Date10_07/Project/CodeUp/No_1032.java diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1032.java b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1032.java new file mode 100644 index 0000000..4d36427 --- /dev/null +++ b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1032.java @@ -0,0 +1,17 @@ +package Date10_07.Project.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1032 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + String s = bf.readLine(); + + int num = Integer.parseInt(s); + + System.out.printf("%x",num); // 소문자 x는 16진수 소문자로 출력 + } +} From 0911c07d6fbfb98728940ab4863d48aa87c2a151 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Sat, 8 Oct 2022 16:03:42 +0900 Subject: [PATCH 025/307] =?UTF-8?q?[CodeUp]=201033=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_07/Project/CodeUp/No_1033.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 git/Lion-Java/src/Date10_07/Project/CodeUp/No_1033.java diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1033.java b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1033.java new file mode 100644 index 0000000..3888d9d --- /dev/null +++ b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1033.java @@ -0,0 +1,17 @@ +package Date10_07.Project.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1033 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + String s = bf.readLine(); + + int num = Integer.parseInt(s); + + System.out.printf("%X",num); // 대문자 x는 16진수 대문자로 출력 + } +} From b4e641510cc6ae0e26fd71e39824d9c880d878c2 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Sat, 8 Oct 2022 16:03:46 +0900 Subject: [PATCH 026/307] =?UTF-8?q?[CodeUp]=201034=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_07/Project/CodeUp/No_1034.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 git/Lion-Java/src/Date10_07/Project/CodeUp/No_1034.java diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1034.java b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1034.java new file mode 100644 index 0000000..8230b71 --- /dev/null +++ b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1034.java @@ -0,0 +1,17 @@ +package Date10_07.Project.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1034 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + String s = bf.readLine(); + + int num = Integer.parseInt(s,8); // 8진수로 저장한다는 뜻 + + System.out.printf("%d",num); + } +} From 5838e8906a38e93ddd358d5ed51d942aa5830fc2 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Sat, 8 Oct 2022 16:03:51 +0900 Subject: [PATCH 027/307] =?UTF-8?q?[CodeUp]=201035=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_07/Project/CodeUp/No_1035.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 git/Lion-Java/src/Date10_07/Project/CodeUp/No_1035.java diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1035.java b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1035.java new file mode 100644 index 0000000..bc41a4c --- /dev/null +++ b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1035.java @@ -0,0 +1,18 @@ +package Date10_07.Project.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1035 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + String s = bf.readLine(); + + int num = Integer.parseInt(s,16); + + System.out.printf("%o",num); + + } +} From f74a28dba113aa0d48ad3525c401ae5c9352a50e Mon Sep 17 00:00:00 2001 From: qowl880 Date: Sat, 8 Oct 2022 16:03:58 +0900 Subject: [PATCH 028/307] =?UTF-8?q?[CodeUp]=201036=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_07/Project/CodeUp/No_1036.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 git/Lion-Java/src/Date10_07/Project/CodeUp/No_1036.java diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1036.java b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1036.java new file mode 100644 index 0000000..a1e9407 --- /dev/null +++ b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1036.java @@ -0,0 +1,19 @@ +package Date10_07.Project.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1036 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + String s = bf.readLine(); + + char c = s.charAt(0); + + int num = c; + + System.out.println(num); + } +} From fe9fbf2bb0b705e48aeb3c3f921c7e691fa40ee5 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Sat, 8 Oct 2022 16:10:01 +0900 Subject: [PATCH 029/307] File Method --- .../Date10_07/Project/PopulationMethod.java | 49 +++++++++++++------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java index 5098bed..781e2df 100644 --- a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java +++ b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java @@ -4,8 +4,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; +import java.util.*; public class PopulationMethod { static String address = "C:\\Users\\qowhx\\OneDrive\\바탕 화면\\인구\\2021_인구관련연간자료_20221006_47106.csv"; @@ -56,29 +55,48 @@ public static void ReadByLine2() { // 1줄씩 전부 읽기 } - public static PopulationMove parse(String data) throws IOException { // 원하는 값 추출 + public static PopulationMove parse(String data){ // 원하는 값 추출을 위한 파싱 String[] str = data.split(","); - int FromSido = Integer.parseInt(str[0]); - int ToSido = Integer.parseInt(str[6]); + int FromSido = Integer.parseInt(str[0]); // 11 + int ToSido = Integer.parseInt(str[6]); // 41 - return new PopulationMove(FromSido,ToSido); + return new PopulationMove(FromSido,ToSido); // 맵핑한 값 반환 "서울에서 경기도로 이사합니다" } - public static List ReadByLineParse() throws IOException{ // 1줄씩 전부 읽어서 파싱하기 - List pml = new ArrayList<>(); // PopulationMove arraylist 객체 초기화 + public static String Heatparse(String data){ // heat에 넣기 위한 파싱 + String[] str = data.split(","); + String FromSido = str[0]; // 11 + String ToSido = str[6]; // 41 + String result = FromSido + ","+ToSido; + return result; + } + + + public static Map ReadByLineParse() throws IOException{ // 1줄씩 전부 읽어서 파싱하기 + Map pml = new HashMap<>(); // PopulationMove arraylist 객체 초기화 + Map mapcount = new HashMap<>(); // 카운트 저장할 Map + BufferedReader reader = new BufferedReader( new FileReader(address) ); String str; while ((str = reader.readLine()) != null) { // 파일의 마지막 데이터까지 반복 - PopulationMove pm = parse(str); // pm 참조변수에 parse(한줄 읽기)값 저장 - pml.add(pm); // 리스트에 pm 값 저장 + String pm = String.valueOf(parse(str)); // pm 참조변수에 parse,mapping한(한줄 읽기)값 저장 + + // 횟수 구하기 + if(mapcount.get(pm) == null) { // 처음 들어오는 값이면 1초기화 + mapcount.put(pm,1); + } + mapcount.put(pm,mapcount.get(pm)+1); // 2번째 부터 들어오는 값은 키,키값을 불러와 +1 + + pml.put(pm,mapcount.get(pm)); // 해쉬 pm키, 키에 따른 카운트 값 저장(중복 제거) 저장 결과 : "서울에서 경기도로 이사했습니다", 1 } reader.close(); + return pml; // 리스트 출력 } - + public void CreateFile(){ // 파일 생성 File file = new File(saveaddress); // 파일 생성 위치및 파일 이름 try{ @@ -90,13 +108,14 @@ public void CreateFile(){ // 파일 생성 } } - public void Filewrite(Liststrs){ // 파일 작성 - File file = new File(saveaddress); + public void Filewrite(Mapstrs){ // 파일 작성 + File file = new File(saveaddress); try{ BufferedWriter writer = new BufferedWriter(new FileWriter(file)); - for(PopulationMove str:strs){ // 매개변수로 받은 리스트만큼 반복 - writer.write(String.valueOf(str)+"\n"); // 매개변수로 받은 리스트의 값+"\n" 으로 파일에 작성 + + for(String str:strs.keySet()){ // 참조변수로 받은 리스트만큼 반복 + writer.write(str+","+strs.get(str)+"\n"); // 참조변수로 받은 리스트의 값+"\n" 으로 파일에 작성 } writer.close(); }catch (IOException e){ From 403a8e21dd74c8af2ad6c05b3bd49f1c05840a8e Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Sat, 8 Oct 2022 16:14:47 +0900 Subject: [PATCH 030/307] Update README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f041cee..19f8f28 100644 --- a/README.md +++ b/README.md @@ -18,5 +18,11 @@
-## ☁️ 프로젝트 주요 기능 +## ☁️ 대용량데이터처리 프로젝트 진행 순서 +- 목적 : A지역에서 B지역으로 어느곳으로 이사를 많이 갔는지 횟수 구하기 +(1) 인구이동관련 대용량 파일을 다운받음 +(2) 대용량 파일을 읽음 +(3) 파일을 읽는 방식은 1줄씩 마지막 데이터까지 읽음 +(4) 원하는 데이터만 추출하기 위해 파싱작업(여러가지 데이터중 지역만 추출) +(5) 추출한 데이터 Mapping(현재 지역이 숫자로 되어 있기에 한글로 변경 ex. 11 -> "서울") From e6b0e72ef40713730026bb5882c1231dcbc9bc6d Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Sat, 8 Oct 2022 16:23:37 +0900 Subject: [PATCH 031/307] Update README.md --- README.md | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 19f8f28..1bbe6c0 100644 --- a/README.md +++ b/README.md @@ -18,11 +18,19 @@
-## ☁️ 대용량데이터처리 프로젝트 진행 순서 -- 목적 : A지역에서 B지역으로 어느곳으로 이사를 많이 갔는지 횟수 구하기 -(1) 인구이동관련 대용량 파일을 다운받음 -(2) 대용량 파일을 읽음 -(3) 파일을 읽는 방식은 1줄씩 마지막 데이터까지 읽음 -(4) 원하는 데이터만 추출하기 위해 파싱작업(여러가지 데이터중 지역만 추출) -(5) 추출한 데이터 Mapping(현재 지역이 숫자로 되어 있기에 한글로 변경 ex. 11 -> "서울") +## ☁️ 대용량데이터처리 프로젝트(1) +### ➀ 목적 +####    A지역에서 B지역으로 어느곳으로 이사를 많이 갔는지 횟수 구하기 + +### ➁ 진행 순서 +####    1. 인구이동관련 대용량 파일을 다운받음 +####    2. 추출한 값 저장할 파일 생성 +####    3. 대용량 파일을 읽음 +####    4. 파일을 읽는 방식은 1줄씩 마지막 데이터까지 읽음 +####    5. 원하는 데이터만 추출하기 위해 파싱작업(여러가지 데이터중 지역만 추출) +####    6. 추출한 데이터 Mapping(현재 지역이 숫자로 되어 있기에 한글로 변경 ex. 11 -> "서울") +####    7. Mapping 할때마다 횟수 카운트 +####    8. Mapping한 A,B 지역을 담은 데이터와 횟수 카운트를 Map에 저장[key:(A,B),value:(횟수)] +####    9. 새로 생성한 파일에 지역정보와 이사횟수 작성 + From bc5c8f8e56d2dac4a57c785e7e58c2289b65087a Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Sat, 8 Oct 2022 16:24:40 +0900 Subject: [PATCH 032/307] File Method --- git/Lion-Java/src/Date10_07/Project/PopulationMethod.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java index 781e2df..0e969ea 100644 --- a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java +++ b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java @@ -7,9 +7,9 @@ import java.util.*; public class PopulationMethod { - static String address = "C:\\Users\\qowhx\\OneDrive\\바탕 화면\\인구\\2021_인구관련연간자료_20221006_47106.csv"; + static String address = "대용량 데이터 파일 위치"; - static String saveaddress = "C:\\Users\\qowhx\\AppData\\Roaming\\SPB_Data\\git\\Java-Study\\file.txt"; + static String saveaddress = "파일 생성할 "; public static void ReadByChar() throws IOException { // 1글자씩 읽기 FileReader fileReader = new FileReader(address); @@ -61,7 +61,7 @@ public static PopulationMove parse(String data){ // 원하는 값 추출 int FromSido = Integer.parseInt(str[0]); // 11 int ToSido = Integer.parseInt(str[6]); // 41 - return new PopulationMove(FromSido,ToSido); // 맵핑한 값 반환 "서울에서 경기도로 이사합니다" + return new PopulationMove(FromSido,ToSido); // 맵핑한 값 반환 "서울,경기도" } public static String Heatparse(String data){ // heat에 넣기 위한 파싱 @@ -90,7 +90,7 @@ public static Map ReadByLineParse() throws IOException{ } mapcount.put(pm,mapcount.get(pm)+1); // 2번째 부터 들어오는 값은 키,키값을 불러와 +1 - pml.put(pm,mapcount.get(pm)); // 해쉬 pm키, 키에 따른 카운트 값 저장(중복 제거) 저장 결과 : "서울에서 경기도로 이사했습니다", 1 + pml.put(pm,mapcount.get(pm)); // Map에 저장하여 Key만 중복제거 저장 결과 : "서울,경기도", 1 } reader.close(); From fca854d26f433dec389273690395d105ba4e5476 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Sat, 8 Oct 2022 17:16:05 +0900 Subject: [PATCH 033/307] =?UTF-8?q?[CodeUp]=201037=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_07/Project/CodeUp/No_1037.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 git/Lion-Java/src/Date10_07/Project/CodeUp/No_1037.java diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1037.java b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1037.java new file mode 100644 index 0000000..e5b81bd --- /dev/null +++ b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1037.java @@ -0,0 +1,19 @@ +package Date10_07.Project.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1037 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + String s = bf.readLine(); + + int num = Integer.parseInt(s); + + char c = (char)num; + + System.out.println(c); + } +} From f36baf6ca458dddb7d593cd7990ec6042f32b660 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Sat, 8 Oct 2022 17:16:11 +0900 Subject: [PATCH 034/307] =?UTF-8?q?[CodeUp]=201038=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_07/Project/CodeUp/No_1038.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 git/Lion-Java/src/Date10_07/Project/CodeUp/No_1038.java diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1038.java b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1038.java new file mode 100644 index 0000000..2bc6792 --- /dev/null +++ b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1038.java @@ -0,0 +1,18 @@ +package Date10_07.Project.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1038 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + String[] str = bf.readLine().split(" "); + + long num1 = Long.parseLong(str[0]); + long num2 = Long.parseLong(str[1]); + + System.out.println(num1 + num2); + } +} From dcbe799a9edfbb40e470872db53b58b6f49922f1 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Sat, 8 Oct 2022 17:16:16 +0900 Subject: [PATCH 035/307] =?UTF-8?q?[CodeUp]=201039=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_07/Project/CodeUp/No_1039.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 git/Lion-Java/src/Date10_07/Project/CodeUp/No_1039.java diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1039.java b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1039.java new file mode 100644 index 0000000..c228e32 --- /dev/null +++ b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1039.java @@ -0,0 +1,18 @@ +package Date10_07.Project.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1039 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + String[] s = bf.readLine().split(" "); + + long num1 = Long.parseLong(s[0]); + long num2 = Long.parseLong(s[1]); + + System.out.println(num1+num2); + } +} From 73f6ef407e20451613a7f0aab5fb979104181323 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Sat, 8 Oct 2022 17:16:20 +0900 Subject: [PATCH 036/307] =?UTF-8?q?[CodeUp]=201040=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_07/Project/CodeUp/No_1040.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 git/Lion-Java/src/Date10_07/Project/CodeUp/No_1040.java diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1040.java b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1040.java new file mode 100644 index 0000000..78e3f1a --- /dev/null +++ b/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1040.java @@ -0,0 +1,15 @@ +package Date10_07.Project.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1040 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + int num = Integer.parseInt(bf.readLine()); + + System.out.println(-(num)); + } +} From bfa788069a2e9230fd6144147ba8aec463c2870e Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Sun, 9 Oct 2022 17:27:09 +0900 Subject: [PATCH 037/307] File Method --- git/Lion-Java/src/Date10_07/Project/PopulationMethod.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java index 0e969ea..dfc9afe 100644 --- a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java +++ b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java @@ -74,7 +74,6 @@ public static String Heatparse(String data){ // heat에 넣기 위한 public static Map ReadByLineParse() throws IOException{ // 1줄씩 전부 읽어서 파싱하기 - Map pml = new HashMap<>(); // PopulationMove arraylist 객체 초기화 Map mapcount = new HashMap<>(); // 카운트 저장할 Map BufferedReader reader = new BufferedReader( @@ -89,12 +88,10 @@ public static Map ReadByLineParse() throws IOException{ mapcount.put(pm,1); } mapcount.put(pm,mapcount.get(pm)+1); // 2번째 부터 들어오는 값은 키,키값을 불러와 +1 - - pml.put(pm,mapcount.get(pm)); // Map에 저장하여 Key만 중복제거 저장 결과 : "서울,경기도", 1 } reader.close(); - return pml; // 리스트 출력 + return mapcount; // 리스트 출력 } public void CreateFile(){ // 파일 생성 From 9c0349cb844a5230aaee5b6fd07d57cf8c6b65a1 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Sun, 9 Oct 2022 20:08:11 +0900 Subject: [PATCH 038/307] Update README.md --- README.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1bbe6c0..6456e0d 100644 --- a/README.md +++ b/README.md @@ -23,14 +23,12 @@ ####    A지역에서 B지역으로 어느곳으로 이사를 많이 갔는지 횟수 구하기 ### ➁ 진행 순서 -####    1. 인구이동관련 대용량 파일을 다운받음 -####    2. 추출한 값 저장할 파일 생성 -####    3. 대용량 파일을 읽음 -####    4. 파일을 읽는 방식은 1줄씩 마지막 데이터까지 읽음 -####    5. 원하는 데이터만 추출하기 위해 파싱작업(여러가지 데이터중 지역만 추출) -####    6. 추출한 데이터 Mapping(현재 지역이 숫자로 되어 있기에 한글로 변경 ex. 11 -> "서울") -####    7. Mapping 할때마다 횟수 카운트 -####    8. Mapping한 A,B 지역을 담은 데이터와 횟수 카운트를 Map에 저장[key:(A,B),value:(횟수)] -####    9. 새로 생성한 파일에 지역정보와 이사횟수 작성 +####    1. 대용량 데이터 파일을 다운받음 +####    2. 파일을 읽고 자신이 원하는 값만 추출함 +####    3. 현재 값이 숫자로 되어 있으므로 원하는 형식으로 맵핑함 +####    4. 추출한 데이터를 저장할 파일을 생성하고 파일에 데이터를 작성하여 저장함 + +https://velog.io/@qowl880/Java-%EB%8C%80%EC%9A%A9%EB%9F%89%EC%B2%98%EB%A6%AC-%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8 + From 615cf33bb1845ba1f6b2cb36866a4580f2f451c7 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Sun, 9 Oct 2022 20:09:14 +0900 Subject: [PATCH 039/307] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6456e0d..f2b9651 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ ####    3. 현재 값이 숫자로 되어 있으므로 원하는 형식으로 맵핑함 ####    4. 추출한 데이터를 저장할 파일을 생성하고 파일에 데이터를 작성하여 저장함 +## 📗 정리 블로그 https://velog.io/@qowl880/Java-%EB%8C%80%EC%9A%A9%EB%9F%89%EC%B2%98%EB%A6%AC-%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8 From 89a6298486dbbbc4730775ba7afcba53a8eb7d0d Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Sun, 9 Oct 2022 20:09:34 +0900 Subject: [PATCH 040/307] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f2b9651..71a0586 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ ####    3. 현재 값이 숫자로 되어 있으므로 원하는 형식으로 맵핑함 ####    4. 추출한 데이터를 저장할 파일을 생성하고 파일에 데이터를 작성하여 저장함 -## 📗 정리 블로그 +### 📗 정리 블로그 https://velog.io/@qowl880/Java-%EB%8C%80%EC%9A%A9%EB%9F%89%EC%B2%98%EB%A6%AC-%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8 From f78861ad133eb9cc57572c49494e384f76272f27 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Mon, 10 Oct 2022 13:49:03 +0900 Subject: [PATCH 041/307] =?UTF-8?q?[CodeUp]=201031=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1031.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1031.java (92%) diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1031.java b/git/Lion-Java/src/Date10_07/CodeUp/No_1031.java similarity index 92% rename from git/Lion-Java/src/Date10_07/Project/CodeUp/No_1031.java rename to git/Lion-Java/src/Date10_07/CodeUp/No_1031.java index 64f4ab8..7f04e1b 100644 --- a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1031.java +++ b/git/Lion-Java/src/Date10_07/CodeUp/No_1031.java @@ -1,4 +1,4 @@ -package Date10_07.Project.CodeUp; +package Date10_07.CodeUp; import java.io.BufferedReader; import java.io.IOException; From d75bcdd444ba3739a045f84790bdcf1022b35af5 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Mon, 10 Oct 2022 13:49:08 +0900 Subject: [PATCH 042/307] =?UTF-8?q?[CodeUp]=201032=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1032.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1032.java (92%) diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1032.java b/git/Lion-Java/src/Date10_07/CodeUp/No_1032.java similarity index 92% rename from git/Lion-Java/src/Date10_07/Project/CodeUp/No_1032.java rename to git/Lion-Java/src/Date10_07/CodeUp/No_1032.java index 4d36427..5c35601 100644 --- a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1032.java +++ b/git/Lion-Java/src/Date10_07/CodeUp/No_1032.java @@ -1,4 +1,4 @@ -package Date10_07.Project.CodeUp; +package Date10_07.CodeUp; import java.io.BufferedReader; import java.io.IOException; From de917aadaba283ce0b8ba97527dd0ae89b213d2d Mon Sep 17 00:00:00 2001 From: qowl880 Date: Mon, 10 Oct 2022 13:49:19 +0900 Subject: [PATCH 043/307] =?UTF-8?q?[CodeUp]=201033=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1033.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1033.java (92%) diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1033.java b/git/Lion-Java/src/Date10_07/CodeUp/No_1033.java similarity index 92% rename from git/Lion-Java/src/Date10_07/Project/CodeUp/No_1033.java rename to git/Lion-Java/src/Date10_07/CodeUp/No_1033.java index 3888d9d..e3f9708 100644 --- a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1033.java +++ b/git/Lion-Java/src/Date10_07/CodeUp/No_1033.java @@ -1,4 +1,4 @@ -package Date10_07.Project.CodeUp; +package Date10_07.CodeUp; import java.io.BufferedReader; import java.io.IOException; From 59375ffc3d2918991ac8a4270b2e5adeaa8073ef Mon Sep 17 00:00:00 2001 From: qowl880 Date: Mon, 10 Oct 2022 13:49:24 +0900 Subject: [PATCH 044/307] =?UTF-8?q?[CodeUp]=201034=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1034.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1034.java (92%) diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1034.java b/git/Lion-Java/src/Date10_07/CodeUp/No_1034.java similarity index 92% rename from git/Lion-Java/src/Date10_07/Project/CodeUp/No_1034.java rename to git/Lion-Java/src/Date10_07/CodeUp/No_1034.java index 8230b71..cea8b41 100644 --- a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1034.java +++ b/git/Lion-Java/src/Date10_07/CodeUp/No_1034.java @@ -1,4 +1,4 @@ -package Date10_07.Project.CodeUp; +package Date10_07.CodeUp; import java.io.BufferedReader; import java.io.IOException; From 514b8d198654859b8691163c882643df908b726b Mon Sep 17 00:00:00 2001 From: qowl880 Date: Mon, 10 Oct 2022 13:49:29 +0900 Subject: [PATCH 045/307] =?UTF-8?q?[CodeUp]=201035=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1035.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1035.java (91%) diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1035.java b/git/Lion-Java/src/Date10_07/CodeUp/No_1035.java similarity index 91% rename from git/Lion-Java/src/Date10_07/Project/CodeUp/No_1035.java rename to git/Lion-Java/src/Date10_07/CodeUp/No_1035.java index bc41a4c..410c2df 100644 --- a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1035.java +++ b/git/Lion-Java/src/Date10_07/CodeUp/No_1035.java @@ -1,4 +1,4 @@ -package Date10_07.Project.CodeUp; +package Date10_07.CodeUp; import java.io.BufferedReader; import java.io.IOException; From 769033db40ab368290aecb265643e55f50f9dfcb Mon Sep 17 00:00:00 2001 From: qowl880 Date: Mon, 10 Oct 2022 13:49:35 +0900 Subject: [PATCH 046/307] =?UTF-8?q?[CodeUp]=201036=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1036.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1036.java (92%) diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1036.java b/git/Lion-Java/src/Date10_07/CodeUp/No_1036.java similarity index 92% rename from git/Lion-Java/src/Date10_07/Project/CodeUp/No_1036.java rename to git/Lion-Java/src/Date10_07/CodeUp/No_1036.java index a1e9407..14598e7 100644 --- a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1036.java +++ b/git/Lion-Java/src/Date10_07/CodeUp/No_1036.java @@ -1,4 +1,4 @@ -package Date10_07.Project.CodeUp; +package Date10_07.CodeUp; import java.io.BufferedReader; import java.io.IOException; From ba72dc467a5cc94c47605fbfa47910fba609f9e3 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Mon, 10 Oct 2022 13:49:40 +0900 Subject: [PATCH 047/307] =?UTF-8?q?[CodeUp]=201037=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1037.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1037.java (92%) diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1037.java b/git/Lion-Java/src/Date10_07/CodeUp/No_1037.java similarity index 92% rename from git/Lion-Java/src/Date10_07/Project/CodeUp/No_1037.java rename to git/Lion-Java/src/Date10_07/CodeUp/No_1037.java index e5b81bd..3f9f3fd 100644 --- a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1037.java +++ b/git/Lion-Java/src/Date10_07/CodeUp/No_1037.java @@ -1,4 +1,4 @@ -package Date10_07.Project.CodeUp; +package Date10_07.CodeUp; import java.io.BufferedReader; import java.io.IOException; From 347d833ee938199eac57fb709681feecf7c659a0 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Mon, 10 Oct 2022 13:49:45 +0900 Subject: [PATCH 048/307] =?UTF-8?q?[CodeUp]=201038=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1038.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1038.java (93%) diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1038.java b/git/Lion-Java/src/Date10_07/CodeUp/No_1038.java similarity index 93% rename from git/Lion-Java/src/Date10_07/Project/CodeUp/No_1038.java rename to git/Lion-Java/src/Date10_07/CodeUp/No_1038.java index 2bc6792..3c03e23 100644 --- a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1038.java +++ b/git/Lion-Java/src/Date10_07/CodeUp/No_1038.java @@ -1,4 +1,4 @@ -package Date10_07.Project.CodeUp; +package Date10_07.CodeUp; import java.io.BufferedReader; import java.io.IOException; From 84f7d703838e4e9f09fde4342312d0beae9f48c2 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Mon, 10 Oct 2022 13:49:50 +0900 Subject: [PATCH 049/307] =?UTF-8?q?[CodeUp]=201039=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1039.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1039.java (92%) diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1039.java b/git/Lion-Java/src/Date10_07/CodeUp/No_1039.java similarity index 92% rename from git/Lion-Java/src/Date10_07/Project/CodeUp/No_1039.java rename to git/Lion-Java/src/Date10_07/CodeUp/No_1039.java index c228e32..b7bc550 100644 --- a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1039.java +++ b/git/Lion-Java/src/Date10_07/CodeUp/No_1039.java @@ -1,4 +1,4 @@ -package Date10_07.Project.CodeUp; +package Date10_07.CodeUp; import java.io.BufferedReader; import java.io.IOException; From d8c7b29a188a9de618fc1c91f2d66c4c6932be1e Mon Sep 17 00:00:00 2001 From: qowl880 Date: Mon, 10 Oct 2022 13:49:55 +0900 Subject: [PATCH 050/307] =?UTF-8?q?[CodeUp]=201040=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1040.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename git/Lion-Java/src/Date10_07/{Project => }/CodeUp/No_1040.java (91%) diff --git a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1040.java b/git/Lion-Java/src/Date10_07/CodeUp/No_1040.java similarity index 91% rename from git/Lion-Java/src/Date10_07/Project/CodeUp/No_1040.java rename to git/Lion-Java/src/Date10_07/CodeUp/No_1040.java index 78e3f1a..65896a6 100644 --- a/git/Lion-Java/src/Date10_07/Project/CodeUp/No_1040.java +++ b/git/Lion-Java/src/Date10_07/CodeUp/No_1040.java @@ -1,4 +1,4 @@ -package Date10_07.Project.CodeUp; +package Date10_07.CodeUp; import java.io.BufferedReader; import java.io.IOException; From fbead37d9cb6c93ac4087d07141e40f8ba5f7ae7 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Mon, 10 Oct 2022 23:06:40 +0900 Subject: [PATCH 051/307] =?UTF-8?q?Project=20Method(HeatMap=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_07/Project/PopulationMethod.java | 70 ++++++++++++++++--- 1 file changed, 59 insertions(+), 11 deletions(-) diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java index dfc9afe..5a0736a 100644 --- a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java +++ b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java @@ -7,9 +7,10 @@ import java.util.*; public class PopulationMethod { - static String address = "대용량 데이터 파일 위치"; + static String address = "C:\\Users\\qowhx\\OneDrive\\바탕 화면\\인구\\2021_인구관련연간자료_20221006_47106.csv"; - static String saveaddress = "파일 생성할 "; + static String saveaddress = "C:\\Users\\qowhx\\AppData\\Roaming\\SPB_Data\\git\\Java-Study\\file.txt"; + static String heatsaveaddress = "C:\\Users\\qowhx\\AppData\\Roaming\\SPB_Data\\git\\Java-Study\\heatfile.txt"; public static void ReadByChar() throws IOException { // 1글자씩 읽기 FileReader fileReader = new FileReader(address); @@ -64,15 +65,6 @@ public static PopulationMove parse(String data){ // 원하는 값 추출 return new PopulationMove(FromSido,ToSido); // 맵핑한 값 반환 "서울,경기도" } - public static String Heatparse(String data){ // heat에 넣기 위한 파싱 - String[] str = data.split(","); - String FromSido = str[0]; // 11 - String ToSido = str[6]; // 41 - String result = FromSido + ","+ToSido; - return result; - } - - public static Map ReadByLineParse() throws IOException{ // 1줄씩 전부 읽어서 파싱하기 Map mapcount = new HashMap<>(); // 카운트 저장할 Map @@ -119,4 +111,60 @@ public void Filewrite(Mapstrs){ // 파일 작성 e.printStackTrace(); } } + + // -------------- heat를 위한 메서드 ---------------- + + public static String Heatparse(String data){ // heat에 넣기 위한 파싱 + String[] str = data.split(","); + String FromSido = str[0]; // 11 + String ToSido = str[6]; // 41 + String result = FromSido + ","+ToSido; + return result; + } + + public static Map HeatReadByLineParse() throws IOException{ // heat에 넣기 위한 1줄씩 전부 읽기 + Map mapcount = new TreeMap<>(); // 카운트 저장할 Map + + BufferedReader reader = new BufferedReader( + new FileReader(address) + ); + String str; + while ((str = reader.readLine()) != null) { // 파일의 마지막 데이터까지 반복 + String pm = Heatparse(str); // pm 참조변수에 parse,mapping한(한줄 읽기)값 저장 + + // 횟수 구하기 + if(mapcount.get(pm) == null) { // 처음 들어오는 값이면 1초기화 + mapcount.put(pm,1); + }else + mapcount.put(pm,mapcount.get(pm)+1); // 2번째 부터 들어오는 값은 키,키값을 불러와 +1 + } + reader.close(); + + return mapcount; // 리스트 출력 + } + + public void HeatCreateFile(){ // heat 파일 생성 + File file = new File(heatsaveaddress); // 파일 생성 위치및 파일 이름 + try{ + System.out.println("파일 생성"); + file.createNewFile(); + }catch (IOException e){ + System.out.println("파일 생성 못함"); + throw new RuntimeException(); + } + } + + public void HeatFilewrite(Mapstrs){ // heat 파일 작성 + File file = new File(heatsaveaddress); + + try{ + BufferedWriter writer = new BufferedWriter(new FileWriter(file)); + for(String str:strs.keySet()){ // 참조변수로 받은 리스트만큼 반복 + writer.write(str+","+strs.get(str)+"\n"); // 참조변수로 받은 리스트의 값+"\n" 으로 파일에 작성 + } + writer.close(); + }catch (IOException e){ + e.printStackTrace(); + } + } } From fe6abd3b3acd4fc035a9927c8d4ea4a6178d5ba9 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Mon, 10 Oct 2022 23:06:50 +0900 Subject: [PATCH 052/307] =?UTF-8?q?Project=20Main(HeatMap=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_07/Project/PopulationStatistics.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationStatistics.java b/git/Lion-Java/src/Date10_07/Project/PopulationStatistics.java index 7f72fa3..38e09c9 100644 --- a/git/Lion-Java/src/Date10_07/Project/PopulationStatistics.java +++ b/git/Lion-Java/src/Date10_07/Project/PopulationStatistics.java @@ -1,7 +1,7 @@ package Date10_07.Project; import java.io.IOException; -import java.util.List; + public class PopulationStatistics { public static void main(String[] args) throws IOException { @@ -13,6 +13,11 @@ public static void main(String[] args) throws IOException { // System.out.println(method.ReadByLineParse()); method.CreateFile(); - method.Filewrite(method.ReadByLineParse()); + method.Filewrite(method.ReadByLineParse()); // 파싱한 값 맵핑하여 파일에 저장 + + // heat 차트 작성을 위한 작업 + method.HeatCreateFile(); + method.HeatFilewrite(method.HeatReadByLineParse()); + } } From 34cb162f866fe7a7caee440c28cd38e0b173133f Mon Sep 17 00:00:00 2001 From: qowl880 Date: Mon, 10 Oct 2022 23:07:01 +0900 Subject: [PATCH 053/307] Project Mapping --- git/Lion-Java/src/Date10_07/Project/PopulationMove.java | 1 - 1 file changed, 1 deletion(-) diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationMove.java b/git/Lion-Java/src/Date10_07/Project/PopulationMove.java index 4851d0f..4eba02b 100644 --- a/git/Lion-Java/src/Date10_07/Project/PopulationMove.java +++ b/git/Lion-Java/src/Date10_07/Project/PopulationMove.java @@ -11,7 +11,6 @@ public class PopulationMove { private int fromSido; private int toSido; - String coments; // ReadByLineParse() 메서드에서 파싱한 문자열을 저장할 변수 int num; public PopulationMove(){ From 53535694fc4d29f56d5ed08f39a475cdc8e878c2 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Mon, 10 Oct 2022 23:08:29 +0900 Subject: [PATCH 054/307] =?UTF-8?q?Project=20Method(HeatMap=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_07/Project/PopulationMethod.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java index 5a0736a..7e0fb12 100644 --- a/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java +++ b/git/Lion-Java/src/Date10_07/Project/PopulationMethod.java @@ -7,10 +7,11 @@ import java.util.*; public class PopulationMethod { - static String address = "C:\\Users\\qowhx\\OneDrive\\바탕 화면\\인구\\2021_인구관련연간자료_20221006_47106.csv"; + static String address = "대용량 파일 위치"; - static String saveaddress = "C:\\Users\\qowhx\\AppData\\Roaming\\SPB_Data\\git\\Java-Study\\file.txt"; - static String heatsaveaddress = "C:\\Users\\qowhx\\AppData\\Roaming\\SPB_Data\\git\\Java-Study\\heatfile.txt"; + static String saveaddress = "파싱,맵핑하여 추출한 데이터 저장할 파일 위치"; + static String heatsaveaddress = "HeatMap에 필요한 데이터 저장할 파일 "; + public static void ReadByChar() throws IOException { // 1글자씩 읽기 FileReader fileReader = new FileReader(address); From f976558a8fee614d196c20bcb20c6754111f4b35 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Mon, 10 Oct 2022 23:10:39 +0900 Subject: [PATCH 055/307] Update README.md --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 71a0586..0003096 100644 --- a/README.md +++ b/README.md @@ -33,3 +33,16 @@ https://velog.io/@qowl880/Java-%EB%8C%80%EC%9A%A9%EB%9F%89%EC%B2%98%EB%A6%AC-%ED +## ☁️ 대용량데이터처리 프로젝트(2) +### ➀ 목적 +####    대용량데이터처리 프로젝트(1)에서 추출한 데이터를 Heat Map으로 출력하기 + +### ➁ 진행 순서 +####    1. 대용량 데이터 파일을 다운받음 +####    2. 파일을 읽고 자신이 원하는 값만 추출함 +####    3. 추출한 데이터를 저장할 파일을 생성하고 파일에 데이터를 작성하여 저장함 +####    4. 데이터를 가지고 Heat Map + +### 📗 정리 블로그 +https://velog.io/@qowl880/Java-%EB%8C%80%EC%9A%A9%EB%9F%89%EC%B2%98%EB%A6%AC-%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B82-owien5hj + From 97d4bebfe69d83bbd93249e06023d237733dcc99 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Mon, 10 Oct 2022 23:10:58 +0900 Subject: [PATCH 056/307] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0003096..9701d11 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ https://velog.io/@qowl880/Java-%EB%8C%80%EC%9A%A9%EB%9F%89%EC%B2%98%EB%A6%AC-%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8 +
## ☁️ 대용량데이터처리 프로젝트(2) ### ➀ 목적 From 7353b4f099c987e68e96b4121152a962157666e7 Mon Sep 17 00:00:00 2001 From: qowl880 Date: Tue, 11 Oct 2022 09:20:07 +0900 Subject: [PATCH 057/307] =?UTF-8?q?=EC=9E=90=EB=A6=BF=EC=88=98=20=EB=8D=94?= =?UTF-8?q?=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_11/Algorithm/Programmers_12931.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 git/Lion-Java/src/Date10_11/Algorithm/Programmers_12931.java diff --git a/git/Lion-Java/src/Date10_11/Algorithm/Programmers_12931.java b/git/Lion-Java/src/Date10_11/Algorithm/Programmers_12931.java new file mode 100644 index 0000000..0271bc3 --- /dev/null +++ b/git/Lion-Java/src/Date10_11/Algorithm/Programmers_12931.java @@ -0,0 +1,16 @@ +package Date10_11.Algorithm; + +public class Programmers_12931 { + public static void main(String[] args) { + int num = 123; + + String str = String.valueOf(num); + int result = 0; + + for(int i=0; i Date: Tue, 11 Oct 2022 09:22:17 +0900 Subject: [PATCH 058/307] =?UTF-8?q?=EC=9E=90=EB=A6=BF=EC=88=98=20=EB=8D=94?= =?UTF-8?q?=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_11/Algorithm/Programmers_12931.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/Lion-Java/src/Date10_11/Algorithm/Programmers_12931.java b/git/Lion-Java/src/Date10_11/Algorithm/Programmers_12931.java index 0271bc3..76ba608 100644 --- a/git/Lion-Java/src/Date10_11/Algorithm/Programmers_12931.java +++ b/git/Lion-Java/src/Date10_11/Algorithm/Programmers_12931.java @@ -8,7 +8,7 @@ public static void main(String[] args) { int result = 0; for(int i=0; i Date: Tue, 11 Oct 2022 22:48:37 +0900 Subject: [PATCH 059/307] =?UTF-8?q?=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C(=EA=B0=81=20=EC=9E=90=EB=A6=AC=EC=9D=98?= =?UTF-8?q?=EA=B0=92=20=ED=95=A9=20=EA=B5=AC=ED=95=98=EA=B8=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_11/Algorithm/CodeUp_1278.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 git/Lion-Java/src/Date10_11/Algorithm/CodeUp_1278.java diff --git a/git/Lion-Java/src/Date10_11/Algorithm/CodeUp_1278.java b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp_1278.java new file mode 100644 index 0000000..cf619e3 --- /dev/null +++ b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp_1278.java @@ -0,0 +1,21 @@ +package Date10_11.Algorithm; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class CodeUp_1278 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + int num = Integer.parseInt(bf.readLine()); + int count=0; + + while(num>0){ + num /= 10; + count ++; + } + + System.out.println(count); + } +} From cbb28db3ced7a59c231143a16f5108eda8ee28f5 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 11 Oct 2022 22:54:04 +0900 Subject: [PATCH 060/307] =?UTF-8?q?[CodeUp]=201041=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_11/Algorithm/CodeUp/No_1041.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1041.java diff --git a/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1041.java b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1041.java new file mode 100644 index 0000000..f798936 --- /dev/null +++ b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1041.java @@ -0,0 +1,17 @@ +package Date10_11.Algorithm.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1041 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + char c = bf.readLine().charAt(0); + + int num = (int)c; + + System.out.println((char)(num+1)); + } +} From 4b544267f492f55cc0823a23a3486455d596fd2c Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 11 Oct 2022 22:54:09 +0900 Subject: [PATCH 061/307] =?UTF-8?q?[CodeUp]=201042=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_11/Algorithm/CodeUp/No_1042.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1042.java diff --git a/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1042.java b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1042.java new file mode 100644 index 0000000..70b0800 --- /dev/null +++ b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1042.java @@ -0,0 +1,18 @@ +package Date10_11.Algorithm.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1042 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + String[] str = bf.readLine().split(" "); + + int num1 = Integer.parseInt(str[0]); + int num2 = Integer.parseInt(str[1]); + + System.out.println(num1/num2); + } +} From fd66f9142d3525b7170040dde71adfe8a97fcb3b Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 11 Oct 2022 22:54:14 +0900 Subject: [PATCH 062/307] =?UTF-8?q?[CodeUp]=201043=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1043.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1043.java diff --git a/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1043.java b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1043.java new file mode 100644 index 0000000..12fa4af --- /dev/null +++ b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1043.java @@ -0,0 +1,7 @@ +package Date10_11.Algorithm.CodeUp; + +public class No_1043 { + public static void main(String[] args) { + + } +} From 9c0c3c40720f1b2c8534526887d1be1ffa37d748 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 11 Oct 2022 23:27:34 +0900 Subject: [PATCH 063/307] =?UTF-8?q?[CodeUp]=201043=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_11/Algorithm/CodeUp/No_1043.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1043.java b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1043.java index 12fa4af..efa397a 100644 --- a/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1043.java +++ b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1043.java @@ -1,7 +1,16 @@ package Date10_11.Algorithm.CodeUp; +import java.util.Scanner; + public class No_1043 { public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + String[] str = scan.nextLine().split(" "); + + int num1 = Integer.parseInt(str[0]); + int num2 = Integer.parseInt(str[1]); + System.out.println(num1 % num2); } } From 294baaac3da46d3fd3ba5a5f8709bac5e9bbabe6 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 11 Oct 2022 23:27:39 +0900 Subject: [PATCH 064/307] =?UTF-8?q?[CodeUp]=201044=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_11/Algorithm/CodeUp/No_1044.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1044.java diff --git a/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1044.java b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1044.java new file mode 100644 index 0000000..a121d4d --- /dev/null +++ b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1044.java @@ -0,0 +1,13 @@ +package Date10_11.Algorithm.CodeUp; + +import java.util.Scanner; + +public class No_1044 { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + long num =scan.nextInt(); + + System.out.println(num+1); + } +} From ac4ac2b51173aeb3d09cfcd1384bb163d66d0d90 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 11 Oct 2022 23:27:44 +0900 Subject: [PATCH 065/307] =?UTF-8?q?[CodeUp]=201045=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_11/Algorithm/CodeUp/No_1045.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1045.java diff --git a/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1045.java b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1045.java new file mode 100644 index 0000000..cb36354 --- /dev/null +++ b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1045.java @@ -0,0 +1,23 @@ +package Date10_11.Algorithm.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1045 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + String[] str = bf.readLine().split(" "); + + int num1 = Integer.parseInt(str[0]); + int num2 = Integer.parseInt(str[1]); + + System.out.println(num1 + num2); + System.out.println(num1 - num2); + System.out.println(num1 * num2); + System.out.println(num1 / num2); + System.out.println(num1 % num2); + System.out.printf("%.2f",(float)num1/(float)num2); + } +} From b9e310cc162c5bfd56d853f92272d342223c446c Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 11 Oct 2022 23:27:50 +0900 Subject: [PATCH 066/307] =?UTF-8?q?[CodeUp]=201046=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_11/Algorithm/CodeUp/No_1046.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1046.java diff --git a/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1046.java b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1046.java new file mode 100644 index 0000000..489af11 --- /dev/null +++ b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1046.java @@ -0,0 +1,19 @@ +package Date10_11.Algorithm.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1046 { + public static void main(String[] args) throws IOException { + BufferedReader bf =new BufferedReader(new InputStreamReader(System.in)); + + String[] str = bf.readLine().split(" "); + + int num1 = Integer.parseInt(str[0]); + int num2 = Integer.parseInt(str[1]); + int num3 = Integer.parseInt(str[2]); + System.out.println(num1+num2+num3); + System.out.printf("%.1f",(float)((num1+num2+num3))/str.length); + } +} From 0f14e162746f6284ab88e5ec71dfe4429e8bd486 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 11 Oct 2022 23:28:01 +0900 Subject: [PATCH 067/307] =?UTF-8?q?[CodeUp]=201047=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C(=EB=B9=84=ED=8A=B8=20=EB=8B=A8=EC=9C=84=20=EC=8B=9C?= =?UTF-8?q?=ED=94=84=ED=8A=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_11/Algorithm/CodeUp/No_1047.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1047.java diff --git a/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1047.java b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1047.java new file mode 100644 index 0000000..67f6878 --- /dev/null +++ b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1047.java @@ -0,0 +1,20 @@ +package Date10_11.Algorithm.CodeUp; + +import java.util.Scanner; + +public class No_1047 { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + int num = scan.nextInt(); + + System.out.println(num<<1); + + // 비트 단위 시프트 연산자 + // ex. int a = 10; + // printf("%d", a<<1); //10을 2배 한 값인 20 이 출력된다. + // printf("%d", a>>1); //10을 반으로 나눈 값인 5 가 출력된다. + // printf("%d", a<<2); //10을 4배 한 값인 40 이 출력된다. + // printf("%d", a>>2); //10을 반으로 나눈 후 다시 반으로 나눈 값인 2 가 출력된다. + } +} From 03ab1cf81ea467f92187621cb1bc66a58c839ecd Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 11 Oct 2022 23:28:07 +0900 Subject: [PATCH 068/307] =?UTF-8?q?[CodeUp]=201047=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C(=EB=B9=84=ED=8A=B8=20=EB=8B=A8=EC=9C=84=20=EC=8B=9C?= =?UTF-8?q?=ED=94=84=ED=8A=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_11/Algorithm/CodeUp/No_1048.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1048.java diff --git a/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1048.java b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1048.java new file mode 100644 index 0000000..e54ab40 --- /dev/null +++ b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1048.java @@ -0,0 +1,18 @@ +package Date10_11.Algorithm.CodeUp; + +import java.util.Scanner; + +public class No_1048 { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + String[] str = scan.nextLine().split(" "); + + int num1 = Integer.parseInt(str[0]); + int num2 = Integer.parseInt(str[1]); + + System.out.println(num1< Date: Thu, 13 Oct 2022 08:31:58 +0900 Subject: [PATCH 069/307] =?UTF-8?q?[CodeUp]=201049=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1049.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1049.java diff --git a/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1049.java b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1049.java new file mode 100644 index 0000000..7338247 --- /dev/null +++ b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp/No_1049.java @@ -0,0 +1,7 @@ +package Date10_11.Algorithm.CodeUp; + +public class No_1049 { + public static void main(String[] args) { + + } +} From 49cde6838bf0b774e131afc904f7f1a1c40063e2 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 08:32:32 +0900 Subject: [PATCH 070/307] =?UTF-8?q?[CodeUp]=201620=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C(=EA=B0=81=20=EC=9E=90=EB=A6=AC=EC=9D=98=20=ED=95=A9?= =?UTF-8?q?=20=EA=B5=AC=ED=95=98=EA=B8=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_11/Algorithm/CodeUp_1620.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 git/Lion-Java/src/Date10_11/Algorithm/CodeUp_1620.java diff --git a/git/Lion-Java/src/Date10_11/Algorithm/CodeUp_1620.java b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp_1620.java new file mode 100644 index 0000000..06e4be3 --- /dev/null +++ b/git/Lion-Java/src/Date10_11/Algorithm/CodeUp_1620.java @@ -0,0 +1,22 @@ +package Date10_11.Algorithm; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class CodeUp_1620 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + int num = Integer.parseInt(bf.readLine()); + int result = 0; + + + while(num>0){ + result += num%10; + num /= 10; + } + + System.out.println(result); + } +} From 29609b413e29f62d31c618ac7ef5ffcc568e9620 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 08:32:58 +0900 Subject: [PATCH 071/307] - --- .../Date10_11/Algorithm/Programmers_12931.java | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 git/Lion-Java/src/Date10_11/Algorithm/Programmers_12931.java diff --git a/git/Lion-Java/src/Date10_11/Algorithm/Programmers_12931.java b/git/Lion-Java/src/Date10_11/Algorithm/Programmers_12931.java deleted file mode 100644 index 76ba608..0000000 --- a/git/Lion-Java/src/Date10_11/Algorithm/Programmers_12931.java +++ /dev/null @@ -1,16 +0,0 @@ -package Date10_11.Algorithm; - -public class Programmers_12931 { - public static void main(String[] args) { - int num = 123; - - String str = String.valueOf(num); - int result = 0; - - for(int i=0; i Date: Thu, 13 Oct 2022 09:09:48 +0900 Subject: [PATCH 072/307] - --- .../src/Date10_11/Algorithm/Solution.java | 14 +++++++ git/Lion-Java/src/Date10_12/LineReader.java | 37 +++++++++++++++++++ git/Lion-Java/src/Date10_12/Main.java | 20 ++++++++++ .../src/Date10_12/domain/Hospital.java | 19 ++++++++++ .../src/Date10_12/pasrser/HospitalParser.java | 11 ++++++ .../src/Date10_12/pasrser/Parser.java | 5 +++ 6 files changed, 106 insertions(+) create mode 100644 git/Lion-Java/src/Date10_11/Algorithm/Solution.java create mode 100644 git/Lion-Java/src/Date10_12/LineReader.java create mode 100644 git/Lion-Java/src/Date10_12/Main.java create mode 100644 git/Lion-Java/src/Date10_12/domain/Hospital.java create mode 100644 git/Lion-Java/src/Date10_12/pasrser/HospitalParser.java create mode 100644 git/Lion-Java/src/Date10_12/pasrser/Parser.java diff --git a/git/Lion-Java/src/Date10_11/Algorithm/Solution.java b/git/Lion-Java/src/Date10_11/Algorithm/Solution.java new file mode 100644 index 0000000..3776b82 --- /dev/null +++ b/git/Lion-Java/src/Date10_11/Algorithm/Solution.java @@ -0,0 +1,14 @@ +package Date10_11.Algorithm; + +public class Solution { + public int solution(int n){ + int result = 0; + + while(n>0){ + result += n%10; + + result /= 10; + } + return result; + } +} diff --git a/git/Lion-Java/src/Date10_12/LineReader.java b/git/Lion-Java/src/Date10_12/LineReader.java new file mode 100644 index 0000000..a700631 --- /dev/null +++ b/git/Lion-Java/src/Date10_12/LineReader.java @@ -0,0 +1,37 @@ +package Date10_12; + +import Date10_12.pasrser.Parser; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class LineReader { + Parser parser; + boolean isRemoveColumnName = true; + + public LineReader(Parser parser) { + this.parser = parser; + } + + public LineReader(Parser parser, boolean isRemoveColumnName) { + this.parser = parser; + this.isRemoveColumnName = isRemoveColumnName; + } + + List readLines(String filename) throws IOException { + List result = new ArrayList<>(); + BufferedReader br = new BufferedReader(new FileReader(filename)); + String str; + if (isRemoveColumnName) { + br.readLine(); + } + while ((str = br.readLine()) != null) { + result.add(parser.parse(str)); + } + return result; + } + +} diff --git a/git/Lion-Java/src/Date10_12/Main.java b/git/Lion-Java/src/Date10_12/Main.java new file mode 100644 index 0000000..8686eb6 --- /dev/null +++ b/git/Lion-Java/src/Date10_12/Main.java @@ -0,0 +1,20 @@ +package Date10_12; + +import Date10_12.domain.Hospital; +import Date10_12.pasrser.HospitalParser; + +import java.io.IOException; +import java.util.List; + +public class Main { + public static void main(String[] args) throws IOException { + LineReader hospitalLineReader = new LineReader<>(new HospitalParser()); + String filename = "C:\\Users\\ocean\\Downloads\\서울시 병의원 위치 정보.csv"; + List hospitals = hospitalLineReader.readLines(filename); + + System.out.println(hospitals.size()); + for (Hospital hospital : hospitals) { + System.out.println(hospital.getId()); + } + } +} diff --git a/git/Lion-Java/src/Date10_12/domain/Hospital.java b/git/Lion-Java/src/Date10_12/domain/Hospital.java new file mode 100644 index 0000000..a7b2a0a --- /dev/null +++ b/git/Lion-Java/src/Date10_12/domain/Hospital.java @@ -0,0 +1,19 @@ +package Date10_12.domain; + +public class Hospital { + private String id; + private String address; + private String district; + private String category; + private Integer emergencyRoom; // snake camel + private String name; // snake camel + private String subdivision; // snake camel + + public Hospital(String id) { + this.id = id; + } + + public String getId() { + return id; + } +} \ No newline at end of file diff --git a/git/Lion-Java/src/Date10_12/pasrser/HospitalParser.java b/git/Lion-Java/src/Date10_12/pasrser/HospitalParser.java new file mode 100644 index 0000000..af78724 --- /dev/null +++ b/git/Lion-Java/src/Date10_12/pasrser/HospitalParser.java @@ -0,0 +1,11 @@ +package Date10_12.pasrser; + +import Date10_12.domain.Hospital; + +public class HospitalParser implements Parser{ + @Override + public Hospital parse(String str) { + String[] splitted = str.split(","); + return new Hospital(splitted[0]); + } +} diff --git a/git/Lion-Java/src/Date10_12/pasrser/Parser.java b/git/Lion-Java/src/Date10_12/pasrser/Parser.java new file mode 100644 index 0000000..ee5a7e8 --- /dev/null +++ b/git/Lion-Java/src/Date10_12/pasrser/Parser.java @@ -0,0 +1,5 @@ +package Date10_12.pasrser; + +public interface Parser { + T parse(String str); +} \ No newline at end of file From e9ee51c2d2601d25c6970a4e6c9f9d5a2179e1fb Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 09:49:26 +0900 Subject: [PATCH 073/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20=EB=B2=84=EB=B8=94=EC=A0=95=EB=A0=AC(=EC=9E=91=EC=9D=80?= =?UTF-8?q?=EC=88=98=20=EC=95=9E=EC=9C=BC=EB=A1=9C=20=EB=B3=B4=EB=82=B4?= =?UTF-8?q?=EA=B8=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_13/Algorithm/BubbleSort.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 git/Lion-Java/src/Date10_13/Algorithm/BubbleSort.java diff --git a/git/Lion-Java/src/Date10_13/Algorithm/BubbleSort.java b/git/Lion-Java/src/Date10_13/Algorithm/BubbleSort.java new file mode 100644 index 0000000..3645159 --- /dev/null +++ b/git/Lion-Java/src/Date10_13/Algorithm/BubbleSort.java @@ -0,0 +1,32 @@ +package Date10_13.Algorithm; + + +/* 버블정렬 + (1) swap 자리 바꾸기 + (2) 이중 for문 + (3) 이중 for문 control + +*/ + +import java.util.Arrays; +public class BubbleSort { + + public int[] sort(int[] arr){ + for(int j = 1; jarr[j]){ + int temp = arr[j]; + arr[j] = arr[j-1]; + arr[j-1] = temp; + } + } + return arr; + } + + public static void main(String[] args) { + int[] arr = {7,2,3,9,28,11}; + BubbleSort b = new BubbleSort(); + int[] result = b.sort(arr); + + System.out.println(Arrays.toString(result)); + } +} From 8acd2f78a63849afd06a42aa418b616da7be8f26 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 10:12:07 +0900 Subject: [PATCH 074/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20=EB=B2=84=EB=B8=94=EC=A0=95=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_13/Algorithm/BubbleSort.java | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/git/Lion-Java/src/Date10_13/Algorithm/BubbleSort.java b/git/Lion-Java/src/Date10_13/Algorithm/BubbleSort.java index 3645159..0b05e10 100644 --- a/git/Lion-Java/src/Date10_13/Algorithm/BubbleSort.java +++ b/git/Lion-Java/src/Date10_13/Algorithm/BubbleSort.java @@ -11,22 +11,25 @@ import java.util.Arrays; public class BubbleSort { - public int[] sort(int[] arr){ - for(int j = 1; jarr[j]){ - int temp = arr[j]; - arr[j] = arr[j-1]; - arr[j-1] = temp; + public int[] sort(int[] arr){ + for(int i=1; i arr[j+1]) { + int temp = arr[j]; + arr[j] = arr[j+1]; + arr[j+1] = temp; + } + } + System.out.println(Arrays.toString(arr)); } + return arr; } - return arr; - } - public static void main(String[] args) { - int[] arr = {7,2,3,9,28,11}; - BubbleSort b = new BubbleSort(); - int[] result = b.sort(arr); + public static void main(String[] args) { + int[] arr = {7,2,3,9,28,11}; + BubbleSort b = new BubbleSort(); + int[] result = b.sort(arr); - System.out.println(Arrays.toString(result)); - } + System.out.println(Arrays.toString(result)); + } } From 9bafdcbb0912397fe51e7256fb2c557753ff6446 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Thu, 13 Oct 2022 10:21:57 +0900 Subject: [PATCH 075/307] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 9701d11..7995c9f 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,12 @@ - 2022-10-06 : List/Set/Map + File(파일 입출력) - 2022-10-07 : Project(대용량데이터처리) + +- 2022-10-11 : Aws + docker + Mysql 연결 + +- 2022-10-12 : 알고리즘[max,min 구하기] + 대용량 파일 처리 + +- 2022-10-13 : 알고리즘[버블정렬]
From 46b8a28b56d3f4a9a43a07dbd623cce382317cda Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 11:45:46 +0900 Subject: [PATCH 076/307] out --- .../classes/Date10_12/LineReader.class | Bin 0 -> 1782 bytes lion/out/production/classes/Date10_12/Main.class | Bin 0 -> 1568 bytes .../classes/Date10_12/domain/Hospital.class | Bin 0 -> 2109 bytes .../Date10_12/pasrser/HospitalParser.class | Bin 0 -> 914 bytes .../classes/Date10_12/pasrser/Parser.class | Bin 0 -> 265 bytes .../Date10_12/pasrser/HospitalParserTest.class | Bin 0 -> 1630 bytes 6 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 lion/out/production/classes/Date10_12/LineReader.class create mode 100644 lion/out/production/classes/Date10_12/Main.class create mode 100644 lion/out/production/classes/Date10_12/domain/Hospital.class create mode 100644 lion/out/production/classes/Date10_12/pasrser/HospitalParser.class create mode 100644 lion/out/production/classes/Date10_12/pasrser/Parser.class create mode 100644 lion/out/test/classes/Date10_12/pasrser/HospitalParserTest.class diff --git a/lion/out/production/classes/Date10_12/LineReader.class b/lion/out/production/classes/Date10_12/LineReader.class new file mode 100644 index 0000000000000000000000000000000000000000..9360de0192e128ca0195b4215366d6a9bbb0f0f2 GIT binary patch literal 1782 zcma)7*-{fh6g@o|m?T8hki;m;qNqt&B8nS9Trju=u!Pcr7i&lc91KZnGO_f<|L_ZZ z)hd-zs(kdp&#?Rqx6?C|g(X!!LE->a`&MX=8warz-TGCgG^n`Qeyk2~)Tc%ulPSt*9Rs~`$oHFo{p%)B` zdSW|+URCOWz57Pg(>U2)qzjQs``UvtD-v+3J-}sgPyvf#rD*0cl*n!9FZ6U#FRiB+ zZObgJXOga~W}C%y&aB$Z%D-k7jgnK_@ZJCx+cK)PqAhS}Z>+M)j>lcUSx(=ot*sfB zQD{`mSG5U)3WqevUVH@ z$GazSj#qs{(!0Epa#or7414fjKMfLsW3m=}mNUz+B~vE&Yq(?B;Df$pXfS40cO zZE{^Lb=_NN6jQ*LkaHB>ublMvcz#BC?UQJ~<;@c%CcNQkohNp`seI?_F3{oJ2?A&K zJ959C`1C?ymqM?F$rTLpR_f+erSQj|K;W>m3e&Ptv_ATxh!JswtLJ<=*whw8O8p2W zHT)62_YN>l8|L*UsZpE*DI!i${gg69JB9(w@Niky3HRVeGFhA=h9kyr$!VNn zvEmrTStKZRn5ZOo)s_UaUV<(@Mf@;X4@3ElAq^uMI)9;0BgGiqDv8tHfSe=L9hGsM J=bnNK{{U|*g*E^H literal 0 HcmV?d00001 diff --git a/lion/out/production/classes/Date10_12/Main.class b/lion/out/production/classes/Date10_12/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..cf8c688e6ef013c49e31b74385b8a4a8827121eb GIT binary patch literal 1568 zcmah}-BJ`s7(Knr()%;81aKoUM3R_fQD6l%MnFsejhpNOx`qTLMKwzcqq{R(GqaZF zP4Wa@>jjjt%F1Mi|Ov~_k8F3y8n9j#~T1w@oNf$n31?7aXEz^ z%%l**l?1*v>(wN_!L>9dFq^_0=FRSU8k1NszZ(+YrqGY?jBZh4Nn%-`ciwTGa6zCa zH@+@lEqOayAX9W)z0#;{YyY0wu2M2s^eU>lu6)Ow4~15^=L7-+#bp)h>5E&_Gx?Ho z+&RXnaTUns9uyy`Cn{f6?ry#u`i{FhXYwTWyrAxcsw!}%%X`N&e)-#nN)t%=yG${3 zLL7o>MKN&iYPF+%=In~skuy}{p;OhaszufO2bDmw6)h?$GH8TOHD7dsknY)|3_Pp1 zSh#dz!uc-g@v;^eZn8;CJH!9k_mx9cd0bNUh!IVhfy8Z| z%U;8;=v%CpWto;tnR09lVOU_e)2$9a0%IL~m?3jB z&|agu)#7c-aUXhqO&K6lmEehuAMm3@(MAa?Hde7FamU78lx^I@Pd3)^vyES{Au!TO zevB*|_wm3uZ3^^vtV~gyyiOZew;$L z90st+dPML3`bvf$Bsbit<`FO`A&P&83E=WvBzTxS8ga2iStEBU!rj}GCH7e$jed*Uo z-BfugX~1JIJRak`IbbhcR#zu~9(E(=yCL-gdc!^HHRYDAI2b?A>aKbt12<4MFo`Jx z(@I=Z;$0hYw&`mz4i|c>EDa%6$5VVKkQPNDaIIq<%Bt(|6F;~81Fk&Za(w=#2Seau zah*Fzst8&VrIq*)!H({Je=E==W>WKZ-!gem!}sbbe-N0vcrM#Hb`ND#=ph?hR?}xu zYk1Cbt-J2wQCGmIIgadA+m`1^QuIeWn+PNPLfe+pYD;e}ycmDah__f^moDy{bT2)B zWFCLU@NZS(e<6aXTJ3hj_GLxGj{@_F{D#FQaP$A|aGM=cwMq>sRb^bIRG|ekYa^Ih zbHU8A3uYEwFtY+VXW3qF;62Kl+->oGinDJ14Ph?#k@_>Ry+t{JH03xlT#X`+B6n9q zYsOLHj`xBnSii)4Kf-)T8;xh?0MlIQBW>R4BV*2t^f6*iXZpyRGub{g^Ax!Yp9}N^ zW|$%FDC3@Bc9Zlv!%lLGjbxsyCH9gct+qoigILTc7J3diQF)oF0|j}Qssj;M=@c^~ z!AfzX7?~q-$jE(Kvo*mm|3a!TTF_51_LBP){fF#<>=l(oXczexSQxOnL2Knb`x>Kq zpuJ7sr5KypK?d0Yo9vNMJiClpVa+n0bip{qc->r1uPpL6ESc>n&px&iPG4I4!~E8@A07kFu*Y9o&|8y40ryt44x z!W)8lAOoom2}Z5nCgeYaJ&&-^l!5ncc-rxzW6|-sQf`J_;kQL3b)FXU>bHyu>&=fs zdAmEmcK6(Yh@;qx+|OY=kV^R9g--Vgg@L{i+*PZ{@A_;lRdy0&QE^aIlFQVRgLD8A%PUJ9vaLp*lw0 zS(=t7lx7Ddtjx2LL8j2jf8n1t+Am=QelcZtF|R}&?h zBe=1}O|@DzVWeuzMFo#p&tgl9SVFG!o;xh39d?+l`DSD50_IqC-k+H&=CCsAy^1HJ G`1BSV`OXml literal 0 HcmV?d00001 diff --git a/lion/out/production/classes/Date10_12/pasrser/Parser.class b/lion/out/production/classes/Date10_12/pasrser/Parser.class new file mode 100644 index 0000000000000000000000000000000000000000..dc2164f7cacf0de1fa3d0045c7c0df543053dd80 GIT binary patch literal 265 zcmX^0Z`VEs1_pBm9(D#Ub_Q-n2G)YaqT*CW1~mYfU5} z|D>$c>3jnQ)o+HSlrUuZEWA2?VQ~pq^RMgk|~H*k@$oz$tk_av5kGM z#J2?8(8Li0$!X$ZSE*Vx4funTI?e?GKY*WdxAzwiv$jK03WSqx=VhOHW_GkYzyI;` zZvY^H-~=a}wZofEu)$de5GLPpfY%A<;Jg#wh6{GMXa^q$z3-?gReP6%E}wsdgYK*8 zafJhSLQN^x^HZZr_NF|VM2{zt9+Q(Ja#m$_$JwpjQga+!NDRxGBJiIJVkjf$vN`3i3eD=T==5XMRTf!Yp+795@&O-@x9sl?eGa|mqXk2+8;xm#XQ5>s_eA`y z*;RVKM60`mZvI5qbovOjJH?J>RT^}yz@R)IHSZLN*_^ftb%IXh!;aLfas|n)rLysC zm#!AfnvNzRZPl#pnonwUhb1T0>=u1ewPqUVGK+JVuS}aIV{4JFE_EPulT}8W>&E6f zo|jmaidlS&_%@0V^T%~-`7YzU*D!XTnl&W*)~r`LA|J6nDjdUvZmjk-cpVcQ XN0b}o36= Date: Thu, 13 Oct 2022 11:57:27 +0900 Subject: [PATCH 077/307] first commit --- lion/build.gradle | 19 ++++ lion/gradlew | 234 +++++++++++++++++++++++++++++++++++++++++++ lion/gradlew.bat | 89 ++++++++++++++++ lion/settings.gradle | 2 + 4 files changed, 344 insertions(+) create mode 100644 lion/build.gradle create mode 100644 lion/gradlew create mode 100644 lion/gradlew.bat create mode 100644 lion/settings.gradle diff --git a/lion/build.gradle b/lion/build.gradle new file mode 100644 index 0000000..3cae2d7 --- /dev/null +++ b/lion/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'java' +} + +group 'org.example' +version '1.0-SNAPSHOT' + +repositories { + mavenCentral() +} + +dependencies { + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/lion/gradlew b/lion/gradlew new file mode 100644 index 0000000..1b6c787 --- /dev/null +++ b/lion/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/lion/gradlew.bat b/lion/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/lion/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/lion/settings.gradle b/lion/settings.gradle new file mode 100644 index 0000000..3d0cdf1 --- /dev/null +++ b/lion/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'lion' + From de59b7dca16735f0513dc12010db5bc3770e42e7 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 11:57:42 +0900 Subject: [PATCH 078/307] main --- lion/src/main/java/Date10_12/Main.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lion/src/main/java/Date10_12/Main.java diff --git a/lion/src/main/java/Date10_12/Main.java b/lion/src/main/java/Date10_12/Main.java new file mode 100644 index 0000000..e3e5fe6 --- /dev/null +++ b/lion/src/main/java/Date10_12/Main.java @@ -0,0 +1,20 @@ +package Date10_12; + +import Date10_12.domain.Hospital; +import Date10_12.pasrser.HospitalParser; + +import java.io.IOException; +import java.util.List; + +public class Main { + public static void main(String[] args) throws IOException { + LineReader hospitalLineReader = new LineReader<>(new HospitalParser()); + String filename = "C:\\DB file\\seoul_hospital_information.csv"; + List hospitals = hospitalLineReader.readLines(filename); + + System.out.println(hospitals.size()); + for (Hospital hospital : hospitals) { + System.out.println(hospital.getId()); + } + } +} From ac6c53befb9fc49e5f8218fe4bdf981f03e6cd37 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 11:57:54 +0900 Subject: [PATCH 079/307] parser(interface) --- lion/src/main/java/Date10_12/pasrser/Parser.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 lion/src/main/java/Date10_12/pasrser/Parser.java diff --git a/lion/src/main/java/Date10_12/pasrser/Parser.java b/lion/src/main/java/Date10_12/pasrser/Parser.java new file mode 100644 index 0000000..ee5a7e8 --- /dev/null +++ b/lion/src/main/java/Date10_12/pasrser/Parser.java @@ -0,0 +1,5 @@ +package Date10_12.pasrser; + +public interface Parser { + T parse(String str); +} \ No newline at end of file From 518131eefaed6f6c88700b6715527b6ad36e9db9 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 11:58:01 +0900 Subject: [PATCH 080/307] testcase --- .../Date10_12/pasrser/HospitalParserTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java diff --git a/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java b/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java new file mode 100644 index 0000000..f58238e --- /dev/null +++ b/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java @@ -0,0 +1,17 @@ +package Date10_12.pasrser; + +import Date10_12.domain.Hospital; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class HospitalParserTest { + @Test + @DisplayName("ID가 파싱이 잘 되는지") + void idParsing() { + HospitalParser hospitalParser = new HospitalParser(); + Hospital hospital = hospitalParser.parse("\"A1120837\",\"서울특별시 송파구 동남로 208 (가락동)\",\"C\",\"의원\",\"G099\",\"응급의료기관 이외\",\"2\",\"토요일 첫째주 셋째주 휴진\",\"2005년 부터 진료 재활의학과전문의 전문물리치료 통증클리닉 척추교정치료 체외충격파 휜다리교정 목허리어깨무릎발 통증 디스크 퇴행성관절염\",\"극동아파트상가204호\",\"연세정소아과의원\",\"02-448-6436\",\"02-2227-7777\",\"1900\",\"1900\",\"1900\",\"1900\",\"1900\",\"1500\",\"1400\",\"1600\",\"0900\",\"0900\",\"0900\",\"0900\",\"0900\",\"0900\",\"1000\",\"0900\",\"057\",\"83\",\"127.13147131787721\",\"37.49579508152157\",\"2022-09-07 14:55:30.0\""); + Assertions.assertEquals("A1120837", hospital.getId()); + + } +} \ No newline at end of file From 4d0ba4873bb79357398f714d1d9bc9bf21e5ca1e Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 11:58:11 +0900 Subject: [PATCH 081/307] parser --- .../main/java/Date10_12/pasrser/HospitalParser.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 lion/src/main/java/Date10_12/pasrser/HospitalParser.java diff --git a/lion/src/main/java/Date10_12/pasrser/HospitalParser.java b/lion/src/main/java/Date10_12/pasrser/HospitalParser.java new file mode 100644 index 0000000..992d0e6 --- /dev/null +++ b/lion/src/main/java/Date10_12/pasrser/HospitalParser.java @@ -0,0 +1,12 @@ +package Date10_12.pasrser; + +import Date10_12.domain.Hospital; + +// 클래스에서 alt+enter를 눌러 테스트를 할 수 있다. +public class HospitalParser implements Parser{ + @Override + public Hospital parse(String str) { + String[] splitted = str.split(","); + return new Hospital(splitted[0]); + } +} From 0d5270f843befd00cb068df9cca0d8064a6ff144 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 11:58:24 +0900 Subject: [PATCH 082/307] filereader --- lion/src/main/java/Date10_12/LineReader.java | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 lion/src/main/java/Date10_12/LineReader.java diff --git a/lion/src/main/java/Date10_12/LineReader.java b/lion/src/main/java/Date10_12/LineReader.java new file mode 100644 index 0000000..a700631 --- /dev/null +++ b/lion/src/main/java/Date10_12/LineReader.java @@ -0,0 +1,37 @@ +package Date10_12; + +import Date10_12.pasrser.Parser; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class LineReader { + Parser parser; + boolean isRemoveColumnName = true; + + public LineReader(Parser parser) { + this.parser = parser; + } + + public LineReader(Parser parser, boolean isRemoveColumnName) { + this.parser = parser; + this.isRemoveColumnName = isRemoveColumnName; + } + + List readLines(String filename) throws IOException { + List result = new ArrayList<>(); + BufferedReader br = new BufferedReader(new FileReader(filename)); + String str; + if (isRemoveColumnName) { + br.readLine(); + } + while ((str = br.readLine()) != null) { + result.add(parser.parse(str)); + } + return result; + } + +} From 99a0adb4b67c46a56be34b00884b314b769d688a Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 11:58:35 +0900 Subject: [PATCH 083/307] hospital --- .../main/java/Date10_12/domain/Hospital.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 lion/src/main/java/Date10_12/domain/Hospital.java diff --git a/lion/src/main/java/Date10_12/domain/Hospital.java b/lion/src/main/java/Date10_12/domain/Hospital.java new file mode 100644 index 0000000..484d35b --- /dev/null +++ b/lion/src/main/java/Date10_12/domain/Hospital.java @@ -0,0 +1,49 @@ +package Date10_12.domain; + +public class Hospital { + private String id; + private String address; //주소 + private String district; //구 + private String category; //카테고리 + private String name; //병원명 + private String subDivision; //세부분과 + private int emergencyRoom; //응급 운영 현황 + + + public Hospital(String id){ + this.id = id; + // this.id = id.replaceAll("\"",""); 파일에서 가져온 데이터는 "정보"가 되어 있으므로 ""를 제거해 준다. + } + + public Hospital(String id, String address, String category, int emergencyRoom, + String name, String subDivision){ + this.id = id; + this.address = address; + this.category = category; + this.name = name; + this.emergencyRoom = emergencyRoom; + this.subDivision = subDivision; + this.setDistrict(); + } + + public String getId() { + return id.replace("\"", ""); + } + + public void setId(String id) { + this.id = id; + } + + public void setDistrict() { + String[] address = this.address.split(" "); + this.district = address[0] + " " + address[1]; + } + + @Override + public String toString() { + return "\"" + this.id + "\"" + "," + "\"" + this.address + "\"" + "," + "\"" + + this.district + "\"" + "," + "\"" + this.category + "\"" + "," + this.emergencyRoom + "," + "\"" + + this.name + "\"" + "," + this.subDivision; + } + +} \ No newline at end of file From 9b4ce9d3f8ff452f620c93087bec35d735c029fb Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 13:14:15 +0900 Subject: [PATCH 084/307] =?UTF-8?q?hospital(address=20=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/Date10_12/domain/Hospital.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/lion/src/main/java/Date10_12/domain/Hospital.java b/lion/src/main/java/Date10_12/domain/Hospital.java index 484d35b..a1c4759 100644 --- a/lion/src/main/java/Date10_12/domain/Hospital.java +++ b/lion/src/main/java/Date10_12/domain/Hospital.java @@ -9,6 +9,10 @@ public class Hospital { private String subDivision; //세부분과 private int emergencyRoom; //응급 운영 현황 + public Hospital(String id, String address) { + this.id = id; + this.address = address; + } public Hospital(String id){ this.id = id; @@ -30,10 +34,31 @@ public String getId() { return id.replace("\"", ""); } - public void setId(String id) { - this.id = id; + public String getAddress() { + return address; + } + + public String getDistrict() { + return district; + } + + public String getCategory() { + return category; } + public String getName() { + return name; + } + + public String getSubDivision() { + return subDivision; + } + + public int getEmergencyRoom() { + return emergencyRoom; + } + + public void setDistrict() { String[] address = this.address.split(" "); this.district = address[0] + " " + address[1]; From 8fc867150d2bc11219be96096fe2d53dfe9dbd50 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 13:14:45 +0900 Subject: [PATCH 085/307] =?UTF-8?q?Parser(""=EC=A0=9C=EA=B1=B0,=20address?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lion/src/main/java/Date10_12/pasrser/HospitalParser.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lion/src/main/java/Date10_12/pasrser/HospitalParser.java b/lion/src/main/java/Date10_12/pasrser/HospitalParser.java index 992d0e6..887862f 100644 --- a/lion/src/main/java/Date10_12/pasrser/HospitalParser.java +++ b/lion/src/main/java/Date10_12/pasrser/HospitalParser.java @@ -4,9 +4,14 @@ // 클래스에서 alt+enter를 눌러 테스트를 할 수 있다. public class HospitalParser implements Parser{ + + private String replaceAll(String str){ // " " 제거 + return str.replaceAll("\"",""); + } + @Override public Hospital parse(String str) { String[] splitted = str.split(","); - return new Hospital(splitted[0]); + return new Hospital(replaceAll(splitted[0]),replaceAll(splitted[1])); } } From e78c90d664a3ab5a92143791177d5847eb9b2dff Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 13:15:01 +0900 Subject: [PATCH 086/307] =?UTF-8?q?testcase(address=20=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/Date10_12/pasrser/HospitalParserTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java b/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java index f58238e..292471b 100644 --- a/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java +++ b/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java @@ -6,12 +6,17 @@ import org.junit.jupiter.api.Test; class HospitalParserTest { + + String str = "\"A1120837\",\"서울특별시 송파구 동남로 208 (가락동)\",\"C\",\"의원\",\"G099\",\"응급의료기관 이외\",\"2\",\"토요일 첫째주 셋째주 휴진\",\"2005년 부터 진료 재활의학과전문의 전문물리치료 통증클리닉 척추교정치료 체외충격파 휜다리교정 목허리어깨무릎발 통증 디스크 퇴행성관절염\",\"극동아파트상가204호\",\"연세정소아과의원\",\"02-448-6436\",\"02-2227-7777\",\"1900\",\"1900\",\"1900\",\"1900\",\"1900\",\"1500\",\"1400\",\"1600\",\"0900\",\"0900\",\"0900\",\"0900\",\"0900\",\"0900\",\"1000\",\"0900\",\"057\",\"83\",\"127.13147131787721\",\"37.49579508152157\",\"2022-09-07 14:55:30.0\""; @Test @DisplayName("ID가 파싱이 잘 되는지") void idParsing() { HospitalParser hospitalParser = new HospitalParser(); - Hospital hospital = hospitalParser.parse("\"A1120837\",\"서울특별시 송파구 동남로 208 (가락동)\",\"C\",\"의원\",\"G099\",\"응급의료기관 이외\",\"2\",\"토요일 첫째주 셋째주 휴진\",\"2005년 부터 진료 재활의학과전문의 전문물리치료 통증클리닉 척추교정치료 체외충격파 휜다리교정 목허리어깨무릎발 통증 디스크 퇴행성관절염\",\"극동아파트상가204호\",\"연세정소아과의원\",\"02-448-6436\",\"02-2227-7777\",\"1900\",\"1900\",\"1900\",\"1900\",\"1900\",\"1500\",\"1400\",\"1600\",\"0900\",\"0900\",\"0900\",\"0900\",\"0900\",\"0900\",\"1000\",\"0900\",\"057\",\"83\",\"127.13147131787721\",\"37.49579508152157\",\"2022-09-07 14:55:30.0\""); + Hospital hospital = hospitalParser.parse(str); + + String address = "서울특별시 송파구 동남로 208 (가락동)"; Assertions.assertEquals("A1120837", hospital.getId()); + Assertions.assertEquals(address,hospital.getAddress()); } } \ No newline at end of file From f4081c691db4429c4061ee510f9fb81007617e5f Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 13:43:00 +0900 Subject: [PATCH 087/307] =?UTF-8?q?testcase(district=20=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java b/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java index 292471b..8d915ce 100644 --- a/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java +++ b/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java @@ -6,7 +6,6 @@ import org.junit.jupiter.api.Test; class HospitalParserTest { - String str = "\"A1120837\",\"서울특별시 송파구 동남로 208 (가락동)\",\"C\",\"의원\",\"G099\",\"응급의료기관 이외\",\"2\",\"토요일 첫째주 셋째주 휴진\",\"2005년 부터 진료 재활의학과전문의 전문물리치료 통증클리닉 척추교정치료 체외충격파 휜다리교정 목허리어깨무릎발 통증 디스크 퇴행성관절염\",\"극동아파트상가204호\",\"연세정소아과의원\",\"02-448-6436\",\"02-2227-7777\",\"1900\",\"1900\",\"1900\",\"1900\",\"1900\",\"1500\",\"1400\",\"1600\",\"0900\",\"0900\",\"0900\",\"0900\",\"0900\",\"0900\",\"1000\",\"0900\",\"057\",\"83\",\"127.13147131787721\",\"37.49579508152157\",\"2022-09-07 14:55:30.0\""; @Test @DisplayName("ID가 파싱이 잘 되는지") @@ -18,5 +17,7 @@ void idParsing() { Assertions.assertEquals("A1120837", hospital.getId()); Assertions.assertEquals(address,hospital.getAddress()); + String district = "서울특별시 송파구"; + Assertions.assertEquals(district,hospital.getDistrict()); } } \ No newline at end of file From 7634b610a1b7cc466885ae86409c0ae067f99cbd Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 13:43:33 +0900 Subject: [PATCH 088/307] =?UTF-8?q?Hospital(district=20set=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/Date10_12/domain/Hospital.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lion/src/main/java/Date10_12/domain/Hospital.java b/lion/src/main/java/Date10_12/domain/Hospital.java index a1c4759..2185b45 100644 --- a/lion/src/main/java/Date10_12/domain/Hospital.java +++ b/lion/src/main/java/Date10_12/domain/Hospital.java @@ -1,24 +1,29 @@ package Date10_12.domain; public class Hospital { - private String id; - private String address; //주소 - private String district; //구 - private String category; //카테고리 - private String name; //병원명 - private String subDivision; //세부분과 - private int emergencyRoom; //응급 운영 현황 + private String id; // [0] + private String address; //주소 [1] + private String district; //구 [1]수정 + private String category; //카테고리 [2] + private String name; //병원명 [10] + private String subDivision; //세부분과 [10] 수정 + private int emergencyRoom; //응급 운영 현황 [6] - public Hospital(String id, String address) { + public Hospital(String id, String address, String category, String name, String subDivision, int emergencyRoom) { this.id = id; this.address = address; + this.category = category; + this.name = name; + this.subDivision = subDivision; + this.emergencyRoom = emergencyRoom; } - public Hospital(String id){ + public Hospital(String id, String address) { this.id = id; - // this.id = id.replaceAll("\"",""); 파일에서 가져온 데이터는 "정보"가 되어 있으므로 ""를 제거해 준다. + this.address = address; } + public Hospital(String id, String address, String category, int emergencyRoom, String name, String subDivision){ this.id = id; From 6f0ea94cb7afc009d389187452a9b191cd40eace Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 13:44:05 +0900 Subject: [PATCH 089/307] =?UTF-8?q?HospitalParser(district=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lion/src/main/java/Date10_12/pasrser/HospitalParser.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lion/src/main/java/Date10_12/pasrser/HospitalParser.java b/lion/src/main/java/Date10_12/pasrser/HospitalParser.java index 887862f..26a1cdb 100644 --- a/lion/src/main/java/Date10_12/pasrser/HospitalParser.java +++ b/lion/src/main/java/Date10_12/pasrser/HospitalParser.java @@ -5,13 +5,12 @@ // 클래스에서 alt+enter를 눌러 테스트를 할 수 있다. public class HospitalParser implements Parser{ - private String replaceAll(String str){ // " " 제거 - return str.replaceAll("\"",""); - } @Override public Hospital parse(String str) { + str = str.replaceAll("\"",""); // "" 제거 String[] splitted = str.split(","); - return new Hospital(replaceAll(splitted[0]),replaceAll(splitted[1])); + + return new Hospital(splitted[0],splitted[1],splitted[2],Integer.parseInt(splitted[6]),splitted[4],splitted[5]); } } From d0cfae6e68f093b083165047dca0be235f36b828 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 14:22:06 +0900 Subject: [PATCH 090/307] =?UTF-8?q?HospitalParser(category,emergency,name?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lion/src/main/java/Date10_12/pasrser/HospitalParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lion/src/main/java/Date10_12/pasrser/HospitalParser.java b/lion/src/main/java/Date10_12/pasrser/HospitalParser.java index 26a1cdb..ee6524c 100644 --- a/lion/src/main/java/Date10_12/pasrser/HospitalParser.java +++ b/lion/src/main/java/Date10_12/pasrser/HospitalParser.java @@ -11,6 +11,6 @@ public Hospital parse(String str) { str = str.replaceAll("\"",""); // "" 제거 String[] splitted = str.split(","); - return new Hospital(splitted[0],splitted[1],splitted[2],Integer.parseInt(splitted[6]),splitted[4],splitted[5]); + return new Hospital(splitted[0],splitted[1],splitted[2],Integer.parseInt(splitted[6]),splitted[10]); } } From 7669543bd26ae0e315a170fa2f665d3639109db9 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 14:22:14 +0900 Subject: [PATCH 091/307] =?UTF-8?q?TestCase(category,emergency,name=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date10_12/pasrser/HospitalParserTest.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java b/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java index 8d915ce..ca105b4 100644 --- a/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java +++ b/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test; class HospitalParserTest { - String str = "\"A1120837\",\"서울특별시 송파구 동남로 208 (가락동)\",\"C\",\"의원\",\"G099\",\"응급의료기관 이외\",\"2\",\"토요일 첫째주 셋째주 휴진\",\"2005년 부터 진료 재활의학과전문의 전문물리치료 통증클리닉 척추교정치료 체외충격파 휜다리교정 목허리어깨무릎발 통증 디스크 퇴행성관절염\",\"극동아파트상가204호\",\"연세정소아과의원\",\"02-448-6436\",\"02-2227-7777\",\"1900\",\"1900\",\"1900\",\"1900\",\"1900\",\"1500\",\"1400\",\"1600\",\"0900\",\"0900\",\"0900\",\"0900\",\"0900\",\"0900\",\"1000\",\"0900\",\"057\",\"83\",\"127.13147131787721\",\"37.49579508152157\",\"2022-09-07 14:55:30.0\""; + String str = "\"A1120837\",\"서울특별시 송파구 동남로 208 (가락동)\",\"A\",\"의원\",\"G099\",\"응급의료기관 이외\",\"1\",\"토요일 첫째주 셋째주 휴진\",\"2005년 부터 진료 재활의학과전문의 전문물리치료 통증클리닉 척추교정치료 체외충격파 휜다리교정 목허리어깨무릎발 통증 디스크 퇴행성관절염\",\"극동아파트상가204호\",\"연세정소아과의원\",\"02-448-6436\",\"02-2227-7777\",\"1900\",\"1900\",\"1900\",\"1900\",\"1900\",\"1500\",\"1400\",\"1600\",\"0900\",\"0900\",\"0900\",\"0900\",\"0900\",\"0900\",\"1000\",\"0900\",\"057\",\"83\",\"127.13147131787721\",\"37.49579508152157\",\"2022-09-07 14:55:30.0\""; @Test @DisplayName("ID가 파싱이 잘 되는지") void idParsing() { @@ -19,5 +19,15 @@ void idParsing() { String district = "서울특별시 송파구"; Assertions.assertEquals(district,hospital.getDistrict()); + + String category = "종합병원"; + Assertions.assertEquals(category,hospital.getCategory()); + + String emergency = "운영중"; + Assertions.assertEquals(emergency,hospital.getEmergencyRoom()); + + String name = "연세정소아과의원"; + Assertions.assertEquals(name,hospital.getName()); + } } \ No newline at end of file From cf71fad11e4955ecd8e2a1634bdf3d473c40f322 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 14:22:30 +0900 Subject: [PATCH 092/307] =?UTF-8?q?Hospital(category,emergency,name=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/Date10_12/domain/Hospital.java | 63 ++++++++++++------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/lion/src/main/java/Date10_12/domain/Hospital.java b/lion/src/main/java/Date10_12/domain/Hospital.java index 2185b45..2bebcc1 100644 --- a/lion/src/main/java/Date10_12/domain/Hospital.java +++ b/lion/src/main/java/Date10_12/domain/Hospital.java @@ -1,5 +1,8 @@ package Date10_12.domain; +import java.util.HashMap; +import java.util.Map; + public class Hospital { private String id; // [0] private String address; //주소 [1] @@ -9,23 +12,8 @@ public class Hospital { private String subDivision; //세부분과 [10] 수정 private int emergencyRoom; //응급 운영 현황 [6] - public Hospital(String id, String address, String category, String name, String subDivision, int emergencyRoom) { - this.id = id; - this.address = address; - this.category = category; - this.name = name; - this.subDivision = subDivision; - this.emergencyRoom = emergencyRoom; - } - - public Hospital(String id, String address) { - this.id = id; - this.address = address; - } - - public Hospital(String id, String address, String category, int emergencyRoom, - String name, String subDivision){ + String name){ this.id = id; this.address = address; this.category = category; @@ -33,6 +21,7 @@ public Hospital(String id, String address, String category, int emergencyRoom, this.emergencyRoom = emergencyRoom; this.subDivision = subDivision; this.setDistrict(); + this.setCategory(); } public String getId() { @@ -43,14 +32,48 @@ public String getAddress() { return address; } + + public void setDistrict() { + String[] address = this.address.split(" "); + this.district = address[0] + " " + address[1]; + } + public String getDistrict() { return district; } + public void setCategory() { // 맵핑 + Map categorytmap = new HashMap<>(); + categorytmap.put("A","종합병원"); + categorytmap.put("B","병원"); + categorytmap.put("C","의원"); + categorytmap.put("D","요양병원"); + categorytmap.put("E","한방병원"); + categorytmap.put("G","한의원"); + categorytmap.put("I","기타"); + categorytmap.put("M","치과병원"); + categorytmap.put("N","치과의원"); + categorytmap.put("R","보건소"); + categorytmap.put("W","기타(구급차)"); + + category = categorytmap.get(category); + } + public String getCategory() { return category; } + public String setEmergencyRoom() { + if(emergencyRoom == 1){ + return "운영중"; + }else + return "운영안함"; + } + + public String getEmergencyRoom() { + return setEmergencyRoom(); + } + public String getName() { return name; } @@ -59,15 +82,9 @@ public String getSubDivision() { return subDivision; } - public int getEmergencyRoom() { - return emergencyRoom; - } - public void setDistrict() { - String[] address = this.address.split(" "); - this.district = address[0] + " " + address[1]; - } + @Override public String toString() { From fb5a8cc039436daea23dddc7e6dffa7dd679f67a Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 14:37:14 +0900 Subject: [PATCH 093/307] =?UTF-8?q?Hospital(subDivision=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/Date10_12/domain/Hospital.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lion/src/main/java/Date10_12/domain/Hospital.java b/lion/src/main/java/Date10_12/domain/Hospital.java index 2bebcc1..8c1b67a 100644 --- a/lion/src/main/java/Date10_12/domain/Hospital.java +++ b/lion/src/main/java/Date10_12/domain/Hospital.java @@ -9,9 +9,10 @@ public class Hospital { private String district; //구 [1]수정 private String category; //카테고리 [2] private String name; //병원명 [10] - private String subDivision; //세부분과 [10] 수정 + private String subDivision=""; //세부분과 [10] 수정 private int emergencyRoom; //응급 운영 현황 [6] + public Hospital(String id, String address, String category, int emergencyRoom, String name){ this.id = id; @@ -19,9 +20,9 @@ public Hospital(String id, String address, String category, int emergencyRoom, this.category = category; this.name = name; this.emergencyRoom = emergencyRoom; - this.subDivision = subDivision; this.setDistrict(); this.setCategory(); + this.setSubdivision(); } public String getId() { @@ -78,6 +79,20 @@ public String getName() { return name; } + private void setSubdivision(){ + String[] subdivisionList = new String[]{ + "치과", "성형외과", "한방병원", "한의원", "영상의학과", "이비인후과", "소아청소년과", "내과", "정형외과", "외과", + "가정의학과","피부과", "안과", "소아과", "요양병원", "비뇨기과", "정신건강의학과", "산부인과", "재활의학과", + "정신과", "마취통증의학과"}; + for(String subdivision : subdivisionList){ + if(this.name.contains(subdivision)){ + this.subDivision=subdivision; + }else + this.subDivision = "없음"; + } + + } + public String getSubDivision() { return subDivision; } From ef402ca4df13f142d6319b2db24d8fc7b75b06bb Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 14:37:23 +0900 Subject: [PATCH 094/307] =?UTF-8?q?TestCase(subDivision=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/Date10_12/pasrser/HospitalParserTest.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java b/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java index ca105b4..b650055 100644 --- a/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java +++ b/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test; class HospitalParserTest { - String str = "\"A1120837\",\"서울특별시 송파구 동남로 208 (가락동)\",\"A\",\"의원\",\"G099\",\"응급의료기관 이외\",\"1\",\"토요일 첫째주 셋째주 휴진\",\"2005년 부터 진료 재활의학과전문의 전문물리치료 통증클리닉 척추교정치료 체외충격파 휜다리교정 목허리어깨무릎발 통증 디스크 퇴행성관절염\",\"극동아파트상가204호\",\"연세정소아과의원\",\"02-448-6436\",\"02-2227-7777\",\"1900\",\"1900\",\"1900\",\"1900\",\"1900\",\"1500\",\"1400\",\"1600\",\"0900\",\"0900\",\"0900\",\"0900\",\"0900\",\"0900\",\"1000\",\"0900\",\"057\",\"83\",\"127.13147131787721\",\"37.49579508152157\",\"2022-09-07 14:55:30.0\""; + String str = "\"A1120837\",\"서울특별시 송파구 동남로 208 (가락동)\",\"A\",\"의원\",\"G099\",\"응급의료기관 이외\",\"1\",\"토요일 첫째주 셋째주 휴진\",\"2005년 부터 진료 재활의학과전문의 전문물리치료 통증클리닉 척추교정치료 체외충격파 휜다리교정 목허리어깨무릎발 통증 디스크 퇴행성관절염\",\"극동아파트상가204호\",\"가로수치과의원\",\"02-448-6436\",\"02-2227-7777\",\"1900\",\"1900\",\"1900\",\"1900\",\"1900\",\"1500\",\"1400\",\"1600\",\"0900\",\"0900\",\"0900\",\"0900\",\"0900\",\"0900\",\"1000\",\"0900\",\"057\",\"83\",\"127.13147131787721\",\"37.49579508152157\",\"2022-09-07 14:55:30.0\""; @Test @DisplayName("ID가 파싱이 잘 되는지") void idParsing() { @@ -26,8 +26,12 @@ void idParsing() { String emergency = "운영중"; Assertions.assertEquals(emergency,hospital.getEmergencyRoom()); - String name = "연세정소아과의원"; + String name = "가로수치과의원"; Assertions.assertEquals(name,hospital.getName()); + String subdivision = "치과"; + Assertions.assertEquals(subdivision,hospital.getSubDivision()); + + } } \ No newline at end of file From 6345db1ffa1e105f9b54330166184b47cfc9f1a2 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 14:53:18 +0900 Subject: [PATCH 095/307] =?UTF-8?q?FileController(=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=EA=B3=BC=20=ED=8C=8C=EC=8B=B1=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date10_12/{LineReader.java => FileController.java} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename lion/src/main/java/Date10_12/{LineReader.java => FileController.java} (83%) diff --git a/lion/src/main/java/Date10_12/LineReader.java b/lion/src/main/java/Date10_12/FileController.java similarity index 83% rename from lion/src/main/java/Date10_12/LineReader.java rename to lion/src/main/java/Date10_12/FileController.java index a700631..7f9b970 100644 --- a/lion/src/main/java/Date10_12/LineReader.java +++ b/lion/src/main/java/Date10_12/FileController.java @@ -8,15 +8,15 @@ import java.util.ArrayList; import java.util.List; -public class LineReader { +public class FileController { Parser parser; boolean isRemoveColumnName = true; - public LineReader(Parser parser) { + public FileController(Parser parser) { this.parser = parser; } - public LineReader(Parser parser, boolean isRemoveColumnName) { + public FileController(Parser parser, boolean isRemoveColumnName) { this.parser = parser; this.isRemoveColumnName = isRemoveColumnName; } From cb73e139f6a2ddf5577976e40ab6674d8ca3078b Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 14:54:25 +0900 Subject: [PATCH 096/307] Hospital(DTO) --- lion/src/main/java/Date10_12/domain/Hospital.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lion/src/main/java/Date10_12/domain/Hospital.java b/lion/src/main/java/Date10_12/domain/Hospital.java index 8c1b67a..b9b3055 100644 --- a/lion/src/main/java/Date10_12/domain/Hospital.java +++ b/lion/src/main/java/Date10_12/domain/Hospital.java @@ -84,9 +84,11 @@ private void setSubdivision(){ "치과", "성형외과", "한방병원", "한의원", "영상의학과", "이비인후과", "소아청소년과", "내과", "정형외과", "외과", "가정의학과","피부과", "안과", "소아과", "요양병원", "비뇨기과", "정신건강의학과", "산부인과", "재활의학과", "정신과", "마취통증의학과"}; + for(String subdivision : subdivisionList){ - if(this.name.contains(subdivision)){ - this.subDivision=subdivision; + if(name.contains(subdivision)){ + subDivision=subdivision; + break; }else this.subDivision = "없음"; } @@ -98,9 +100,6 @@ public String getSubDivision() { } - - - @Override public String toString() { return "\"" + this.id + "\"" + "," + "\"" + this.address + "\"" + "," + "\"" From 8f001804466ba7dd8992ba186cbc80abfad5654b Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 14:54:35 +0900 Subject: [PATCH 097/307] TestCase(TDD) --- lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java b/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java index b650055..3574ae0 100644 --- a/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java +++ b/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java @@ -32,6 +32,5 @@ void idParsing() { String subdivision = "치과"; Assertions.assertEquals(subdivision,hospital.getSubDivision()); - } } \ No newline at end of file From e9c250944701a5d6fd6b31c0e07223def080cc94 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 14:54:41 +0900 Subject: [PATCH 098/307] Main --- lion/src/main/java/Date10_12/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lion/src/main/java/Date10_12/Main.java b/lion/src/main/java/Date10_12/Main.java index e3e5fe6..24e45b3 100644 --- a/lion/src/main/java/Date10_12/Main.java +++ b/lion/src/main/java/Date10_12/Main.java @@ -8,7 +8,7 @@ public class Main { public static void main(String[] args) throws IOException { - LineReader hospitalLineReader = new LineReader<>(new HospitalParser()); + FileController hospitalLineReader = new FileController<>(new HospitalParser()); String filename = "C:\\DB file\\seoul_hospital_information.csv"; List hospitals = hospitalLineReader.readLines(filename); From 9f4ebd93890970795ab77d455c4e23c53fb8d301 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Thu, 13 Oct 2022 14:56:02 +0900 Subject: [PATCH 099/307] Hospital Parser --- lion/src/main/java/Date10_12/pasrser/HospitalParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lion/src/main/java/Date10_12/pasrser/HospitalParser.java b/lion/src/main/java/Date10_12/pasrser/HospitalParser.java index ee6524c..82b4871 100644 --- a/lion/src/main/java/Date10_12/pasrser/HospitalParser.java +++ b/lion/src/main/java/Date10_12/pasrser/HospitalParser.java @@ -13,4 +13,4 @@ public Hospital parse(String str) { return new Hospital(splitted[0],splitted[1],splitted[2],Integer.parseInt(splitted[6]),splitted[10]); } -} +} From 7ccb9ae67b724834971ae67420aa8273a83e250e Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 22:04:06 +0900 Subject: [PATCH 100/307] =?UTF-8?q?Controller(File,Parser=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lion/src/main/java/Date10_12/FileController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lion/src/main/java/Date10_12/FileController.java b/lion/src/main/java/Date10_12/FileController.java index 7f9b970..e52a40a 100644 --- a/lion/src/main/java/Date10_12/FileController.java +++ b/lion/src/main/java/Date10_12/FileController.java @@ -9,6 +9,7 @@ import java.util.List; public class FileController { + String filename = "C:\\DB file\\seoul_hospital_information.txt"; Parser parser; boolean isRemoveColumnName = true; @@ -21,7 +22,7 @@ public FileController(Parser parser, boolean isRemoveColumnName) { this.isRemoveColumnName = isRemoveColumnName; } - List readLines(String filename) throws IOException { + List readLines() throws IOException { List result = new ArrayList<>(); BufferedReader br = new BufferedReader(new FileReader(filename)); String str; From 7b4ebbd0a0bd7886cbbd2fabb2a7d797a9f61da8 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 22:04:23 +0900 Subject: [PATCH 101/307] DTO(Mapping) --- .../main/java/Date10_12/domain/Hospital.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lion/src/main/java/Date10_12/domain/Hospital.java b/lion/src/main/java/Date10_12/domain/Hospital.java index b9b3055..a1f76ac 100644 --- a/lion/src/main/java/Date10_12/domain/Hospital.java +++ b/lion/src/main/java/Date10_12/domain/Hospital.java @@ -57,7 +57,7 @@ public void setCategory() { // 맵핑 categorytmap.put("R","보건소"); categorytmap.put("W","기타(구급차)"); - category = categorytmap.get(category); + this.category = categorytmap.get(category); } public String getCategory() { @@ -99,12 +99,27 @@ public String getSubDivision() { return subDivision; } + public String getSqlInsertQuery(){ + String sql = String.format("INSERT INTO `likelion-db`.`seoul_hospital`\n" + + "(`id`,`address`,`district`,`category`,`emergency_room`,`name`,`subdivision`)\n" + + "VALUES\n" + + "(\"%s\",\n" + + "\"%s\",\n" + + "\"%s\",\n" + + "\"%s\",\n" + + "%d,\n" + + "\"%s\",\n" + + "\"%s\");",this.id,this.address,this.district,this.category,this.emergencyRoom,this.name,this.subDivision); + + return sql; + } @Override public String toString() { return "\"" + this.id + "\"" + "," + "\"" + this.address + "\"" + "," + "\"" + this.district + "\"" + "," + "\"" + this.category + "\"" + "," + this.emergencyRoom + "," + "\"" + - this.name + "\"" + "," + this.subDivision; + this.name + "\"" + "," + "\""+this.subDivision+ "\""; } + } \ No newline at end of file From 8a8ef745117dd39a5e3446046d2f12ccdd6e0aaa Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 22:04:35 +0900 Subject: [PATCH 102/307] Parser --- .../Date10_12/pasrser/HospitalParser.java | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/lion/src/main/java/Date10_12/pasrser/HospitalParser.java b/lion/src/main/java/Date10_12/pasrser/HospitalParser.java index ee6524c..bc443c5 100644 --- a/lion/src/main/java/Date10_12/pasrser/HospitalParser.java +++ b/lion/src/main/java/Date10_12/pasrser/HospitalParser.java @@ -2,10 +2,18 @@ import Date10_12.domain.Hospital; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.List; +import java.util.Map; + // 클래스에서 alt+enter를 눌러 테스트를 할 수 있다. public class HospitalParser implements Parser{ - + static String fileaddress = "C:\\Users\\qowhx\\AppData\\Roaming\\SPB_Data\\git\\Java-Study\\lion\\test.txt"; + static String DBfileaddress = "C:\\DB file\\seoul_hospital_infomation_parsingdata.txt"; @Override public Hospital parse(String str) { str = str.replaceAll("\"",""); // "" 제거 @@ -13,4 +21,47 @@ public Hospital parse(String str) { return new Hospital(splitted[0],splitted[1],splitted[2],Integer.parseInt(splitted[6]),splitted[10]); } + + public void CreateFile(){ // 파일 생성 + File file = new File(fileaddress); // 파일 생성 위치및 파일 이름 + try{ + System.out.println("파일 생성"); + file.createNewFile(); + }catch (IOException e){ + System.out.println("파일 생성 못함"); + throw new RuntimeException(); + } + } + + public void Filewrite(List hospitals){ // 파일 작성 + File file = new File(fileaddress); + + try{ + BufferedWriter writer = new BufferedWriter(new FileWriter(file)); + + for(Hospital hospital:hospitals){ // 참조변수로 받은 리스트만큼 반복 + writer.write(String.valueOf(hospital)+"\n"); // 참조변수로 받은 리스트의 값+"\n" 으로 파일에 작성 + } + writer.close(); + }catch (IOException e){ + e.printStackTrace(); + } + } + + public void DBFilewrite(List hospitals){ // 파일 작성 + File file = new File(DBfileaddress); + + try{ + BufferedWriter writer = new BufferedWriter(new FileWriter(file)); + + for(Hospital hospital:hospitals){ // 참조변수로 받은 리스트만큼 반복 + writer.write(hospital+"\n"); // 참조변수로 받은 리스트의 값+"\n" 으로 파일에 작성 + } + writer.close(); + }catch (IOException e){ + e.printStackTrace(); + } + } + + } From 0ff04b8f468b6dc5a12e595fd2e34de5c47db969 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 22:04:45 +0900 Subject: [PATCH 103/307] TestCase(TDD) --- .../Date10_12/pasrser/HospitalParserTest.java | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java b/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java index 3574ae0..3967d48 100644 --- a/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java +++ b/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java @@ -15,22 +15,40 @@ void idParsing() { String address = "서울특별시 송파구 동남로 208 (가락동)"; Assertions.assertEquals("A1120837", hospital.getId()); - Assertions.assertEquals(address,hospital.getAddress()); + Assertions.assertEquals(address, hospital.getAddress()); String district = "서울특별시 송파구"; - Assertions.assertEquals(district,hospital.getDistrict()); + Assertions.assertEquals(district, hospital.getDistrict()); String category = "종합병원"; - Assertions.assertEquals(category,hospital.getCategory()); + Assertions.assertEquals(category, hospital.getCategory()); String emergency = "운영중"; - Assertions.assertEquals(emergency,hospital.getEmergencyRoom()); + Assertions.assertEquals(emergency, hospital.getEmergencyRoom()); String name = "가로수치과의원"; - Assertions.assertEquals(name,hospital.getName()); + Assertions.assertEquals(name, hospital.getName()); String subdivision = "치과"; - Assertions.assertEquals(subdivision,hospital.getSubDivision()); + Assertions.assertEquals(subdivision, hospital.getSubDivision()); + } + @Test + @DisplayName("insert쿼리를 잘 만드는지 test") + void makeSqlQueryTest() { + HospitalParser hospitalParser = new HospitalParser(); + Hospital hospital = hospitalParser.parse(this.str); + String sql ="INSERT INTO `likelion-db`.`seoul_hospital`\n" + + "(`id`,`address`,`district`,`category`,`emergency_room`,`name`,`subdivision`)\n" + + "VALUES\n" + + "(\"A1120837\",\n" + + "\"서울특별시 송파구 동남로 208 (가락동)\",\n" + + "\"서울특별시 송파구\",\n" + + "\"종합병원\",\n" + + "1,\n" + + "\"가로수치과의원\",\n" + + "\"치과\");"; + Assertions.assertEquals(sql, hospital.getSqlInsertQuery()); } + } \ No newline at end of file From c3df40f43d1cb410296a0017eb8353ae15d87d30 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 22:04:49 +0900 Subject: [PATCH 104/307] Main --- lion/src/main/java/Date10_12/Main.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lion/src/main/java/Date10_12/Main.java b/lion/src/main/java/Date10_12/Main.java index 24e45b3..a539a26 100644 --- a/lion/src/main/java/Date10_12/Main.java +++ b/lion/src/main/java/Date10_12/Main.java @@ -9,12 +9,13 @@ public class Main { public static void main(String[] args) throws IOException { FileController hospitalLineReader = new FileController<>(new HospitalParser()); - String filename = "C:\\DB file\\seoul_hospital_information.csv"; - List hospitals = hospitalLineReader.readLines(filename); - System.out.println(hospitals.size()); - for (Hospital hospital : hospitals) { - System.out.println(hospital.getId()); - } + List hospitals = hospitalLineReader.readLines(); // 파일에서 값을 1줄씩 전체 읽어 list에 저장 + + HospitalParser hospitalParser = new HospitalParser(); + hospitalParser.CreateFile(); // 파일 생성 + + hospitalParser.Filewrite(hospitals); + hospitalParser.DBFilewrite(hospitals); } } From 3fd30839392c92012d6b18c89f5e400a5c8d2eb3 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Thu, 13 Oct 2022 22:07:34 +0900 Subject: [PATCH 105/307] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7995c9f..9af39d2 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,9 @@ - 2022-10-11 : Aws + docker + Mysql 연결 -- 2022-10-12 : 알고리즘[max,min 구하기] + 대용량 파일 처리 +- 2022-10-12 : 알고리즘[max,min 구하기] + 대용량 데이터 처리 -- 2022-10-13 : 알고리즘[버블정렬] +- 2022-10-13 : 알고리즘[버블정렬] + 대용량 데이터 처리(mysql에 데이터 insert까지)
From 0c86a352324086f7db10d3cc1d625e4400aadfd4 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 22:36:10 +0900 Subject: [PATCH 106/307] =?UTF-8?q?[CodeUp]=201050=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_13/Algorithm/CodeUp/No_1050.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1050.java diff --git a/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1050.java b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1050.java new file mode 100644 index 0000000..cc835e6 --- /dev/null +++ b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1050.java @@ -0,0 +1,21 @@ +package Date10_13.Algorithm.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1050 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String[] str = br.readLine().split(" "); + + int num1 = Integer.parseInt(str[0]); + int num2 = Integer.parseInt(str[1]); + + if(num1 == num2) + System.out.println("1"); + else + System.out.println("0"); + } +} From 3e31fde7b0b6c6d98841e19d2e2ef241008f680d Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 22:36:16 +0900 Subject: [PATCH 107/307] =?UTF-8?q?[CodeUp]=201051=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_13/Algorithm/CodeUp/No_1051.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1051.java diff --git a/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1051.java b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1051.java new file mode 100644 index 0000000..db52b29 --- /dev/null +++ b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1051.java @@ -0,0 +1,21 @@ +package Date10_13.Algorithm.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1051 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String[] str = br.readLine().split(" "); + + int num1 = Integer.parseInt(str[0]); + int num2 = Integer.parseInt(str[1]); + + if(num1 <= num2) + System.out.println("1"); + else + System.out.println("0"); + } +} From 14742e49fc4f92b134a766d0371f351f63209bce Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 22:36:21 +0900 Subject: [PATCH 108/307] =?UTF-8?q?[CodeUp]=201052=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_13/Algorithm/CodeUp/No_1052.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1052.java diff --git a/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1052.java b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1052.java new file mode 100644 index 0000000..db47b10 --- /dev/null +++ b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1052.java @@ -0,0 +1,21 @@ +package Date10_13.Algorithm.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1052 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String[] str = br.readLine().split(" "); + + int num1 = Integer.parseInt(str[0]); + int num2 = Integer.parseInt(str[1]); + + if(num1 != num2) + System.out.println("1"); + else + System.out.println("0"); + } +} From 36bea763c781e43193aa3815f28d0b8436f5947e Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 22:36:27 +0900 Subject: [PATCH 109/307] =?UTF-8?q?[CodeUp]=201053=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_13/Algorithm/CodeUp/No_1053.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1053.java diff --git a/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1053.java b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1053.java new file mode 100644 index 0000000..5b07245 --- /dev/null +++ b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1053.java @@ -0,0 +1,18 @@ +package Date10_13.Algorithm.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1053 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int num1 = Integer.parseInt(br.readLine()); + + if(num1 == 1) + System.out.println("0"); + else + System.out.println("1"); + } +} From 60ee0fe7e185a46dd478576b16e5b706d96eeb81 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 22:36:35 +0900 Subject: [PATCH 110/307] =?UTF-8?q?[CodeUp]=201054=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_13/Algorithm/CodeUp/No_1054.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1054.java diff --git a/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1054.java b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1054.java new file mode 100644 index 0000000..f176509 --- /dev/null +++ b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1054.java @@ -0,0 +1,21 @@ +package Date10_13.Algorithm.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1054 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String[] str = br.readLine().split(" "); + + int num1 = Integer.parseInt(str[0]); + int num2 = Integer.parseInt(str[1]); + + if(num1 ==1 && num2 == 1) + System.out.println("1"); + else + System.out.println("0"); + } +} From ee9a605bea32f7821311cd705fcba1bf87773045 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 22:36:40 +0900 Subject: [PATCH 111/307] =?UTF-8?q?[CodeUp]=201055=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_13/Algorithm/CodeUp/No_1055.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1055.java diff --git a/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1055.java b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1055.java new file mode 100644 index 0000000..82407c8 --- /dev/null +++ b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1055.java @@ -0,0 +1,21 @@ +package Date10_13.Algorithm.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1055 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String[] str = br.readLine().split(" "); + + int num1 = Integer.parseInt(str[0]); + int num2 = Integer.parseInt(str[1]); + + if(num1 ==1 || num2 == 1) + System.out.println("1"); + else + System.out.println("0"); + } +} From 559890c9610ca887ff5cc8281257d8a75b9c3fb1 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 22:36:45 +0900 Subject: [PATCH 112/307] =?UTF-8?q?[CodeUp]=201056=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_13/Algorithm/CodeUp/No_1056.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1056.java diff --git a/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1056.java b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1056.java new file mode 100644 index 0000000..d1bb74d --- /dev/null +++ b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1056.java @@ -0,0 +1,21 @@ +package Date10_13.Algorithm.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1056 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String[] str = br.readLine().split(" "); + + int num1 = Integer.parseInt(str[0]); + int num2 = Integer.parseInt(str[1]); + + if((num1 ==1 && num2 != 1)||(num1 !=1 && num2 == 1)) + System.out.println("1"); + else + System.out.println("0"); + } +} From 5903fbd33eb4ec37b34c99e0614270b07c8f4c5a Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 22:36:49 +0900 Subject: [PATCH 113/307] =?UTF-8?q?[CodeUp]=201057=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_13/Algorithm/CodeUp/No_1057.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1057.java diff --git a/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1057.java b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1057.java new file mode 100644 index 0000000..b7121fa --- /dev/null +++ b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1057.java @@ -0,0 +1,21 @@ +package Date10_13.Algorithm.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1057 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String[] str = br.readLine().split(" "); + + int num1 = Integer.parseInt(str[0]); + int num2 = Integer.parseInt(str[1]); + + if(num1 == num2) + System.out.println("1"); + else + System.out.println("0"); + } +} From 27b0b45b5a5d140825e483fc91be016f7af064c2 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 22:36:54 +0900 Subject: [PATCH 114/307] =?UTF-8?q?[CodeUp]=201058=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_13/Algorithm/CodeUp/No_1058.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1058.java diff --git a/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1058.java b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1058.java new file mode 100644 index 0000000..0ca640c --- /dev/null +++ b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1058.java @@ -0,0 +1,17 @@ +package Date10_13.Algorithm.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1058 { + public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String[] str = br.readLine().split(" "); + + boolean num1 = Integer.parseInt(str[0]) != 0; + boolean num2 = Integer.parseInt(str[1]) != 0; + + System.out.print(num1||num2? 0:1); + } +} From 857f2124bff7acb246477c57eaf002a0c21a52f4 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 22:36:58 +0900 Subject: [PATCH 115/307] =?UTF-8?q?[CodeUp]=201059=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_13/Algorithm/CodeUp/No_1059.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1059.java diff --git a/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1059.java b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1059.java new file mode 100644 index 0000000..f45bf2f --- /dev/null +++ b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1059.java @@ -0,0 +1,17 @@ +package Date10_13.Algorithm.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1059 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int num = Integer.parseInt(br.readLine()); + + System.out.printf("%d",~num); // 비트단위논리연산 + // ~n = -n -1 + // ex) 2일때 ~2 = -2 -1 + } +} From 88eccdfcb64152e7c083775de4f5821f5933cbb9 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 13 Oct 2022 22:37:03 +0900 Subject: [PATCH 116/307] =?UTF-8?q?[CodeUp]=201060=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_13/Algorithm/CodeUp/No_1060.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1060.java diff --git a/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1060.java b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1060.java new file mode 100644 index 0000000..42de7e8 --- /dev/null +++ b/git/Lion-Java/src/Date10_13/Algorithm/CodeUp/No_1060.java @@ -0,0 +1,23 @@ +package Date10_13.Algorithm.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1060 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String[] str = br.readLine().split(" "); + + int num1 = Integer.parseInt(str[0]); + int num2 = Integer.parseInt(str[1]); + + System.out.printf("%d",num1&num2); // 비트단위 연산자 + // 두개의 값의 비트연산자를 더함(중복 자리의 값만 1로 반환) + // ex) + // 3 : 00000000 00000000 00000000 00000011 + // 5 : 00000000 00000000 00000000 00000101 + // 3 & 5 : 00000000 00000000 00000000 00000001 + } +} From 7b1991ee1fe9b139043eabea779d93fe730c6f20 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Fri, 14 Oct 2022 09:47:20 +0900 Subject: [PATCH 117/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20=EC=84=A0=ED=83=9D=EC=A0=95=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_14/Algorithm/InsertSort.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 git/Lion-Java/src/Date10_14/Algorithm/InsertSort.java diff --git a/git/Lion-Java/src/Date10_14/Algorithm/InsertSort.java b/git/Lion-Java/src/Date10_14/Algorithm/InsertSort.java new file mode 100644 index 0000000..602be5e --- /dev/null +++ b/git/Lion-Java/src/Date10_14/Algorithm/InsertSort.java @@ -0,0 +1,29 @@ +package Date10_14.Algorithm; + +// 삽입정렬 + +import java.util.Arrays; + +public class InsertSort { + + static int[] sort(int[] arr){ + int i = 1; + + if(arr[i] < arr[i-1]){ + int tmp; + + tmp = arr[i]; + arr[i] = arr[i-1]; + arr[i-1] = tmp; + } + + return arr; + } + + + public static void main(String[] args) { + int[] arr = {8,5,6,2,4}; + + System.out.println(Arrays.toString(sort(arr))); + } +} From 90032abd363728fe6bfb83bec819e5ec64282fa3 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Fri, 14 Oct 2022 09:48:52 +0900 Subject: [PATCH 118/307] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9af39d2..bc46422 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ - 2022-10-12 : 알고리즘[max,min 구하기] + 대용량 데이터 처리 - 2022-10-13 : 알고리즘[버블정렬] + 대용량 데이터 처리(mysql에 데이터 insert까지) + +- 2022-10-14 : 알고리즘[선택정렬] +
From 1ea185f373f90b855d81264707f8b3659cbe6adf Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Fri, 14 Oct 2022 09:56:19 +0900 Subject: [PATCH 119/307] =?UTF-8?q?=EC=82=BD=EC=9E=85=EC=A0=95=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_14/Algorithm/InsertSort.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/Lion-Java/src/Date10_14/Algorithm/InsertSort.java b/git/Lion-Java/src/Date10_14/Algorithm/InsertSort.java index 602be5e..65679f9 100644 --- a/git/Lion-Java/src/Date10_14/Algorithm/InsertSort.java +++ b/git/Lion-Java/src/Date10_14/Algorithm/InsertSort.java @@ -26,4 +26,4 @@ public static void main(String[] args) { System.out.println(Arrays.toString(sort(arr))); } -} +} From 51d6bae8d3440745c0177045ab962e58f3210fdf Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Fri, 14 Oct 2022 10:12:27 +0900 Subject: [PATCH 120/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20=EC=82=BD=EC=9E=85=EC=A0=95=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_14/Algorithm/InsertSort.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/git/Lion-Java/src/Date10_14/Algorithm/InsertSort.java b/git/Lion-Java/src/Date10_14/Algorithm/InsertSort.java index 602be5e..91fb701 100644 --- a/git/Lion-Java/src/Date10_14/Algorithm/InsertSort.java +++ b/git/Lion-Java/src/Date10_14/Algorithm/InsertSort.java @@ -7,16 +7,17 @@ public class InsertSort { static int[] sort(int[] arr){ - int i = 1; - if(arr[i] < arr[i-1]){ - int tmp; - - tmp = arr[i]; - arr[i] = arr[i-1]; - arr[i-1] = tmp; + for(int i=1; i= 0; j--) { // 이전 값 모두 비교(이전값 개수만큼 반복) + if (arr[j+1] < arr[j]) { + int tmp = arr[j+1]; + arr[j+1] = arr[j]; + arr[j] = tmp; + } + System.out.println(Arrays.toString(arr)); + } } - return arr; } From bff61fd7de8440b04a419b394ccc0deed55abbd7 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Fri, 14 Oct 2022 10:12:57 +0900 Subject: [PATCH 121/307] =?UTF-8?q?=EC=82=BD=EC=9E=85=EC=A0=95=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_14/Algorithm/InsertSort.java | 1 + 1 file changed, 1 insertion(+) diff --git a/git/Lion-Java/src/Date10_14/Algorithm/InsertSort.java b/git/Lion-Java/src/Date10_14/Algorithm/InsertSort.java index 32b8a28..365178f 100644 --- a/git/Lion-Java/src/Date10_14/Algorithm/InsertSort.java +++ b/git/Lion-Java/src/Date10_14/Algorithm/InsertSort.java @@ -28,3 +28,4 @@ public static void main(String[] args) { System.out.println(Arrays.toString(sort(arr))); } } + From f4f91205e002ca60cbdaf9e7567ec394d381b8f0 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Fri, 14 Oct 2022 10:42:17 +0900 Subject: [PATCH 122/307] =?UTF-8?q?[CodeUp]=201443=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_14/Algorithm/CodeUp/No_1443.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 git/Lion-Java/src/Date10_14/Algorithm/CodeUp/No_1443.java diff --git a/git/Lion-Java/src/Date10_14/Algorithm/CodeUp/No_1443.java b/git/Lion-Java/src/Date10_14/Algorithm/CodeUp/No_1443.java new file mode 100644 index 0000000..bc0fceb --- /dev/null +++ b/git/Lion-Java/src/Date10_14/Algorithm/CodeUp/No_1443.java @@ -0,0 +1,32 @@ +package Date10_14.Algorithm.CodeUp; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class No_1443 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int num = Integer.parseInt(br.readLine()); // 배열 사이즈 입력 + int[] arr = new int[num]; + + for(int i = 0; i=0; j--){ + if(arr[j] < arr[j+1]){ + int tmp = arr[j+1]; + arr[j+1] = arr[j]; + arr[j] = tmp; + } + } + } + + for(int i= num-1; i>=0; i--){ + System.out.println(arr[i]); + } + } +} From cfeafd19c694e8fb0d4f06a858823affa86c3fbb Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Sat, 15 Oct 2022 21:51:45 +0900 Subject: [PATCH 123/307] TestCase(TDD) --- lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java b/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java index 3967d48..0396372 100644 --- a/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java +++ b/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java @@ -51,4 +51,4 @@ void makeSqlQueryTest() { Assertions.assertEquals(sql, hospital.getSqlInsertQuery()); } -} \ No newline at end of file +} From a36e03b33068e9cc7be7aee715069c4bc1eef536 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Sun, 16 Oct 2022 11:31:47 +0900 Subject: [PATCH 124/307] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bc46422..4420c3a 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ - 2022-10-13 : 알고리즘[버블정렬] + 대용량 데이터 처리(mysql에 데이터 insert까지) -- 2022-10-14 : 알고리즘[선택정렬] + +- 2022-10-14 : 알고리즘[삽입정렬] +
From 890606cdef7e40ffafda1886bc82e0b4332bdeb2 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Sun, 16 Oct 2022 11:35:32 +0900 Subject: [PATCH 125/307] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4420c3a..c409eda 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,9 @@ - 2022-10-12 : 알고리즘[max,min 구하기] + 대용량 데이터 처리 -- 2022-10-13 : 알고리즘[버블정렬] + 대용량 데이터 처리(mysql에 데이터 insert까지) +- 2022-10-13 : 알고리즘[버블정렬] + 대용량 데이터 처리(Mysql에 파일로 데이터 삽입) -- 2022-10-14 : 알고리즘[삽입정렬] + +- 2022-10-14 : 알고리즘[삽입정렬] + Mysql(기초 문법)
From 2da674387e6d93478858cb8164034057549b8c3a Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Sun, 16 Oct 2022 17:10:38 +0900 Subject: [PATCH 126/307] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c409eda..1f2b916 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ - 2022-10-13 : 알고리즘[버블정렬] + 대용량 데이터 처리(Mysql에 파일로 데이터 삽입) -- 2022-10-14 : 알고리즘[삽입정렬] + Mysql(기초 문법) +- 2022-10-14 : 알고리즘[삽입정렬] + Mysql(기초 문법) + TDD
From 6ba422efa2769bcf1333c41c57a68df10cac9893 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Mon, 17 Oct 2022 09:10:13 +0900 Subject: [PATCH 127/307] =?UTF-8?q?=EC=A7=81=EA=B0=81=EC=82=BC=EA=B0=81?= =?UTF-8?q?=ED=98=95=20=EB=B3=84=EC=B0=8D=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_17/Algorithm/Star.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 git/Lion-Java/src/Date10_17/Algorithm/Star.java diff --git a/git/Lion-Java/src/Date10_17/Algorithm/Star.java b/git/Lion-Java/src/Date10_17/Algorithm/Star.java new file mode 100644 index 0000000..67c678a --- /dev/null +++ b/git/Lion-Java/src/Date10_17/Algorithm/Star.java @@ -0,0 +1,14 @@ +package Date10_17.Algorithm; + +/* 알고리즘 문제 + + 별찍기(직각 삼각형) + */ +public class Star { + public static void main(String[] args) { + System.out.println("*"); + System.out.println("**"); + System.out.println("***"); + System.out.println("****"); + } +} From 5cb3e8f1900d142e968412acd9196a50cee9531c Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Mon, 17 Oct 2022 09:17:30 +0900 Subject: [PATCH 128/307] =?UTF-8?q?=EC=A7=81=EA=B0=81=EC=82=BC=EA=B0=81?= =?UTF-8?q?=ED=98=95=20=EB=B3=84=EC=B0=8D=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_17/Algorithm/Star.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/git/Lion-Java/src/Date10_17/Algorithm/Star.java b/git/Lion-Java/src/Date10_17/Algorithm/Star.java index 67c678a..f7ab8be 100644 --- a/git/Lion-Java/src/Date10_17/Algorithm/Star.java +++ b/git/Lion-Java/src/Date10_17/Algorithm/Star.java @@ -6,9 +6,11 @@ */ public class Star { public static void main(String[] args) { - System.out.println("*"); - System.out.println("**"); - System.out.println("***"); - System.out.println("****"); + for(int i=0; i<4; i++){ + for(int j=0; j Date: Mon, 17 Oct 2022 09:20:15 +0900 Subject: [PATCH 129/307] =?UTF-8?q?=EC=A7=81=EA=B0=81=EC=82=BC=EA=B0=81?= =?UTF-8?q?=ED=98=95=20=EB=B3=84=EC=B0=8D=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_17/Algorithm/Star.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/git/Lion-Java/src/Date10_17/Algorithm/Star.java b/git/Lion-Java/src/Date10_17/Algorithm/Star.java index f7ab8be..f5408c0 100644 --- a/git/Lion-Java/src/Date10_17/Algorithm/Star.java +++ b/git/Lion-Java/src/Date10_17/Algorithm/Star.java @@ -1,16 +1,31 @@ package Date10_17.Algorithm; +import Date10_13.Algorithm.BubbleSort; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + /* 알고리즘 문제 별찍기(직각 삼각형) */ public class Star { - public static void main(String[] args) { - for(int i=0; i<4; i++){ + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + int num = Integer.parseInt(bf.readLine()); + + input(num); + } + + static void input(int num){ + for(int i=0; i Date: Mon, 17 Oct 2022 09:20:44 +0900 Subject: [PATCH 130/307] =?UTF-8?q?=EC=A7=81=EA=B0=81=EC=82=BC=EA=B0=81?= =?UTF-8?q?=ED=98=95=20=EB=B3=84=EC=B0=8D=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_17/Algorithm/Star.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git/Lion-Java/src/Date10_17/Algorithm/Star.java b/git/Lion-Java/src/Date10_17/Algorithm/Star.java index f5408c0..d37c651 100644 --- a/git/Lion-Java/src/Date10_17/Algorithm/Star.java +++ b/git/Lion-Java/src/Date10_17/Algorithm/Star.java @@ -14,13 +14,13 @@ public class Star { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); - int num = Integer.parseInt(bf.readLine()); + int num = Integer.parseInt(bf.readLine()); // 라인 개수 입력 받음 input(num); } static void input(int num){ - for(int i=0; i Date: Mon, 17 Oct 2022 09:44:01 +0900 Subject: [PATCH 131/307] =?UTF-8?q?=EC=A7=81=EA=B0=81=EC=82=BC=EA=B0=81?= =?UTF-8?q?=ED=98=95=20=EB=B3=84=EC=B0=8D=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_17/Algorithm/Star.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/git/Lion-Java/src/Date10_17/Algorithm/Star.java b/git/Lion-Java/src/Date10_17/Algorithm/Star.java index d37c651..1f2b9d4 100644 --- a/git/Lion-Java/src/Date10_17/Algorithm/Star.java +++ b/git/Lion-Java/src/Date10_17/Algorithm/Star.java @@ -11,18 +11,28 @@ 별찍기(직각 삼각형) */ public class Star { + private char letter = '*'; + + public Star() { + } + + public Star(char letter) { + this.letter = letter; + } + public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + Star star = new Star('@'); int num = Integer.parseInt(bf.readLine()); // 라인 개수 입력 받음 - input(num); + star.input(num); } - static void input(int num){ + public void input(int num){ for(int i=0; i Date: Mon, 17 Oct 2022 10:00:36 +0900 Subject: [PATCH 132/307] =?UTF-8?q?=ED=94=BC=EB=9D=BC=EB=AF=B8=EB=93=9C=20?= =?UTF-8?q?=EB=B3=84=EC=B0=8D=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_17/Algorithm/Star2.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 git/Lion-Java/src/Date10_17/Algorithm/Star2.java diff --git a/git/Lion-Java/src/Date10_17/Algorithm/Star2.java b/git/Lion-Java/src/Date10_17/Algorithm/Star2.java new file mode 100644 index 0000000..a3cf2f8 --- /dev/null +++ b/git/Lion-Java/src/Date10_17/Algorithm/Star2.java @@ -0,0 +1,31 @@ +package Date10_17.Algorithm; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +/* 알고리즘 문제 + + 별찍기(피라미드 삼각형) + */ +public class Star2 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int num = Integer.parseInt(br.readLine()); + + input(num); + } + + static void input(int num){ + for(int i=0; i Date: Mon, 17 Oct 2022 10:03:14 +0900 Subject: [PATCH 133/307] =?UTF-8?q?=ED=94=BC=EB=9D=BC=EB=AF=B8=EB=93=9C=20?= =?UTF-8?q?=EB=B3=84=EC=B0=8D=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_17/Algorithm/Star2.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git/Lion-Java/src/Date10_17/Algorithm/Star2.java b/git/Lion-Java/src/Date10_17/Algorithm/Star2.java index a3cf2f8..98b63f5 100644 --- a/git/Lion-Java/src/Date10_17/Algorithm/Star2.java +++ b/git/Lion-Java/src/Date10_17/Algorithm/Star2.java @@ -18,11 +18,11 @@ public static void main(String[] args) throws IOException { } static void input(int num){ - for(int i=0; i Date: Mon, 17 Oct 2022 10:12:51 +0900 Subject: [PATCH 134/307] =?UTF-8?q?=ED=94=BC=EB=9D=BC=EB=AF=B8=EB=93=9C=20?= =?UTF-8?q?=EB=B3=84=EC=B0=8D=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/Lion-Java/src/Date10_17/Algorithm/Star2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/Lion-Java/src/Date10_17/Algorithm/Star2.java b/git/Lion-Java/src/Date10_17/Algorithm/Star2.java index 98b63f5..5858f6c 100644 --- a/git/Lion-Java/src/Date10_17/Algorithm/Star2.java +++ b/git/Lion-Java/src/Date10_17/Algorithm/Star2.java @@ -22,7 +22,7 @@ static void input(int num){ for(int j = 1; j Date: Mon, 17 Oct 2022 10:15:10 +0900 Subject: [PATCH 135/307] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 1f2b916..f507da5 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ - 2022-10-13 : 알고리즘[버블정렬] + 대용량 데이터 처리(Mysql에 파일로 데이터 삽입) - 2022-10-14 : 알고리즘[삽입정렬] + Mysql(기초 문법) + TDD + +- 2022-10-17 : 알고리즘[For문 별찍기] +
From c79b8df5cf85a0a4b5904a523c5f662965cbef3e Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Mon, 17 Oct 2022 10:29:32 +0900 Subject: [PATCH 136/307] =?UTF-8?q?=EB=A7=88=EB=A6=84=EB=AA=A8=20=EB=B3=84?= =?UTF-8?q?=EC=B0=8D=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_17/Algorithm/Diamond.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 git/Lion-Java/src/Date10_17/Algorithm/Diamond.java diff --git a/git/Lion-Java/src/Date10_17/Algorithm/Diamond.java b/git/Lion-Java/src/Date10_17/Algorithm/Diamond.java new file mode 100644 index 0000000..0ff0ae9 --- /dev/null +++ b/git/Lion-Java/src/Date10_17/Algorithm/Diamond.java @@ -0,0 +1,36 @@ +package Date10_17.Algorithm; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Diamond { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int num = Integer.parseInt(br.readLine()); + + input(num); + } + + static void input(int num){ + for(int i=0; i=0; i--){ + for(int j=1; j Date: Mon, 17 Oct 2022 11:56:49 +0900 Subject: [PATCH 137/307] First Commit --- Java-Mysql-Connect/.idea/vcs.xml | 6 + Java-Mysql-Connect/gradlew | 234 +++++++++++++++++++++++++++++ Java-Mysql-Connect/gradlew.bat | 89 +++++++++++ Java-Mysql-Connect/settings.gradle | 2 + 4 files changed, 331 insertions(+) create mode 100644 Java-Mysql-Connect/.idea/vcs.xml create mode 100644 Java-Mysql-Connect/gradlew create mode 100644 Java-Mysql-Connect/gradlew.bat create mode 100644 Java-Mysql-Connect/settings.gradle diff --git a/Java-Mysql-Connect/.idea/vcs.xml b/Java-Mysql-Connect/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Java-Mysql-Connect/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Java-Mysql-Connect/gradlew b/Java-Mysql-Connect/gradlew new file mode 100644 index 0000000..1b6c787 --- /dev/null +++ b/Java-Mysql-Connect/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/Java-Mysql-Connect/gradlew.bat b/Java-Mysql-Connect/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/Java-Mysql-Connect/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/Java-Mysql-Connect/settings.gradle b/Java-Mysql-Connect/settings.gradle new file mode 100644 index 0000000..6e01e4f --- /dev/null +++ b/Java-Mysql-Connect/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'Java-Mysql-Connect' + From 050aaa13ea63ad98b05dacc9b4a4c5ba848d5468 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Mon, 17 Oct 2022 11:57:06 +0900 Subject: [PATCH 138/307] Java-Mysql-Connect --- .../src/main/java/com/dbexercise/UserDao.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java new file mode 100644 index 0000000..4c61c80 --- /dev/null +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java @@ -0,0 +1,36 @@ +package com.dbexercise; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.Map; + +public class UserDao { + public void add() throws SQLException, ClassNotFoundException { + Map env = System.getenv(); // 아래의 값들은 해킹 위험이 있으므로 코드상에 데이터를 넣지말고 + // 왼쪽 위에 메뉴바에서 망치 옆에 프로젝트를 눌러 edit configurations를 누르고 + // environments variables를 눌러 값을 입력해 준다. + String dbHost = env.get("DB_HOST"); // DB 호스트 번호(AWS 주소) + String dbUser = env.get("DB_USER"); // DB 호스트 이름 + String dbPassword = env.get("DB_PASSWORD"); // DB 비밀번호 + + Class.forName("com.mysql.cj.jdbc.Driver"); // 만약 DB드라이버가 2개 이상일때 어떤 DB에 데이터를 삽입할 것인지 구분하기 위해 사용함 + // 지금은 mysql 1개만 사용하기 때문에 없어도 됨 + Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); // db 연결(호스트,이름,비밀번호) + PreparedStatement ps = conn.prepareStatement("INSERT INTO users(id,name,password) VALUES(?,?,?)"); + ps.setString(1,"4"); // mysql 테이블로 값 insert + ps.setString(2,"hi"); + ps.setString(3,"1234"); + + + ps.executeUpdate(); // ctrl + enter 즉, mysql에서 번개모양을 눌러 최신화 한다는 느낌 + ps.close(); + conn.close(); + } + + public static void main(String[] args) throws SQLException, ClassNotFoundException { + UserDao userDao = new UserDao(); + userDao.add(); + } +} From e5a904b2c6c1d904dfc45f468ffaf31547b16f2b Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Mon, 17 Oct 2022 11:58:07 +0900 Subject: [PATCH 139/307] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f507da5..4bc6095 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ - 2022-10-14 : 알고리즘[삽입정렬] + Mysql(기초 문법) + TDD -- 2022-10-17 : 알고리즘[For문 별찍기] + +- 2022-10-17 : 알고리즘[For문 별찍기] + Java/Mysql 연결(Insert)
From e60f7b6f8b108363f56401d9a2c99c9264ccf686 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Mon, 17 Oct 2022 17:47:50 +0900 Subject: [PATCH 140/307] Delete --- .../src/main/java/com/dbexercise/UserDao.java | 46 +++- .../main/java/com/dbexercise/domain/User.java | 32 +++ lion/build.gradle | 19 -- lion/gradlew | 234 ------------------ lion/gradlew.bat | 89 ------- .../classes/Date10_12/LineReader.class | Bin 1782 -> 0 bytes .../production/classes/Date10_12/Main.class | Bin 1568 -> 0 bytes .../classes/Date10_12/domain/Hospital.class | Bin 2109 -> 0 bytes .../Date10_12/pasrser/HospitalParser.class | Bin 914 -> 0 bytes .../classes/Date10_12/pasrser/Parser.class | Bin 265 -> 0 bytes .../pasrser/HospitalParserTest.class | Bin 1630 -> 0 bytes lion/settings.gradle | 2 - .../main/java/Date10_12/FileController.java | 38 --- lion/src/main/java/Date10_12/Main.java | 21 -- .../main/java/Date10_12/domain/Hospital.java | 125 ---------- .../Date10_12/pasrser/HospitalParser.java | 65 ----- .../main/java/Date10_12/pasrser/Parser.java | 5 - .../Date10_12/pasrser/HospitalParserTest.java | 54 ---- 18 files changed, 67 insertions(+), 663 deletions(-) create mode 100644 Java-Mysql-Connect/src/main/java/com/dbexercise/domain/User.java delete mode 100644 lion/build.gradle delete mode 100644 lion/gradlew delete mode 100644 lion/gradlew.bat delete mode 100644 lion/out/production/classes/Date10_12/LineReader.class delete mode 100644 lion/out/production/classes/Date10_12/Main.class delete mode 100644 lion/out/production/classes/Date10_12/domain/Hospital.class delete mode 100644 lion/out/production/classes/Date10_12/pasrser/HospitalParser.class delete mode 100644 lion/out/production/classes/Date10_12/pasrser/Parser.class delete mode 100644 lion/out/test/classes/Date10_12/pasrser/HospitalParserTest.class delete mode 100644 lion/settings.gradle delete mode 100644 lion/src/main/java/Date10_12/FileController.java delete mode 100644 lion/src/main/java/Date10_12/Main.java delete mode 100644 lion/src/main/java/Date10_12/domain/Hospital.java delete mode 100644 lion/src/main/java/Date10_12/pasrser/HospitalParser.java delete mode 100644 lion/src/main/java/Date10_12/pasrser/Parser.java delete mode 100644 lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java index 4c61c80..8a0d579 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java @@ -1,19 +1,21 @@ package com.dbexercise; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.SQLException; +import com.dbexercise.domain.User; +import com.mysql.cj.protocol.Resultset; + +import java.sql.*; import java.util.Map; public class UserDao { + static Map env = System.getenv(); // 아래의 값들은 해킹 위험이 있으므로 코드상에 데이터를 넣지말고 + // 왼쪽 위에 메뉴바에서 망치 옆에 프로젝트를 눌러 edit configurations를 누르고 + // environments variables를 눌러 값을 입력해 준다. + static String dbHost = env.get("DB_HOST"); // DB 호스트 번호(AWS 주소) 가져옴 + static String dbUser = env.get("DB_USER"); // DB 호스트 이름 가져옴 + static String dbPassword = env.get("DB_PASSWORD"); // DB 비밀번호 가져옴 + public void add() throws SQLException, ClassNotFoundException { - Map env = System.getenv(); // 아래의 값들은 해킹 위험이 있으므로 코드상에 데이터를 넣지말고 - // 왼쪽 위에 메뉴바에서 망치 옆에 프로젝트를 눌러 edit configurations를 누르고 - // environments variables를 눌러 값을 입력해 준다. - String dbHost = env.get("DB_HOST"); // DB 호스트 번호(AWS 주소) - String dbUser = env.get("DB_USER"); // DB 호스트 이름 - String dbPassword = env.get("DB_PASSWORD"); // DB 비밀번호 + Class.forName("com.mysql.cj.jdbc.Driver"); // 만약 DB드라이버가 2개 이상일때 어떤 DB에 데이터를 삽입할 것인지 구분하기 위해 사용함 // 지금은 mysql 1개만 사용하기 때문에 없어도 됨 @@ -27,10 +29,32 @@ public void add() throws SQLException, ClassNotFoundException { ps.executeUpdate(); // ctrl + enter 즉, mysql에서 번개모양을 눌러 최신화 한다는 느낌 ps.close(); conn.close(); + System.out.println("데이터가 insert 됬습니다."); + } + + public User select(String id) throws SQLException, ClassNotFoundException { + Class.forName("com.mysql.cj.jdbc.Driver"); // 만약 DB드라이버가 2개 이상일때 어떤 DB에 데이터를 삽입할 것인지 구분하기 위해 사용함 + // 지금은 mysql 1개만 사용하기 때문에 없어도 됨 + Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); // db 연결(호스트,이름,비밀번호) + PreparedStatement ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); + ps.setString(1,id); // id는 get(String id)로 받은 id + ResultSet rs = ps.executeQuery(); // 쿼리문을 저장함 insert문과 달리 excuteQuery() 사용 + // rs에는 쿼리 실행 결과가 담겨져 있다. (select * from users where id = 1;) + rs.next(); + + // User 생성자를 통해 쿼리문에 id값을 넣어 찾은 id, name,password 값을 저장한다. + User user = new User(rs.getString("id"),rs.getString("name"),rs.getString("password")); + rs.close(); + ps.close(); + conn.close(); + return user; } public static void main(String[] args) throws SQLException, ClassNotFoundException { UserDao userDao = new UserDao(); - userDao.add(); + // userDao.add(); + User user = userDao.select("1"); + System.out.println(user.getName()); + System.out.println(user); } } diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/domain/User.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/domain/User.java new file mode 100644 index 0000000..9f1bc02 --- /dev/null +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/domain/User.java @@ -0,0 +1,32 @@ +package com.dbexercise.domain; + +public class User { + private String id; + private String name; + private String password; + + public User() { + } + + public User(String id, String name, String password) { + this.id = id; + this.name = name; + this.password = password; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getPassword() { + return password; + } + + public String toString(){ + return "id = "+this.id + " name = "+this.name+" password = "+this.password; + } +} diff --git a/lion/build.gradle b/lion/build.gradle deleted file mode 100644 index 3cae2d7..0000000 --- a/lion/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -plugins { - id 'java' -} - -group 'org.example' -version '1.0-SNAPSHOT' - -repositories { - mavenCentral() -} - -dependencies { - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' -} - -test { - useJUnitPlatform() -} \ No newline at end of file diff --git a/lion/gradlew b/lion/gradlew deleted file mode 100644 index 1b6c787..0000000 --- a/lion/gradlew +++ /dev/null @@ -1,234 +0,0 @@ -#!/bin/sh - -# -# Copyright © 2015-2021 the original authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# Darwin, MinGW, and NonStop. -# -# (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt -# within the Gradle project. -# -# You can find Gradle at https://github.com/gradle/gradle/. -# -############################################################################## - -# Attempt to set APP_HOME - -# Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac -done - -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" -APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD=maximum - -warn () { - echo "$*" -} >&2 - -die () { - echo - echo "$*" - echo - exit 1 -} >&2 - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac -fi - -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. - -# For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done -fi - -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. - -set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" - -# Use "xargs" to parse quoted args. -# -# With -n1 it outputs one arg per line, with the quotes and backslashes removed. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' - -exec "$JAVACMD" "$@" diff --git a/lion/gradlew.bat b/lion/gradlew.bat deleted file mode 100644 index 107acd3..0000000 --- a/lion/gradlew.bat +++ /dev/null @@ -1,89 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/lion/out/production/classes/Date10_12/LineReader.class b/lion/out/production/classes/Date10_12/LineReader.class deleted file mode 100644 index 9360de0192e128ca0195b4215366d6a9bbb0f0f2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1782 zcma)7*-{fh6g@o|m?T8hki;m;qNqt&B8nS9Trju=u!Pcr7i&lc91KZnGO_f<|L_ZZ z)hd-zs(kdp&#?Rqx6?C|g(X!!LE->a`&MX=8warz-TGCgG^n`Qeyk2~)Tc%ulPSt*9Rs~`$oHFo{p%)B` zdSW|+URCOWz57Pg(>U2)qzjQs``UvtD-v+3J-}sgPyvf#rD*0cl*n!9FZ6U#FRiB+ zZObgJXOga~W}C%y&aB$Z%D-k7jgnK_@ZJCx+cK)PqAhS}Z>+M)j>lcUSx(=ot*sfB zQD{`mSG5U)3WqevUVH@ z$GazSj#qs{(!0Epa#or
7414fjKMfLsW3m=}mNUz+B~vE&Yq(?B;Df$pXfS40cO zZE{^Lb=_NN6jQ*LkaHB>ublMvcz#BC?UQJ~<;@c%CcNQkohNp`seI?_F3{oJ2?A&K zJ959C`1C?ymqM?F$rTLpR_f+erSQj|K;W>m3e&Ptv_ATxh!JswtLJ<=*whw8O8p2W zHT)62_YN>l8|L*UsZpE*DI!i${gg69JB9(w@Niky3HRVeGFhA=h9kyr$!VNn zvEmrTStKZRn5ZOo)s_UaUV<(@Mf@;X4@3ElAq^uMI)9;0BgGiqDv8tHfSe=L9hGsM J=bnNK{{U|*g*E^H diff --git a/lion/out/production/classes/Date10_12/Main.class b/lion/out/production/classes/Date10_12/Main.class deleted file mode 100644 index cf8c688e6ef013c49e31b74385b8a4a8827121eb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1568 zcmah}-BJ`s7(Knr()%;81aKoUM3R_fQD6l%MnFsejhpNOx`qTLMKwzcqq{R(GqaZF zP4Wa@>jjjt%F1Mi|Ov~_k8F3y8n9j#~T1w@oNf$n31?7aXEz^ z%%l**l?1*v>(wN_!L>9dFq^_0=FRSU8k1NszZ(+YrqGY?jBZh4Nn%-`ciwTGa6zCa zH@+@lEqOayAX9W)z0#;{YyY0wu2M2s^eU>lu6)Ow4~15^=L7-+#bp)h>5E&_Gx?Ho z+&RXnaTUns9uyy`Cn{f6?ry#u`i{FhXYwTWyrAxcsw!}%%X`N&e)-#nN)t%=yG${3 zLL7o>MKN&iYPF+%=In~skuy}{p;OhaszufO2bDmw6)h?$GH8TOHD7dsknY)|3_Pp1 zSh#dz!uc-g@v;^eZn8;CJH!9k_mx9cd0bNUh!IVhfy8Z| z%U;8;=v%CpWto;tnR09lVOU_e)2$9a0%IL~m?3jB z&|agu)#7c-aUXhqO&K6lmEehuAMm3@(MAa?Hde7FamU78lx^I@Pd3)^vyES{Au!TO zevB*|_wm3uZ3^^vtV~gyyiOZew;$L z90st+dPML3`bvf$Bsbit<`FO`A&P&83E=WvBzTxS8ga2iStEBU!rj}GCH7e$jed*Uo z-BfugX~1JIJRak`IbbhcR#zu~9(E(=yCL-gdc!^HHRYDAI2b?A>aKbt12<4MFo`Jx z(@I=Z;$0hYw&`mz4i|c>EDa%6$5VVKkQPNDaIIq<%Bt(|6F;~81Fk&Za(w=#2Seau zah*Fzst8&VrIq*)!H({Je=E==W>WKZ-!gem!}sbbe-N0vcrM#Hb`ND#=ph?hR?}xu zYk1Cbt-J2wQCGmIIgadA+m`1^QuIeWn+PNPLfe+pYD;e}ycmDah__f^moDy{bT2)B zWFCLU@NZS(e<6aXTJ3hj_GLxGj{@_F{D#FQaP$A|aGM=cwMq>sRb^bIRG|ekYa^Ih zbHU8A3uYEwFtY+VXW3qF;62Kl+->oGinDJ14Ph?#k@_>Ry+t{JH03xlT#X`+B6n9q zYsOLHj`xBnSii)4Kf-)T8;xh?0MlIQBW>R4BV*2t^f6*iXZpyRGub{g^Ax!Yp9}N^ zW|$%FDC3@Bc9Zlv!%lLGjbxsyCH9gct+qoigILTc7J3diQF)oF0|j}Qssj;M=@c^~ z!AfzX7?~q-$jE(Kvo*mm|3a!TTF_51_LBP){fF#<>=l(oXczexSQxOnL2Knb`x>Kq zpuJ7sr5KypK?d0Yo9vNMJiClpVa+n0bip{qc->r1uPpL6ESc>n&px&iPG4I4!~E8@A07kFu*Y9o&|8y40ryt44x z!W)8lAOoom2}Z5nCgeYaJ&&-^l!5ncc-rxzW6|-sQf`J_;kQL3b)FXU>bHyu>&=fs zdAmEmcK6(Yh@;qx+|OY=kV^R9g--Vgg@L{i+*PZ{@A_;lRdy0&QE^aIlFQVRgLD8A%PUJ9vaLp*lw0 zS(=t7lx7Ddtjx2LL8j2jf8n1t+Am=QelcZtF|R}&?h zBe=1}O|@DzVWeuzMFo#p&tgl9SVFG!o;xh39d?+l`DSD50_IqC-k+H&=CCsAy^1HJ G`1BSV`OXml diff --git a/lion/out/production/classes/Date10_12/pasrser/Parser.class b/lion/out/production/classes/Date10_12/pasrser/Parser.class deleted file mode 100644 index dc2164f7cacf0de1fa3d0045c7c0df543053dd80..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 265 zcmX^0Z`VEs1_pBm9(D#Ub_Q-n2G)YaqT*CW1~mYfU5} z|D>$c>3jnQ)o+HSlrUuZEWA2?VQ~pq^RMgk|~H*k@$oz$tk_av5kGM z#J2?8(8Li0$!X$ZSE*Vx4funTI?e?GKY*WdxAzwiv$jK03WSqx=VhOHW_GkYzyI;` zZvY^H-~=a}wZofEu)$de5GLPpfY%A<;Jg#wh6{GMXa^q$z3-?gReP6%E}wsdgYK*8 zafJhSLQN^x^HZZr_NF|VM2{zt9+Q(Ja#m$_$JwpjQga+!NDRxGBJiIJVkjf$vN`3i3eD=T==5XMRTf!Yp+795@&O-@x9sl?eGa|mqXk2+8;xm#XQ5>s_eA`y z*;RVKM60`mZvI5qbovOjJH?J>RT^}yz@R)IHSZLN*_^ftb%IXh!;aLfas|n)rLysC zm#!AfnvNzRZPl#pnonwUhb1T0>=u1ewPqUVGK+JVuS}aIV{4JFE_EPulT}8W>&E6f zo|jmaidlS&_%@0V^T%~-`7YzU*D!XTnl&W*)~r`LA|J6nDjdUvZmjk-cpVcQ XN0b}o36= { - String filename = "C:\\DB file\\seoul_hospital_information.txt"; - Parser parser; - boolean isRemoveColumnName = true; - - public FileController(Parser parser) { - this.parser = parser; - } - - public FileController(Parser parser, boolean isRemoveColumnName) { - this.parser = parser; - this.isRemoveColumnName = isRemoveColumnName; - } - - List readLines() throws IOException { - List result = new ArrayList<>(); - BufferedReader br = new BufferedReader(new FileReader(filename)); - String str; - if (isRemoveColumnName) { - br.readLine(); - } - while ((str = br.readLine()) != null) { - result.add(parser.parse(str)); - } - return result; - } - -} diff --git a/lion/src/main/java/Date10_12/Main.java b/lion/src/main/java/Date10_12/Main.java deleted file mode 100644 index a539a26..0000000 --- a/lion/src/main/java/Date10_12/Main.java +++ /dev/null @@ -1,21 +0,0 @@ -package Date10_12; - -import Date10_12.domain.Hospital; -import Date10_12.pasrser.HospitalParser; - -import java.io.IOException; -import java.util.List; - -public class Main { - public static void main(String[] args) throws IOException { - FileController hospitalLineReader = new FileController<>(new HospitalParser()); - - List hospitals = hospitalLineReader.readLines(); // 파일에서 값을 1줄씩 전체 읽어 list에 저장 - - HospitalParser hospitalParser = new HospitalParser(); - hospitalParser.CreateFile(); // 파일 생성 - - hospitalParser.Filewrite(hospitals); - hospitalParser.DBFilewrite(hospitals); - } -} diff --git a/lion/src/main/java/Date10_12/domain/Hospital.java b/lion/src/main/java/Date10_12/domain/Hospital.java deleted file mode 100644 index a1f76ac..0000000 --- a/lion/src/main/java/Date10_12/domain/Hospital.java +++ /dev/null @@ -1,125 +0,0 @@ -package Date10_12.domain; - -import java.util.HashMap; -import java.util.Map; - -public class Hospital { - private String id; // [0] - private String address; //주소 [1] - private String district; //구 [1]수정 - private String category; //카테고리 [2] - private String name; //병원명 [10] - private String subDivision=""; //세부분과 [10] 수정 - private int emergencyRoom; //응급 운영 현황 [6] - - - public Hospital(String id, String address, String category, int emergencyRoom, - String name){ - this.id = id; - this.address = address; - this.category = category; - this.name = name; - this.emergencyRoom = emergencyRoom; - this.setDistrict(); - this.setCategory(); - this.setSubdivision(); - } - - public String getId() { - return id.replace("\"", ""); - } - - public String getAddress() { - return address; - } - - - public void setDistrict() { - String[] address = this.address.split(" "); - this.district = address[0] + " " + address[1]; - } - - public String getDistrict() { - return district; - } - - public void setCategory() { // 맵핑 - Map categorytmap = new HashMap<>(); - categorytmap.put("A","종합병원"); - categorytmap.put("B","병원"); - categorytmap.put("C","의원"); - categorytmap.put("D","요양병원"); - categorytmap.put("E","한방병원"); - categorytmap.put("G","한의원"); - categorytmap.put("I","기타"); - categorytmap.put("M","치과병원"); - categorytmap.put("N","치과의원"); - categorytmap.put("R","보건소"); - categorytmap.put("W","기타(구급차)"); - - this.category = categorytmap.get(category); - } - - public String getCategory() { - return category; - } - - public String setEmergencyRoom() { - if(emergencyRoom == 1){ - return "운영중"; - }else - return "운영안함"; - } - - public String getEmergencyRoom() { - return setEmergencyRoom(); - } - - public String getName() { - return name; - } - - private void setSubdivision(){ - String[] subdivisionList = new String[]{ - "치과", "성형외과", "한방병원", "한의원", "영상의학과", "이비인후과", "소아청소년과", "내과", "정형외과", "외과", - "가정의학과","피부과", "안과", "소아과", "요양병원", "비뇨기과", "정신건강의학과", "산부인과", "재활의학과", - "정신과", "마취통증의학과"}; - - for(String subdivision : subdivisionList){ - if(name.contains(subdivision)){ - subDivision=subdivision; - break; - }else - this.subDivision = "없음"; - } - - } - - public String getSubDivision() { - return subDivision; - } - - public String getSqlInsertQuery(){ - String sql = String.format("INSERT INTO `likelion-db`.`seoul_hospital`\n" + - "(`id`,`address`,`district`,`category`,`emergency_room`,`name`,`subdivision`)\n" + - "VALUES\n" + - "(\"%s\",\n" + - "\"%s\",\n" + - "\"%s\",\n" + - "\"%s\",\n" + - "%d,\n" + - "\"%s\",\n" + - "\"%s\");",this.id,this.address,this.district,this.category,this.emergencyRoom,this.name,this.subDivision); - - return sql; - } - - @Override - public String toString() { - return "\"" + this.id + "\"" + "," + "\"" + this.address + "\"" + "," + "\"" - + this.district + "\"" + "," + "\"" + this.category + "\"" + "," + this.emergencyRoom + "," + "\"" + - this.name + "\"" + "," + "\""+this.subDivision+ "\""; - } - - -} \ No newline at end of file diff --git a/lion/src/main/java/Date10_12/pasrser/HospitalParser.java b/lion/src/main/java/Date10_12/pasrser/HospitalParser.java deleted file mode 100644 index 8da3fb1..0000000 --- a/lion/src/main/java/Date10_12/pasrser/HospitalParser.java +++ /dev/null @@ -1,65 +0,0 @@ -package Date10_12.pasrser; - -import Date10_12.domain.Hospital; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.List; -import java.util.Map; - -// 클래스에서 alt+enter를 눌러 테스트를 할 수 있다. -public class HospitalParser implements Parser{ - - static String fileaddress = "C:\\Users\\qowhx\\AppData\\Roaming\\SPB_Data\\git\\Java-Study\\lion\\test.txt"; - static String DBfileaddress = "C:\\DB file\\seoul_hospital_infomation_parsingdata.txt"; - @Override - public Hospital parse(String str) { - str = str.replaceAll("\"",""); // "" 제거 - String[] splitted = str.split(","); - - return new Hospital(splitted[0],splitted[1],splitted[2],Integer.parseInt(splitted[6]),splitted[10]); - } - - public void CreateFile(){ // 파일 생성 - File file = new File(fileaddress); // 파일 생성 위치및 파일 이름 - try{ - System.out.println("파일 생성"); - file.createNewFile(); - }catch (IOException e){ - System.out.println("파일 생성 못함"); - throw new RuntimeException(); - } - } - - public void Filewrite(List hospitals){ // 파일 작성 - File file = new File(fileaddress); - - try{ - BufferedWriter writer = new BufferedWriter(new FileWriter(file)); - - for(Hospital hospital:hospitals){ // 참조변수로 받은 리스트만큼 반복 - writer.write(String.valueOf(hospital)+"\n"); // 참조변수로 받은 리스트의 값+"\n" 으로 파일에 작성 - } - writer.close(); - }catch (IOException e){ - e.printStackTrace(); - } - } - - public void DBFilewrite(List hospitals){ // 파일 작성 - File file = new File(DBfileaddress); - - try{ - BufferedWriter writer = new BufferedWriter(new FileWriter(file)); - - for(Hospital hospital:hospitals){ // 참조변수로 받은 리스트만큼 반복 - writer.write(hospital+"\n"); // 참조변수로 받은 리스트의 값+"\n" 으로 파일에 작성 - } - writer.close(); - }catch (IOException e){ - e.printStackTrace(); - } - } -} diff --git a/lion/src/main/java/Date10_12/pasrser/Parser.java b/lion/src/main/java/Date10_12/pasrser/Parser.java deleted file mode 100644 index ee5a7e8..0000000 --- a/lion/src/main/java/Date10_12/pasrser/Parser.java +++ /dev/null @@ -1,5 +0,0 @@ -package Date10_12.pasrser; - -public interface Parser { - T parse(String str); -} \ No newline at end of file diff --git a/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java b/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java deleted file mode 100644 index 0396372..0000000 --- a/lion/src/test/java/Date10_12/pasrser/HospitalParserTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package Date10_12.pasrser; - -import Date10_12.domain.Hospital; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -class HospitalParserTest { - String str = "\"A1120837\",\"서울특별시 송파구 동남로 208 (가락동)\",\"A\",\"의원\",\"G099\",\"응급의료기관 이외\",\"1\",\"토요일 첫째주 셋째주 휴진\",\"2005년 부터 진료 재활의학과전문의 전문물리치료 통증클리닉 척추교정치료 체외충격파 휜다리교정 목허리어깨무릎발 통증 디스크 퇴행성관절염\",\"극동아파트상가204호\",\"가로수치과의원\",\"02-448-6436\",\"02-2227-7777\",\"1900\",\"1900\",\"1900\",\"1900\",\"1900\",\"1500\",\"1400\",\"1600\",\"0900\",\"0900\",\"0900\",\"0900\",\"0900\",\"0900\",\"1000\",\"0900\",\"057\",\"83\",\"127.13147131787721\",\"37.49579508152157\",\"2022-09-07 14:55:30.0\""; - @Test - @DisplayName("ID가 파싱이 잘 되는지") - void idParsing() { - HospitalParser hospitalParser = new HospitalParser(); - Hospital hospital = hospitalParser.parse(str); - - String address = "서울특별시 송파구 동남로 208 (가락동)"; - Assertions.assertEquals("A1120837", hospital.getId()); - Assertions.assertEquals(address, hospital.getAddress()); - - String district = "서울특별시 송파구"; - Assertions.assertEquals(district, hospital.getDistrict()); - - String category = "종합병원"; - Assertions.assertEquals(category, hospital.getCategory()); - - String emergency = "운영중"; - Assertions.assertEquals(emergency, hospital.getEmergencyRoom()); - - String name = "가로수치과의원"; - Assertions.assertEquals(name, hospital.getName()); - - String subdivision = "치과"; - Assertions.assertEquals(subdivision, hospital.getSubDivision()); - } - @Test - @DisplayName("insert쿼리를 잘 만드는지 test") - void makeSqlQueryTest() { - - HospitalParser hospitalParser = new HospitalParser(); - Hospital hospital = hospitalParser.parse(this.str); - String sql ="INSERT INTO `likelion-db`.`seoul_hospital`\n" + - "(`id`,`address`,`district`,`category`,`emergency_room`,`name`,`subdivision`)\n" + - "VALUES\n" + - "(\"A1120837\",\n" + - "\"서울특별시 송파구 동남로 208 (가락동)\",\n" + - "\"서울특별시 송파구\",\n" + - "\"종합병원\",\n" + - "1,\n" + - "\"가로수치과의원\",\n" + - "\"치과\");"; - Assertions.assertEquals(sql, hospital.getSqlInsertQuery()); - } - -} From 54680ca01192ce2213eb0716be01c389370d6aa6 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Mon, 17 Oct 2022 17:49:33 +0900 Subject: [PATCH 141/307] First Commit --- Project/build.gradle | 21 ++++ Project/gradlew | 234 ++++++++++++++++++++++++++++++++++++++++ Project/gradlew.bat | 89 +++++++++++++++ Project/settings.gradle | 2 + 4 files changed, 346 insertions(+) create mode 100644 Project/build.gradle create mode 100644 Project/gradlew create mode 100644 Project/gradlew.bat create mode 100644 Project/settings.gradle diff --git a/Project/build.gradle b/Project/build.gradle new file mode 100644 index 0000000..db6e684 --- /dev/null +++ b/Project/build.gradle @@ -0,0 +1,21 @@ +plugins { + id 'java' +} + +group 'org.example' +version '1.0-SNAPSHOT' + +repositories { + mavenCentral() +} + +dependencies { + implementation 'mysql:mysql-connector-java:8.0.30' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' + +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/Project/gradlew b/Project/gradlew new file mode 100644 index 0000000..1b6c787 --- /dev/null +++ b/Project/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/Project/gradlew.bat b/Project/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/Project/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/Project/settings.gradle b/Project/settings.gradle new file mode 100644 index 0000000..3d0cdf1 --- /dev/null +++ b/Project/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'lion' + From adf093915ff3a26c6302604148627aaadbaa2e80 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Mon, 17 Oct 2022 17:50:16 +0900 Subject: [PATCH 142/307] DTO --- .../main/java/Date10_12/domain/Hospital.java | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 Project/src/main/java/Date10_12/domain/Hospital.java diff --git a/Project/src/main/java/Date10_12/domain/Hospital.java b/Project/src/main/java/Date10_12/domain/Hospital.java new file mode 100644 index 0000000..a1f76ac --- /dev/null +++ b/Project/src/main/java/Date10_12/domain/Hospital.java @@ -0,0 +1,125 @@ +package Date10_12.domain; + +import java.util.HashMap; +import java.util.Map; + +public class Hospital { + private String id; // [0] + private String address; //주소 [1] + private String district; //구 [1]수정 + private String category; //카테고리 [2] + private String name; //병원명 [10] + private String subDivision=""; //세부분과 [10] 수정 + private int emergencyRoom; //응급 운영 현황 [6] + + + public Hospital(String id, String address, String category, int emergencyRoom, + String name){ + this.id = id; + this.address = address; + this.category = category; + this.name = name; + this.emergencyRoom = emergencyRoom; + this.setDistrict(); + this.setCategory(); + this.setSubdivision(); + } + + public String getId() { + return id.replace("\"", ""); + } + + public String getAddress() { + return address; + } + + + public void setDistrict() { + String[] address = this.address.split(" "); + this.district = address[0] + " " + address[1]; + } + + public String getDistrict() { + return district; + } + + public void setCategory() { // 맵핑 + Map categorytmap = new HashMap<>(); + categorytmap.put("A","종합병원"); + categorytmap.put("B","병원"); + categorytmap.put("C","의원"); + categorytmap.put("D","요양병원"); + categorytmap.put("E","한방병원"); + categorytmap.put("G","한의원"); + categorytmap.put("I","기타"); + categorytmap.put("M","치과병원"); + categorytmap.put("N","치과의원"); + categorytmap.put("R","보건소"); + categorytmap.put("W","기타(구급차)"); + + this.category = categorytmap.get(category); + } + + public String getCategory() { + return category; + } + + public String setEmergencyRoom() { + if(emergencyRoom == 1){ + return "운영중"; + }else + return "운영안함"; + } + + public String getEmergencyRoom() { + return setEmergencyRoom(); + } + + public String getName() { + return name; + } + + private void setSubdivision(){ + String[] subdivisionList = new String[]{ + "치과", "성형외과", "한방병원", "한의원", "영상의학과", "이비인후과", "소아청소년과", "내과", "정형외과", "외과", + "가정의학과","피부과", "안과", "소아과", "요양병원", "비뇨기과", "정신건강의학과", "산부인과", "재활의학과", + "정신과", "마취통증의학과"}; + + for(String subdivision : subdivisionList){ + if(name.contains(subdivision)){ + subDivision=subdivision; + break; + }else + this.subDivision = "없음"; + } + + } + + public String getSubDivision() { + return subDivision; + } + + public String getSqlInsertQuery(){ + String sql = String.format("INSERT INTO `likelion-db`.`seoul_hospital`\n" + + "(`id`,`address`,`district`,`category`,`emergency_room`,`name`,`subdivision`)\n" + + "VALUES\n" + + "(\"%s\",\n" + + "\"%s\",\n" + + "\"%s\",\n" + + "\"%s\",\n" + + "%d,\n" + + "\"%s\",\n" + + "\"%s\");",this.id,this.address,this.district,this.category,this.emergencyRoom,this.name,this.subDivision); + + return sql; + } + + @Override + public String toString() { + return "\"" + this.id + "\"" + "," + "\"" + this.address + "\"" + "," + "\"" + + this.district + "\"" + "," + "\"" + this.category + "\"" + "," + this.emergencyRoom + "," + "\"" + + this.name + "\"" + "," + "\""+this.subDivision+ "\""; + } + + +} \ No newline at end of file From f8d1018fc205a0dee2f61d6680ea847a95e0d18d Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Mon, 17 Oct 2022 17:50:22 +0900 Subject: [PATCH 143/307] Main --- Project/src/main/java/Date10_12/Main.java | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Project/src/main/java/Date10_12/Main.java diff --git a/Project/src/main/java/Date10_12/Main.java b/Project/src/main/java/Date10_12/Main.java new file mode 100644 index 0000000..62b96ff --- /dev/null +++ b/Project/src/main/java/Date10_12/Main.java @@ -0,0 +1,24 @@ +package Date10_12; + +import Date10_12.domain.Hospital; +import Date10_12.pasrser.HospitalParser; + +import java.io.IOException; +import java.sql.SQLException; +import java.util.List; + +public class Main { + public static void main(String[] args) throws IOException, SQLException, ClassNotFoundException { + FileController hospitalLineReader = new FileController<>(new HospitalParser()); + + List hospitals = hospitalLineReader.readLines(); // 파일에서 값을 1줄씩 전체 읽어 list에 저장 + + HospitalParser hospitalParser = new HospitalParser(); + /* hospitalParser.CreateFile(); // 파일 생성 + + hospitalParser.Filewrite(hospitals); + hospitalParser.DBFilewrite(hospitals); + */ + hospitalParser.insert(hospitals); + } +} From 25bba2a30c253484e345032ba7f8706e63c4a860 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Mon, 17 Oct 2022 17:50:36 +0900 Subject: [PATCH 144/307] Parse(Interface) --- Project/src/main/java/Date10_12/pasrser/Parser.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Project/src/main/java/Date10_12/pasrser/Parser.java diff --git a/Project/src/main/java/Date10_12/pasrser/Parser.java b/Project/src/main/java/Date10_12/pasrser/Parser.java new file mode 100644 index 0000000..ee5a7e8 --- /dev/null +++ b/Project/src/main/java/Date10_12/pasrser/Parser.java @@ -0,0 +1,5 @@ +package Date10_12.pasrser; + +public interface Parser { + T parse(String str); +} \ No newline at end of file From 5b2bba3d1d4b1c58f9d807a648adb6c5333aade9 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Mon, 17 Oct 2022 17:50:56 +0900 Subject: [PATCH 145/307] =?UTF-8?q?Mysql=20Select=EB=A5=BC=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20DAO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/src/main/java/Date10_12/domain/User.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Project/src/main/java/Date10_12/domain/User.java diff --git a/Project/src/main/java/Date10_12/domain/User.java b/Project/src/main/java/Date10_12/domain/User.java new file mode 100644 index 0000000..8998467 --- /dev/null +++ b/Project/src/main/java/Date10_12/domain/User.java @@ -0,0 +1,4 @@ +package Date10_12.domain; + +public class User { +} From e1e321740b7c6bb6ddae6b16af168621348129b0 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Mon, 17 Oct 2022 17:51:59 +0900 Subject: [PATCH 146/307] =?UTF-8?q?HospitalParser(Mysql=20insert=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_12/pasrser/HospitalParser.java | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Project/src/main/java/Date10_12/pasrser/HospitalParser.java diff --git a/Project/src/main/java/Date10_12/pasrser/HospitalParser.java b/Project/src/main/java/Date10_12/pasrser/HospitalParser.java new file mode 100644 index 0000000..69db312 --- /dev/null +++ b/Project/src/main/java/Date10_12/pasrser/HospitalParser.java @@ -0,0 +1,82 @@ +package Date10_12.pasrser; + +import Date10_12.domain.Hospital; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.List; +import java.util.Map; + +// 클래스에서 alt+enter를 눌러 테스트를 할 수 있다. +public class HospitalParser implements Parser{ + + static String fileaddress = "C:\\Users\\qowhx\\AppData\\Roaming\\SPB_Data\\git\\Java-Study\\lion\\test.txt"; + static Map env = System.getenv(); // 아래의 값들은 해킹 위험이 있으므로 코드상에 데이터를 넣지말고 + // 왼쪽 위에 메뉴바에서 망치 옆에 프로젝트를 눌러 edit configurations를 누르고 + // environments variables를 눌러 값을 입력해 준다. + static String dbHost = env.get("DB_HOST"); // DB 호스트 번호(AWS 주소) 가져옴 + static String dbUser = env.get("DB_USER"); // DB 호스트 이름 가져옴 + static String dbPassword = env.get("DB_PASSWORD"); // DB 비밀번호 가져옴 + + @Override + public Hospital parse(String str) { + str = str.replaceAll("\"",""); // "" 제거 + String[] splitted = str.split(","); + + return new Hospital(splitted[0],splitted[1],splitted[2],Integer.parseInt(splitted[6]),splitted[10]); + } + + public void CreateFile(){ // 파일 생성 + File file = new File(fileaddress); // 파일 생성 위치및 파일 이름 + try{ + System.out.println("파일 생성"); + file.createNewFile(); + }catch (IOException e){ + System.out.println("파일 생성 못함"); + throw new RuntimeException(); + } + } + + public void Filewrite(List hospitals){ // 파일 작성 + File file = new File(fileaddress); + + try{ + BufferedWriter writer = new BufferedWriter(new FileWriter(file)); + + for(Hospital hospital:hospitals){ // 참조변수로 받은 리스트만큼 반복 + writer.write(String.valueOf(hospital)+"\n"); // 참조변수로 받은 리스트의 값+"\n" 으로 파일에 작성 + } + writer.close(); + }catch (IOException e){ + e.printStackTrace(); + } + } + + public void insert(List hospitals) throws ClassNotFoundException, SQLException { // 자바 코드를 통해 바로 MYSQL에 데이터 삽입 + Class.forName("com.mysql.cj.jdbc.Driver"); // 만약 DB드라이버가 2개 이상일때 어떤 DB에 데이터를 삽입할 것인지 구분하기 위해 사용함 + // 지금은 mysql 1개만 사용하기 때문에 없어도 됨 + Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); // db 연결(호스트,이름,비밀번호) + PreparedStatement ps = conn.prepareStatement("INSERT INTO test(id,address,district,category,emergency_room,name,subdivision) VALUES(?,?,?,?,?,?,?)"); + + + for(int i =0; i Date: Mon, 17 Oct 2022 17:52:50 +0900 Subject: [PATCH 147/307] Controller --- .../main/java/Date10_12/FileController.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Project/src/main/java/Date10_12/FileController.java diff --git a/Project/src/main/java/Date10_12/FileController.java b/Project/src/main/java/Date10_12/FileController.java new file mode 100644 index 0000000..e52a40a --- /dev/null +++ b/Project/src/main/java/Date10_12/FileController.java @@ -0,0 +1,38 @@ +package Date10_12; + +import Date10_12.pasrser.Parser; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class FileController { + String filename = "C:\\DB file\\seoul_hospital_information.txt"; + Parser parser; + boolean isRemoveColumnName = true; + + public FileController(Parser parser) { + this.parser = parser; + } + + public FileController(Parser parser, boolean isRemoveColumnName) { + this.parser = parser; + this.isRemoveColumnName = isRemoveColumnName; + } + + List readLines() throws IOException { + List result = new ArrayList<>(); + BufferedReader br = new BufferedReader(new FileReader(filename)); + String str; + if (isRemoveColumnName) { + br.readLine(); + } + while ((str = br.readLine()) != null) { + result.add(parser.parse(str)); + } + return result; + } + +} From d9be8be6694b0fed61519d710f1786c9afe1da14 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 18 Oct 2022 09:29:31 +0900 Subject: [PATCH 148/307] =?UTF-8?q?=EC=82=AC=EA=B0=81=ED=98=95=20=EB=B3=84?= =?UTF-8?q?=EC=B0=8D=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Date10_18/Algorithm/Square.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 git/Lion-Java/src/Date10_18/Algorithm/Square.java diff --git a/git/Lion-Java/src/Date10_18/Algorithm/Square.java b/git/Lion-Java/src/Date10_18/Algorithm/Square.java new file mode 100644 index 0000000..bdcf7f1 --- /dev/null +++ b/git/Lion-Java/src/Date10_18/Algorithm/Square.java @@ -0,0 +1,24 @@ +package Date10_18.Algorithm; + + +// 정사각형 +public class Square { + public static void main(String[] args) { + Square s = new Square(); + s.printSquare(3); + System.out.println(); + s.printRectangle(3,5); + } + + void printSquare(int n){ // 정사각형 + for(int i=0; i Date: Tue, 18 Oct 2022 09:47:12 +0900 Subject: [PATCH 149/307] =?UTF-8?q?=ED=8F=89=ED=96=89=EC=82=AC=EB=B3=80?= =?UTF-8?q?=ED=98=95=20=EB=B3=84=EC=B0=8D=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_18/Algorithm/Parallelogram.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 git/Lion-Java/src/Date10_18/Algorithm/Parallelogram.java diff --git a/git/Lion-Java/src/Date10_18/Algorithm/Parallelogram.java b/git/Lion-Java/src/Date10_18/Algorithm/Parallelogram.java new file mode 100644 index 0000000..be30ff5 --- /dev/null +++ b/git/Lion-Java/src/Date10_18/Algorithm/Parallelogram.java @@ -0,0 +1,25 @@ +package Date10_18.Algorithm; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +// 평행사변형 +public class Parallelogram { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int num = Integer.parseInt(br.readLine()); + + new Parallelogram().parallelogram(num); + } + + public void parallelogram(int n){ + for(int i=0; i Date: Tue, 18 Oct 2022 23:04:00 +0900 Subject: [PATCH 150/307] =?UTF-8?q?DAO=20=20(MYSQL=20=EC=97=B0=EB=8F=99)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/Date10_12/dao/UserDao.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Project/src/main/java/Date10_12/dao/UserDao.java diff --git a/Project/src/main/java/Date10_12/dao/UserDao.java b/Project/src/main/java/Date10_12/dao/UserDao.java new file mode 100644 index 0000000..258cc8c --- /dev/null +++ b/Project/src/main/java/Date10_12/dao/UserDao.java @@ -0,0 +1,63 @@ +package Date10_12.dao; + +import Date10_12.domain.User; + +import java.sql.*; +import java.util.Map; + +public class UserDao { + + static Map env = System.getenv(); // 아래의 값들은 해킹 위험이 있으므로 코드상에 데이터를 넣지말고 + // 왼쪽 위에 메뉴바에서 망치 옆에 프로젝트를 눌러 edit configurations를 누르고 + // environments variables를 눌러 값을 입력해 준다. + private static String dbHost = env.get("DB_HOST"); // DB 호스트 번호(AWS 주소) 가져옴 + private static String dbUser = env.get("DB_USER"); // DB 호스트 이름 가져옴 + private static String dbPassword = env.get("DB_PASSWORD"); // DB 비밀번호 가져옴 + + + public void add() throws ClassNotFoundException { + + try{ + Class.forName("com.mysql.cj.jdbc.Driver"); // 만약 DB드라이버가 2개 이상일때 어떤 DB에 데이터를 삽입할 것인지 구분하기 위해 사용함 + // 지금은 mysql 1개만 사용하기 때문에 없어도 됨 + Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); // db 연결(호스트,이름,비밀번호) + PreparedStatement ps = conn.prepareStatement("INSERT INTO users(id,name,password) VALUES(?,?,?)"); + ps.setString(1,"5"); // mysql 테이블로 값 insert + ps.setString(2,"hello"); + ps.setString(3,"aaaa"); + + ps.executeUpdate(); // ctrl + enter 즉, mysql에서 번개모양을 눌러 최신화 한다는 느낌 + ps.close(); + conn.close(); + System.out.println("데이터가 insert 됬습니다."); + + }catch (SQLException e){ + throw new RuntimeException(e); + } + + } + + public User select(String id) throws SQLException, ClassNotFoundException { + Class.forName("com.mysql.cj.jdbc.Driver"); // 만약 DB드라이버가 2개 이상일때 어떤 DB에 데이터를 삽입할 것인지 구분하기 위해 사용함 + // 지금은 mysql 1개만 사용하기 때문에 없어도 됨 + Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); // db 연결(호스트,이름,비밀번호) + PreparedStatement ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); + ps.setString(1,id); // id는 get(String id)로 받은 id + ResultSet rs = ps.executeQuery(); // 쿼리문을 저장함 insert문과 달리 excuteQuery() 사용 + // rs에는 쿼리 실행 결과가 담겨져 있다. (select * from users where id = 1;) + rs.next(); + + // User 생성자를 통해 쿼리문에 id값을 넣어 찾은 id, name,password 값을 저장한다. + User user = new User(rs.getString("id"),rs.getString("name"),rs.getString("password")); + rs.close(); + ps.close(); + conn.close(); + return user; + } + + public static void main(String[] args) throws ClassNotFoundException, SQLException { + UserDao userDao = new UserDao(); + // userDao.add(); + System.out.println(userDao.select("1")); + } +} From 673a78961dd23baef67c4c3a9282cb12f0fa3b77 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 18 Oct 2022 23:05:17 +0900 Subject: [PATCH 151/307] =?UTF-8?q?DTO=20(MYSQL=20=EC=97=B0=EB=8F=99)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/dbexercise/UserDao.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java index 8a0d579..48a1f9c 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java @@ -18,7 +18,7 @@ public void add() throws SQLException, ClassNotFoundException { Class.forName("com.mysql.cj.jdbc.Driver"); // 만약 DB드라이버가 2개 이상일때 어떤 DB에 데이터를 삽입할 것인지 구분하기 위해 사용함 - // 지금은 mysql 1개만 사용하기 때문에 없어도 됨 + // 지금은 mysql 1개만 사용하기 때문에 없어도 됨 Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); // db 연결(호스트,이름,비밀번호) PreparedStatement ps = conn.prepareStatement("INSERT INTO users(id,name,password) VALUES(?,?,?)"); ps.setString(1,"4"); // mysql 테이블로 값 insert @@ -32,23 +32,23 @@ public void add() throws SQLException, ClassNotFoundException { System.out.println("데이터가 insert 됬습니다."); } - public User select(String id) throws SQLException, ClassNotFoundException { - Class.forName("com.mysql.cj.jdbc.Driver"); // 만약 DB드라이버가 2개 이상일때 어떤 DB에 데이터를 삽입할 것인지 구분하기 위해 사용함 - // 지금은 mysql 1개만 사용하기 때문에 없어도 됨 - Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); // db 연결(호스트,이름,비밀번호) - PreparedStatement ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); - ps.setString(1,id); // id는 get(String id)로 받은 id - ResultSet rs = ps.executeQuery(); // 쿼리문을 저장함 insert문과 달리 excuteQuery() 사용 - // rs에는 쿼리 실행 결과가 담겨져 있다. (select * from users where id = 1;) - rs.next(); - - // User 생성자를 통해 쿼리문에 id값을 넣어 찾은 id, name,password 값을 저장한다. - User user = new User(rs.getString("id"),rs.getString("name"),rs.getString("password")); - rs.close(); - ps.close(); - conn.close(); - return user; - } + public User select(String id) throws SQLException, ClassNotFoundException { + Class.forName("com.mysql.cj.jdbc.Driver"); // 만약 DB드라이버가 2개 이상일때 어떤 DB에 데이터를 삽입할 것인지 구분하기 위해 사용함 + // 지금은 mysql 1개만 사용하기 때문에 없어도 됨 + Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); // db 연결(호스트,이름,비밀번호) + PreparedStatement ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); + ps.setString(1,id); // id는 get(String id)로 받은 id + ResultSet rs = ps.executeQuery(); // 쿼리문을 저장함 insert문과 달리 excuteQuery() 사용 + // rs에는 쿼리 실행 결과가 담겨져 있다. (select * from users where id = 1;) + rs.next(); + + // User 생성자를 통해 쿼리문에 id값을 넣어 찾은 id, name,password 값을 저장한다. + User user = new User(rs.getString("id"),rs.getString("name"),rs.getString("password")); + rs.close(); + ps.close(); + conn.close(); + return user; + } public static void main(String[] args) throws SQLException, ClassNotFoundException { UserDao userDao = new UserDao(); From a1092df8f077f141cf68036f6c14fbfb3652a06e Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 18 Oct 2022 23:06:45 +0900 Subject: [PATCH 152/307] =?UTF-8?q?DTO=20=20(MYSQL=20=EC=97=B0=EB=8F=99)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/Date10_12/domain/User.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Project/src/main/java/Date10_12/domain/User.java b/Project/src/main/java/Date10_12/domain/User.java index 8998467..fd95dd8 100644 --- a/Project/src/main/java/Date10_12/domain/User.java +++ b/Project/src/main/java/Date10_12/domain/User.java @@ -1,4 +1,32 @@ package Date10_12.domain; public class User { + private String id; + private String name; + private String password; + + public User() { + } + + public User(String id, String name, String password) { + this.id = id; + this.name = name; + this.password = password; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getPassword() { + return password; + } + + public String toString(){ + return "id = "+this.id + " name = "+this.name+" password = "+this.password; + } } From 4bc1e83f3595e6595d27ab1f899ce19e2df46c29 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 18 Oct 2022 23:11:36 +0900 Subject: [PATCH 153/307] =?UTF-8?q?DAO=20(MYSQL=20=EC=97=B0=EB=8F=99=20-?= =?UTF-8?q?=20user=ED=98=95=EC=8B=9D=EC=9C=BC=EB=A1=9C=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EC=9E=85=EB=A0=A5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/dbexercise/UserDao.java | 77 ++++++++++--------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java index 48a1f9c..cfea73c 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java @@ -1,60 +1,63 @@ package com.dbexercise; import com.dbexercise.domain.User; -import com.mysql.cj.protocol.Resultset; import java.sql.*; import java.util.Map; public class UserDao { + static Map env = System.getenv(); // 아래의 값들은 해킹 위험이 있으므로 코드상에 데이터를 넣지말고 // 왼쪽 위에 메뉴바에서 망치 옆에 프로젝트를 눌러 edit configurations를 누르고 // environments variables를 눌러 값을 입력해 준다. - static String dbHost = env.get("DB_HOST"); // DB 호스트 번호(AWS 주소) 가져옴 - static String dbUser = env.get("DB_USER"); // DB 호스트 이름 가져옴 - static String dbPassword = env.get("DB_PASSWORD"); // DB 비밀번호 가져옴 - - public void add() throws SQLException, ClassNotFoundException { - - - Class.forName("com.mysql.cj.jdbc.Driver"); // 만약 DB드라이버가 2개 이상일때 어떤 DB에 데이터를 삽입할 것인지 구분하기 위해 사용함 - // 지금은 mysql 1개만 사용하기 때문에 없어도 됨 - Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); // db 연결(호스트,이름,비밀번호) - PreparedStatement ps = conn.prepareStatement("INSERT INTO users(id,name,password) VALUES(?,?,?)"); - ps.setString(1,"4"); // mysql 테이블로 값 insert - ps.setString(2,"hi"); - ps.setString(3,"1234"); + private static String dbHost = env.get("DB_HOST"); // DB 호스트 번호(AWS 주소) 가져옴 + private static String dbUser = env.get("DB_USER"); // DB 호스트 이름 가져옴 + private static String dbPassword = env.get("DB_PASSWORD"); // DB 비밀번호 가져옴 - ps.executeUpdate(); // ctrl + enter 즉, mysql에서 번개모양을 눌러 최신화 한다는 느낌 - ps.close(); - conn.close(); - System.out.println("데이터가 insert 됬습니다."); - } + public void add(User user) throws ClassNotFoundException { - public User select(String id) throws SQLException, ClassNotFoundException { + try{ Class.forName("com.mysql.cj.jdbc.Driver"); // 만약 DB드라이버가 2개 이상일때 어떤 DB에 데이터를 삽입할 것인지 구분하기 위해 사용함 // 지금은 mysql 1개만 사용하기 때문에 없어도 됨 Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); // db 연결(호스트,이름,비밀번호) - PreparedStatement ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); - ps.setString(1,id); // id는 get(String id)로 받은 id - ResultSet rs = ps.executeQuery(); // 쿼리문을 저장함 insert문과 달리 excuteQuery() 사용 - // rs에는 쿼리 실행 결과가 담겨져 있다. (select * from users where id = 1;) - rs.next(); - - // User 생성자를 통해 쿼리문에 id값을 넣어 찾은 id, name,password 값을 저장한다. - User user = new User(rs.getString("id"),rs.getString("name"),rs.getString("password")); - rs.close(); + PreparedStatement ps = conn.prepareStatement("INSERT INTO users(id,name,password) VALUES(?,?,?)"); + ps.setString(1,user.getId()); // mysql 테이블로 값 insert + ps.setString(2,user.getName()); + ps.setString(3,user.getPassword()); + + ps.executeUpdate(); // ctrl + enter 즉, mysql에서 번개모양을 눌러 최신화 한다는 느낌 ps.close(); conn.close(); - return user; + System.out.println("데이터가 insert 됬습니다."); + + }catch (SQLException e){ + throw new RuntimeException(e); } - public static void main(String[] args) throws SQLException, ClassNotFoundException { + } + + public User select(String id) throws SQLException, ClassNotFoundException { + Class.forName("com.mysql.cj.jdbc.Driver"); // 만약 DB드라이버가 2개 이상일때 어떤 DB에 데이터를 삽입할 것인지 구분하기 위해 사용함 + // 지금은 mysql 1개만 사용하기 때문에 없어도 됨 + Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); // db 연결(호스트,이름,비밀번호) + PreparedStatement ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); + ps.setString(1,id); // id는 get(String id)로 받은 id + ResultSet rs = ps.executeQuery(); // 쿼리문을 저장함 insert문과 달리 excuteQuery() 사용 + // rs에는 쿼리 실행 결과가 담겨져 있다. (select * from users where id = 1;) + rs.next(); + + // User 생성자를 통해 쿼리문에 id값을 넣어 찾은 id, name,password 값을 저장한다. + User user = new User(rs.getString("id"),rs.getString("name"),rs.getString("password")); + rs.close(); + ps.close(); + conn.close(); + return user; + } + + public static void main(String[] args) throws ClassNotFoundException, SQLException { UserDao userDao = new UserDao(); - // userDao.add(); - User user = userDao.select("1"); - System.out.println(user.getName()); - System.out.println(user); + userDao.add(new User("7","Ruru","1234qwer")); // user로 값을 받아 DTO에 저장한 후 mysql로 데이터 보냄 + System.out.println(userDao.select("1")); } -} +} \ No newline at end of file From 6a05abf9346db2b3f8e408aed8e5b2687ff445db Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 18 Oct 2022 23:36:09 +0900 Subject: [PATCH 154/307] =?UTF-8?q?TDD(user=20=ED=98=95=EC=8B=9D=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EA=B0=92=20=EC=9E=85=EB=A0=A5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/com/dbexercise/UserDaoTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java diff --git a/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java b/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java new file mode 100644 index 0000000..59dc68c --- /dev/null +++ b/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java @@ -0,0 +1,23 @@ +package com.dbexercise; + +import com.dbexercise.domain.User; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.sql.SQLException; + +import static org.junit.jupiter.api.Assertions.*; + +class UserDaoTest { + + @Test + void addAndSelect() throws ClassNotFoundException, SQLException { + UserDao userDao = new UserDao(); + String id = "9"; + User user = new User(id,"test","1234"); // user 값을 DTO에 저장함 + userDao.add(user); + + User selectedUser = userDao.select(id); // DTO에 저장되어 있는 데이터를 가져와 비교함 + Assertions.assertEquals("test",selectedUser.getName()); + } +} \ No newline at end of file From 96caf60bb640cbbe295941fe15ab8889d7357820 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 18 Oct 2022 23:36:39 +0900 Subject: [PATCH 155/307] =?UTF-8?q?DAO(=EC=A4=91=EB=B3=B5=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EB=B6=84=EB=A6=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/dbexercise/UserDao.java | 60 +++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java index cfea73c..e0d1eee 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java @@ -7,21 +7,28 @@ public class UserDao { - static Map env = System.getenv(); // 아래의 값들은 해킹 위험이 있으므로 코드상에 데이터를 넣지말고 - // 왼쪽 위에 메뉴바에서 망치 옆에 프로젝트를 눌러 edit configurations를 누르고 - // environments variables를 눌러 값을 입력해 준다. - private static String dbHost = env.get("DB_HOST"); // DB 호스트 번호(AWS 주소) 가져옴 - private static String dbUser = env.get("DB_USER"); // DB 호스트 이름 가져옴 - private static String dbPassword = env.get("DB_PASSWORD"); // DB 비밀번호 가져옴 + private Connection makeConnection() throws ClassNotFoundException, SQLException { + Map env = System.getenv(); // 아래의 값들은 해킹 위험이 있으므로 코드상에 데이터를 넣지말고 + // 왼쪽 위에 메뉴바에서 망치 옆에 프로젝트를 눌러 edit configurations를 누르고 + // environments variables를 눌러 값을 입력해 준다. + String dbHost = env.get("DB_HOST"); // DB 호스트 번호(AWS 주소) 가져옴 + String dbUser = env.get("DB_USER"); // DB 호스트 이름 가져옴 + String dbPassword = env.get("DB_PASSWORD"); // DB 비밀번호 가져옴 + Class.forName("com.mysql.cj.jdbc.Driver"); // 만약 DB드라이버가 2개 이상일때 어떤 DB에 데이터를 삽입할 것인지 구분하기 위해 사용함 + // 지금은 mysql 1개만 사용하기 때문에 없어도 됨 + Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); + + return conn; + } public void add(User user) throws ClassNotFoundException { try{ - Class.forName("com.mysql.cj.jdbc.Driver"); // 만약 DB드라이버가 2개 이상일때 어떤 DB에 데이터를 삽입할 것인지 구분하기 위해 사용함 - // 지금은 mysql 1개만 사용하기 때문에 없어도 됨 - Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); // db 연결(호스트,이름,비밀번호) - PreparedStatement ps = conn.prepareStatement("INSERT INTO users(id,name,password) VALUES(?,?,?)"); + // db 연결(호스트,이름,비밀번호) + Connection conn = makeConnection(); // 설정들을 모아둔 메서드 호출 + + PreparedStatement ps = conn.prepareStatement("INSERT INTO users(id,name,password) VALUES(?,?,?)"); ps.setString(1,user.getId()); // mysql 테이블로 값 insert ps.setString(2,user.getName()); ps.setString(3,user.getPassword()); @@ -38,21 +45,24 @@ public void add(User user) throws ClassNotFoundException { } public User select(String id) throws SQLException, ClassNotFoundException { - Class.forName("com.mysql.cj.jdbc.Driver"); // 만약 DB드라이버가 2개 이상일때 어떤 DB에 데이터를 삽입할 것인지 구분하기 위해 사용함 - // 지금은 mysql 1개만 사용하기 때문에 없어도 됨 - Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); // db 연결(호스트,이름,비밀번호) - PreparedStatement ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); - ps.setString(1,id); // id는 get(String id)로 받은 id - ResultSet rs = ps.executeQuery(); // 쿼리문을 저장함 insert문과 달리 excuteQuery() 사용 - // rs에는 쿼리 실행 결과가 담겨져 있다. (select * from users where id = 1;) - rs.next(); - - // User 생성자를 통해 쿼리문에 id값을 넣어 찾은 id, name,password 값을 저장한다. - User user = new User(rs.getString("id"),rs.getString("name"),rs.getString("password")); - rs.close(); - ps.close(); - conn.close(); - return user; + + try { + Connection conn = makeConnection(); + PreparedStatement ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); + ps.setString(1, id); // id는 get(String id)로 받은 id + ResultSet rs = ps.executeQuery(); // 쿼리문을 저장함 insert문과 달리 excuteQuery() 사용 + // rs에는 쿼리 실행 결과가 담겨져 있다. (select * from users where id = 1;) + rs.next(); + + // User 생성자를 통해 쿼리문에 id값을 넣어 찾은 id, name,password 값을 저장한다. + User user = new User(rs.getString("id"), rs.getString("name"), rs.getString("password")); + rs.close(); + ps.close(); + conn.close(); + return user; + }catch (SQLException e){ + throw new RuntimeException(e); + } } public static void main(String[] args) throws ClassNotFoundException, SQLException { From 16b079190153f4efe50e781be468ebbbb0dc6680 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 18 Oct 2022 23:55:07 +0900 Subject: [PATCH 156/307] =?UTF-8?q?DAO(=EC=A4=91=EB=B3=B5=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EB=B6=84=EB=A6=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/dbexercise/{ => dao}/UserDao.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Java-Mysql-Connect/src/main/java/com/dbexercise/{ => dao}/UserDao.java (99%) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDao.java similarity index 99% rename from Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java rename to Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDao.java index e0d1eee..3bfa2ef 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/UserDao.java +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDao.java @@ -1,4 +1,4 @@ -package com.dbexercise; +package com.dbexercise.dao; import com.dbexercise.domain.User; From 7a4bb7d20b51dbfdab5f6aad6f15924ed655cefc Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 18 Oct 2022 23:55:30 +0900 Subject: [PATCH 157/307] =?UTF-8?q?DAO(=EC=B6=94=EC=83=81=ED=99=94=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9-DB=EA=B5=AC=EB=B3=84=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dbexercise/dao/UserDaoAbstract.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java new file mode 100644 index 0000000..736a1cf --- /dev/null +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java @@ -0,0 +1,63 @@ +package com.dbexercise.dao; + +import com.dbexercise.domain.User; + +import java.sql.*; +import java.util.Map; + +public abstract class UserDaoAbstract { + + public abstract Connection makeConnection() throws SQLException; + // DB를 여러개 동시에 사용하는 경우 각 DB에 연결시켜야 하므로 추상화 클래스를 상속받아 + // 원하는 DB로 연결시키는 방식에 사용 + + + public void add(User user) throws ClassNotFoundException { + + try{ + // db 연결(호스트,이름,비밀번호) + Connection conn = makeConnection(); // 설정들을 모아둔 메서드 호출 + + PreparedStatement ps = conn.prepareStatement("INSERT INTO users(id,name,password) VALUES(?,?,?)"); + ps.setString(1,user.getId()); // mysql 테이블로 값 insert + ps.setString(2,user.getName()); + ps.setString(3,user.getPassword()); + + ps.executeUpdate(); // ctrl + enter 즉, mysql에서 번개모양을 눌러 최신화 한다는 느낌 + ps.close(); + conn.close(); + System.out.println("데이터가 insert 됬습니다."); + + }catch (SQLException e){ + throw new RuntimeException(e); + } + + } + + public User select(String id) throws SQLException, ClassNotFoundException { + + try { + Connection conn = makeConnection(); + PreparedStatement ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); + ps.setString(1, id); // id는 get(String id)로 받은 id + ResultSet rs = ps.executeQuery(); // 쿼리문을 저장함 insert문과 달리 excuteQuery() 사용 + // rs에는 쿼리 실행 결과가 담겨져 있다. (select * from users where id = 1;) + rs.next(); + + // User 생성자를 통해 쿼리문에 id값을 넣어 찾은 id, name,password 값을 저장한다. + User user = new User(rs.getString("id"), rs.getString("name"), rs.getString("password")); + rs.close(); + ps.close(); + conn.close(); + return user; + }catch (SQLException e){ + throw new RuntimeException(e); + } + } + + public static void main(String[] args) throws ClassNotFoundException, SQLException { + UserDao userDao = new UserDao(); + userDao.add(new User("7","Ruru","1234qwer")); // user로 값을 받아 DTO에 저장한 후 mysql로 데이터 보냄 + System.out.println(userDao.select("1")); + } +} From e17c4f5f389dd01bc78cf2b1d6f9a64f5364111a Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 18 Oct 2022 23:55:45 +0900 Subject: [PATCH 158/307] =?UTF-8?q?DAO(AWS=20=EC=A0=80=EC=9E=A5=EC=86=8C?= =?UTF-8?q?=20=EC=97=B0=EA=B2=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dbexercise/dao/AWSUserDaoImpl.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSUserDaoImpl.java diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSUserDaoImpl.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSUserDaoImpl.java new file mode 100644 index 0000000..e98d29e --- /dev/null +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSUserDaoImpl.java @@ -0,0 +1,26 @@ +package com.dbexercise.dao; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Map; + +// 추상화 클래스 상속 받음 +// AWS 저장소에 연결함 +public class AWSUserDaoImpl extends UserDaoAbstract{ + @Override + public Connection makeConnection() throws SQLException { + Map env = System.getenv(); // 아래의 값들은 해킹 위험이 있으므로 코드상에 데이터를 넣지말고 + // 왼쪽 위에 메뉴바에서 망치 옆에 프로젝트를 눌러 edit configurations를 누르고 + // environments variables를 눌러 값을 입력해 준다. + String dbHost = env.get("DB_HOST"); // DB 호스트 번호(AWS 주소) 가져옴 + String dbUser = env.get("DB_USER"); // DB 호스트 이름 가져옴 + String dbPassword = env.get("DB_PASSWORD"); // DB 비밀번호 가져옴 + + Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); + + // 외부에서 주소와 호스트정보 비밀번호 입력 + + return conn; + } +} From 8a8188a5ce29b67652948cfcf00440429d2c86b4 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 18 Oct 2022 23:55:54 +0900 Subject: [PATCH 159/307] =?UTF-8?q?DAO(Local=20=EC=A0=80=EC=9E=A5=EC=86=8C?= =?UTF-8?q?=20=EC=97=B0=EA=B2=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dbexercise/dao/LocalUserDaoImpl.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Java-Mysql-Connect/src/main/java/com/dbexercise/dao/LocalUserDaoImpl.java diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/LocalUserDaoImpl.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/LocalUserDaoImpl.java new file mode 100644 index 0000000..7b5b7f8 --- /dev/null +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/LocalUserDaoImpl.java @@ -0,0 +1,24 @@ +package com.dbexercise.dao; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Map; + +// 추상화 상속받음 +// 로컬 저장소 연결 +public class LocalUserDaoImpl extends UserDaoAbstract{ + @Override + public Connection makeConnection() throws SQLException { + Map env = System.getenv(); // 아래의 값들은 해킹 위험이 있으므로 코드상에 데이터를 넣지말고 + // 왼쪽 위에 메뉴바에서 망치 옆에 프로젝트를 눌러 edit configurations를 누르고 + // environments variables를 눌러 값을 입력해 준다. + + Connection conn = DriverManager.getConnection( + "jdbc:mysql://localhost:3306" + ,"root","12345678"); + // Local 저장소는 데이터를 코드상에 입력해도 해커가 털어가기 힘들다. + + return conn; + } +} From f3278c6e382ea2b1c6d231431d9a5c020a24461d Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 18 Oct 2022 23:56:07 +0900 Subject: [PATCH 160/307] =?UTF-8?q?TDD(=EC=B6=94=EC=83=81=ED=99=94=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=82=AC=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/test/java/com/dbexercise/UserDaoTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java b/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java index 59dc68c..fda8ab3 100644 --- a/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java +++ b/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java @@ -1,19 +1,19 @@ package com.dbexercise; +import com.dbexercise.dao.AWSUserDaoImpl; +import com.dbexercise.dao.UserDao; import com.dbexercise.domain.User; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.sql.SQLException; -import static org.junit.jupiter.api.Assertions.*; - class UserDaoTest { @Test void addAndSelect() throws ClassNotFoundException, SQLException { - UserDao userDao = new UserDao(); - String id = "9"; + AWSUserDaoImpl userDao = new AWSUserDaoImpl(); + String id = "10"; User user = new User(id,"test","1234"); // user 값을 DTO에 저장함 userDao.add(user); From 1dbf8bd866fd9a00726b9357bf2c54d5cb3aa6d7 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Tue, 18 Oct 2022 23:56:57 +0900 Subject: [PATCH 161/307] DTO --- .../src/main/java/com/dbexercise/domain/User.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/domain/User.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/domain/User.java index 9f1bc02..b0dcdd1 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/domain/User.java +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/domain/User.java @@ -29,4 +29,4 @@ public String getPassword() { public String toString(){ return "id = "+this.id + " name = "+this.name+" password = "+this.password; } -} +} From 69f4fe4e54b22de6c2990930be43a4bada6cd593 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Tue, 18 Oct 2022 23:57:22 +0900 Subject: [PATCH 162/307] =?UTF-8?q?DAO(=EC=B6=94=EC=83=81=ED=99=94=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9-DB=EA=B5=AC=EB=B3=84=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/dbexercise/dao/UserDaoAbstract.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java index 736a1cf..e228105 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java @@ -54,7 +54,7 @@ public User select(String id) throws SQLException, ClassNotFoundException { throw new RuntimeException(e); } } - + public static void main(String[] args) throws ClassNotFoundException, SQLException { UserDao userDao = new UserDao(); userDao.add(new User("7","Ruru","1234qwer")); // user로 값을 받아 DTO에 저장한 후 mysql로 데이터 보냄 From 4ef92fa082d9a197b1763e2068f3dd1ed3475ec9 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Tue, 18 Oct 2022 23:57:33 +0900 Subject: [PATCH 163/307] =?UTF-8?q?DAO(=EC=B6=94=EC=83=81=ED=99=94=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9-DB=EA=B5=AC=EB=B3=84=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/dbexercise/dao/UserDaoAbstract.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java index e228105..4c5db6a 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java @@ -35,7 +35,7 @@ public void add(User user) throws ClassNotFoundException { } public User select(String id) throws SQLException, ClassNotFoundException { - + try { Connection conn = makeConnection(); PreparedStatement ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); From db900bbd2a404dfe15b9b62e7637d315fc8f30b9 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Tue, 18 Oct 2022 23:57:39 +0900 Subject: [PATCH 164/307] =?UTF-8?q?DAO(=EC=B6=94=EC=83=81=ED=99=94=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9-DB=EA=B5=AC=EB=B3=84=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/dbexercise/dao/UserDaoAbstract.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java index 4c5db6a..267b32f 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java @@ -53,7 +53,7 @@ public User select(String id) throws SQLException, ClassNotFoundException { }catch (SQLException e){ throw new RuntimeException(e); } - } + } public static void main(String[] args) throws ClassNotFoundException, SQLException { UserDao userDao = new UserDao(); From 78d778ec107c79a002900649f28b62a7d7b1c244 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Tue, 18 Oct 2022 23:57:46 +0900 Subject: [PATCH 165/307] =?UTF-8?q?DAO(=EC=B6=94=EC=83=81=ED=99=94=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9-DB=EA=B5=AC=EB=B3=84=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/dbexercise/dao/UserDaoAbstract.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java index 267b32f..538de10 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java @@ -4,7 +4,7 @@ import java.sql.*; import java.util.Map; - + public abstract class UserDaoAbstract { public abstract Connection makeConnection() throws SQLException; From b50c800afa34f417b3f1b37c6a86d262b6d14360 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Tue, 18 Oct 2022 23:57:52 +0900 Subject: [PATCH 166/307] =?UTF-8?q?DAO(=EC=B6=94=EC=83=81=ED=99=94=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9-DB=EA=B5=AC=EB=B3=84=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/dbexercise/dao/UserDaoAbstract.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java index 538de10..bf5cfd5 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java @@ -8,7 +8,7 @@ public abstract class UserDaoAbstract { public abstract Connection makeConnection() throws SQLException; - // DB를 여러개 동시에 사용하는 경우 각 DB에 연결시켜야 하므로 추상화 클래스를 상속받아 + // DB를 여러개 동시에 사용하는 경우 각 DB에 연결시켜야 하므로 추상화 클래스를 상속받아 // 원하는 DB로 연결시키는 방식에 사용 From b4cebaeef33a45c666774cc8bda34a76aad22456 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Tue, 18 Oct 2022 23:57:59 +0900 Subject: [PATCH 167/307] =?UTF-8?q?DAO(=EC=B6=94=EC=83=81=ED=99=94=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9-DB=EA=B5=AC=EB=B3=84=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/dbexercise/dao/UserDaoAbstract.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java index bf5cfd5..222eca4 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java @@ -36,7 +36,7 @@ public void add(User user) throws ClassNotFoundException { public User select(String id) throws SQLException, ClassNotFoundException { - try { + try { Connection conn = makeConnection(); PreparedStatement ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); ps.setString(1, id); // id는 get(String id)로 받은 id From 5e96a2d3840d82ea670f85380a32168f74a16a12 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Tue, 18 Oct 2022 23:58:04 +0900 Subject: [PATCH 168/307] =?UTF-8?q?DAO(=EC=B6=94=EC=83=81=ED=99=94=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9-DB=EA=B5=AC=EB=B3=84=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/dbexercise/dao/UserDaoAbstract.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java index 222eca4..e456c0d 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java @@ -3,7 +3,7 @@ import com.dbexercise.domain.User; import java.sql.*; -import java.util.Map; +import java.util.Map; public abstract class UserDaoAbstract { From 70c20c2267557deb9eff669dac4bdb33b30aa4d9 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Wed, 19 Oct 2022 00:52:15 +0900 Subject: [PATCH 169/307] =?UTF-8?q?DAO(=EC=A4=91=EB=B3=B5=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EB=B6=84=EB=A6=AC,=20=EC=B2=AB=EB=B2=88=EC=A7=B8?= =?UTF-8?q?=20=EB=B0=A9=EC=8B=9D)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDao.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDao.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDao.java index 3bfa2ef..0fea1a4 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDao.java +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDao.java @@ -5,6 +5,7 @@ import java.sql.*; import java.util.Map; +// 중복코드만 따로 빼내서 작성한 코드 (첫번째 방식) public class UserDao { private Connection makeConnection() throws ClassNotFoundException, SQLException { From f31fde69ee55e59f45fab7241d36dc1d4b64e37d Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Wed, 19 Oct 2022 00:52:48 +0900 Subject: [PATCH 170/307] =?UTF-8?q?DAO(=EC=B6=94=EC=83=81=ED=99=94=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC,=20=EB=91=90=EB=B2=88=EC=A7=B8=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/dbexercise/dao/AWSUserDaoImpl.java | 2 +- .../src/main/java/com/dbexercise/dao/LocalUserDaoImpl.java | 2 +- .../src/main/java/com/dbexercise/dao/UserDaoAbstract.java | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSUserDaoImpl.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSUserDaoImpl.java index e98d29e..ea05152 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSUserDaoImpl.java +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSUserDaoImpl.java @@ -6,7 +6,7 @@ import java.util.Map; // 추상화 클래스 상속 받음 -// AWS 저장소에 연결함 +// AWS 저장소에 연결함 (2번째 방식) public class AWSUserDaoImpl extends UserDaoAbstract{ @Override public Connection makeConnection() throws SQLException { diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/LocalUserDaoImpl.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/LocalUserDaoImpl.java index 7b5b7f8..471dc6c 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/LocalUserDaoImpl.java +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/LocalUserDaoImpl.java @@ -6,7 +6,7 @@ import java.util.Map; // 추상화 상속받음 -// 로컬 저장소 연결 +// 로컬 저장소 연결 (2번째 방식) public class LocalUserDaoImpl extends UserDaoAbstract{ @Override public Connection makeConnection() throws SQLException { diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java index 736a1cf..88457fe 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java @@ -5,13 +5,13 @@ import java.sql.*; import java.util.Map; +// 추상화를 통해 여러 DB의 값들을 따로 호출하여 사용하는 방법 (2번째 방식) public abstract class UserDaoAbstract { public abstract Connection makeConnection() throws SQLException; // DB를 여러개 동시에 사용하는 경우 각 DB에 연결시켜야 하므로 추상화 클래스를 상속받아 // 원하는 DB로 연결시키는 방식에 사용 - public void add(User user) throws ClassNotFoundException { try{ @@ -55,9 +55,10 @@ public User select(String id) throws SQLException, ClassNotFoundException { } } - public static void main(String[] args) throws ClassNotFoundException, SQLException { - UserDao userDao = new UserDao(); + public static void main(String[] args) throws ClassNotFoundException, SQLException { + AWSUserDaoImpl userDao = new AWSUserDaoImpl(); userDao.add(new User("7","Ruru","1234qwer")); // user로 값을 받아 DTO에 저장한 후 mysql로 데이터 보냄 System.out.println(userDao.select("1")); } + } From 11aa57fb89fb2ef03d10a57aa81ca7e5136ff261 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Wed, 19 Oct 2022 00:53:02 +0900 Subject: [PATCH 171/307] =?UTF-8?q?DAO(=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC,=20=EC=84=B8=EB=B2=88=EC=A7=B8=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dbexercise/dao/AWSConnectionMaker.java | 24 ++++++++ .../dao/UserDaoConnectionMaker.java | 61 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSConnectionMaker.java create mode 100644 Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoConnectionMaker.java diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSConnectionMaker.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSConnectionMaker.java new file mode 100644 index 0000000..19a04e8 --- /dev/null +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSConnectionMaker.java @@ -0,0 +1,24 @@ +package com.dbexercise.dao; + + +// 2번째 방식을 클래스로 따로 빼내어 사용하는 방식 (3번째 방법) + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Map; + +public class AWSConnectionMaker { + public Connection makeConnection() throws SQLException { + Map env = System.getenv(); // 아래의 값들은 해킹 위험이 있으므로 코드상에 데이터를 넣지말고 + // 왼쪽 위에 메뉴바에서 망치 옆에 프로젝트를 눌러 edit configurations를 누르고 + // environments variables를 눌러 값을 입력해 준다. + String dbHost = env.get("DB_HOST"); // DB 호스트 번호(AWS 주소) 가져옴 + String dbUser = env.get("DB_USER"); // DB 호스트 이름 가져옴 + String dbPassword = env.get("DB_PASSWORD"); // DB 비밀번호 가져옴 + + Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); + + return conn; + } +} diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoConnectionMaker.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoConnectionMaker.java new file mode 100644 index 0000000..578e91a --- /dev/null +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoConnectionMaker.java @@ -0,0 +1,61 @@ +package com.dbexercise.dao; + +import com.dbexercise.domain.User; + +import java.sql.*; +import java.util.Map; + +// 2번째 방식을 클래스로 따로 빼내어 사용하는 방식 (3번째 방법) +public class UserDaoConnectionMaker { + + AWSConnectionMaker awsConnectionMaker = new AWSConnectionMaker(); + + public void add(User user) throws ClassNotFoundException { + + try{ + // db 연결(호스트,이름,비밀번호) + Connection conn = awsConnectionMaker.makeConnection(); // 설정들을 모아둔 메서드 호출 + + PreparedStatement ps = conn.prepareStatement("INSERT INTO users(id,name,password) VALUES(?,?,?)"); + ps.setString(1,user.getId()); // mysql 테이블로 값 insert + ps.setString(2,user.getName()); + ps.setString(3,user.getPassword()); + + ps.executeUpdate(); // ctrl + enter 즉, mysql에서 번개모양을 눌러 최신화 한다는 느낌 + ps.close(); + conn.close(); + System.out.println("데이터가 insert 됬습니다."); + + }catch (SQLException e){ + throw new RuntimeException(e); + } + + } + + public User select(String id) throws SQLException, ClassNotFoundException { + + try { + Connection conn = awsConnectionMaker.makeConnection(); + PreparedStatement ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); + ps.setString(1, id); // id는 get(String id)로 받은 id + ResultSet rs = ps.executeQuery(); // 쿼리문을 저장함 insert문과 달리 excuteQuery() 사용 + // rs에는 쿼리 실행 결과가 담겨져 있다. (select * from users where id = 1;) + rs.next(); + + // User 생성자를 통해 쿼리문에 id값을 넣어 찾은 id, name,password 값을 저장한다. + User user = new User(rs.getString("id"), rs.getString("name"), rs.getString("password")); + rs.close(); + ps.close(); + conn.close(); + return user; + }catch (SQLException e){ + throw new RuntimeException(e); + } + } + + public static void main(String[] args) throws ClassNotFoundException, SQLException { + UserDaoConnectionMaker userDao = new UserDaoConnectionMaker(); + userDao.add(new User("7","Ruru","1234qwer")); // user로 값을 받아 DTO에 저장한 후 mysql로 데이터 보냄 + System.out.println(userDao.select("1")); + } +} \ No newline at end of file From 57981452d478efb601770ce635b3cc6a065734bd Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Wed, 19 Oct 2022 00:53:30 +0900 Subject: [PATCH 172/307] =?UTF-8?q?TDD(2=EB=B2=88=EC=A7=B8=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D=20Test=20Case)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java b/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java index fda8ab3..f331a64 100644 --- a/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java +++ b/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java @@ -1,7 +1,6 @@ package com.dbexercise; import com.dbexercise.dao.AWSUserDaoImpl; -import com.dbexercise.dao.UserDao; import com.dbexercise.domain.User; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; From 4752fa99836e43cd8864a8117edb3b855cf22493 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Wed, 19 Oct 2022 00:53:35 +0900 Subject: [PATCH 173/307] =?UTF-8?q?TDD(3=EB=B2=88=EC=A7=B8=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D=20Test=20Case)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserDaoConnectionMakerTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoConnectionMakerTest.java diff --git a/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoConnectionMakerTest.java b/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoConnectionMakerTest.java new file mode 100644 index 0000000..5c0572e --- /dev/null +++ b/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoConnectionMakerTest.java @@ -0,0 +1,23 @@ +package com.dbexercise; + +import com.dbexercise.dao.UserDaoConnectionMaker; +import com.dbexercise.domain.User; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.sql.SQLException; + + +// 3번째 방식 테스트 +class UserDaoConnectionMakerTest { + @Test + void addAndSelect() throws ClassNotFoundException, SQLException { + UserDaoConnectionMaker userDao = new UserDaoConnectionMaker(); + String id = "11"; + User user = new User(id,"test","1234"); // user 값을 DTO에 저장함 + userDao.add(user); + + User selectedUser = userDao.select(id); // DTO에 저장되어 있는 데이터를 가져와 비교함 + Assertions.assertEquals("test",selectedUser.getName()); + } +} \ No newline at end of file From d7aee4fd7b22183855eabd05a48dfe303184538f Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Wed, 19 Oct 2022 00:55:21 +0900 Subject: [PATCH 174/307] =?UTF-8?q?DAO(=EC=B6=94=EC=83=81=ED=99=94=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC,=20=EB=91=90=EB=B2=88=EC=A7=B8=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/dbexercise/dao/UserDaoAbstract.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java index 1c28ab9..cb9357e 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java @@ -63,5 +63,5 @@ public static void main(String[] args) throws ClassNotFoundException, SQLExcepti userDao.add(new User("7","Ruru","1234qwer")); // user로 값을 받아 DTO에 저장한 후 mysql로 데이터 보냄 System.out.println(userDao.select("1")); } - + } From 7e2282514536d2c75903a853c4e0acba7d5d6201 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Wed, 19 Oct 2022 01:04:49 +0900 Subject: [PATCH 175/307] =?UTF-8?q?TDD(3=EB=B2=88=EC=A7=B8=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D=20Test=20Case)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/com/dbexercise/UserDaoConnectionMakerTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoConnectionMakerTest.java b/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoConnectionMakerTest.java index 5c0572e..fed8527 100644 --- a/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoConnectionMakerTest.java +++ b/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoConnectionMakerTest.java @@ -1,5 +1,6 @@ package com.dbexercise; +import com.dbexercise.dao.AWSConnectionMaker; import com.dbexercise.dao.UserDaoConnectionMaker; import com.dbexercise.domain.User; import org.junit.jupiter.api.Assertions; @@ -12,8 +13,8 @@ class UserDaoConnectionMakerTest { @Test void addAndSelect() throws ClassNotFoundException, SQLException { - UserDaoConnectionMaker userDao = new UserDaoConnectionMaker(); - String id = "11"; + UserDaoConnectionMaker userDao = new UserDaoConnectionMaker(new AWSConnectionMaker()); + String id = "12"; User user = new User(id,"test","1234"); // user 값을 DTO에 저장함 userDao.add(user); From 7e2bc154007ff2003489d8856bf22137102e2cb4 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Wed, 19 Oct 2022 01:04:55 +0900 Subject: [PATCH 176/307] =?UTF-8?q?DAO(=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC,=20=EC=84=B8=EB=B2=88=EC=A7=B8=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/dbexercise/dao/UserDaoConnectionMaker.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoConnectionMaker.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoConnectionMaker.java index 578e91a..03a3691 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoConnectionMaker.java +++ b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoConnectionMaker.java @@ -8,7 +8,11 @@ // 2번째 방식을 클래스로 따로 빼내어 사용하는 방식 (3번째 방법) public class UserDaoConnectionMaker { - AWSConnectionMaker awsConnectionMaker = new AWSConnectionMaker(); + AWSConnectionMaker awsConnectionMaker; + + public UserDaoConnectionMaker(AWSConnectionMaker awsConnectionMaker) { + this.awsConnectionMaker = awsConnectionMaker; + } public void add(User user) throws ClassNotFoundException { @@ -54,7 +58,7 @@ public User select(String id) throws SQLException, ClassNotFoundException { } public static void main(String[] args) throws ClassNotFoundException, SQLException { - UserDaoConnectionMaker userDao = new UserDaoConnectionMaker(); + UserDaoConnectionMaker userDao = new UserDaoConnectionMaker(new AWSConnectionMaker()); userDao.add(new User("7","Ruru","1234qwer")); // user로 값을 받아 DTO에 저장한 후 mysql로 데이터 보냄 System.out.println(userDao.select("1")); } From 88be3a68109926f8c8d7b4dc384ef4918e164caf Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Wed, 19 Oct 2022 01:05:47 +0900 Subject: [PATCH 177/307] Out File --- .../com/dbexercise/dao/AWSConnectionMaker.class | Bin 0 -> 1131 bytes .../com/dbexercise/dao/AWSUserDaoImpl.class | Bin 0 -> 1137 bytes .../com/dbexercise/dao/LocalUserDaoImpl.class | Bin 0 -> 928 bytes .../classes/com/dbexercise/dao/UserDao.class | Bin 0 -> 3326 bytes .../com/dbexercise/dao/UserDaoAbstract.class | Bin 0 -> 2665 bytes .../dbexercise/dao/UserDaoConnectionMaker.class | Bin 0 -> 2806 bytes .../classes/com/dbexercise/domain/User.class | Bin 0 -> 1398 bytes .../dbexercise/UserDaoConnectionMakerTest.class | Bin 0 -> 1366 bytes .../classes/com/dbexercise/UserDaoTest.class | Bin 0 -> 1200 bytes 9 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/AWSConnectionMaker.class create mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/AWSUserDaoImpl.class create mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/LocalUserDaoImpl.class create mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDao.class create mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDaoAbstract.class create mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDaoConnectionMaker.class create mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/domain/User.class create mode 100644 Java-Mysql-Connect/out/test/classes/com/dbexercise/UserDaoConnectionMakerTest.class create mode 100644 Java-Mysql-Connect/out/test/classes/com/dbexercise/UserDaoTest.class diff --git a/Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/AWSConnectionMaker.class b/Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/AWSConnectionMaker.class new file mode 100644 index 0000000000000000000000000000000000000000..16932c6f45276ad850c878f17011a28b1aa33be7 GIT binary patch literal 1131 zcma)5T~pdn5Iq+Hp%4_QLbde6wkn94)|P&#O#;<_)jnza z(CKr3RHu6bD3m(W%p`a3*}Z#q@7etN{rv}kS9lXe6px~Kj3*Jy#4w9F8QBPO5zI%C z$AXMS8A}Y|HPbS^b%tOzcg!Gd*;URkS~4xZ+iFy}bEsG9gd|J0q1TUf#}xZ6D0v@D zmtn4C*bTK>;b+`2OqZ)w-BveFv@P4RxZ#<$Rn|XpXO&^3LB=)Akj~~xr+Qmg-A{G( z+CiZ~ZnZ@rzPII>b+xQF2@h8*JGSeIihNgHw`!{9Ii^+Xc#mA}Fhr}Becg3G+fJ3b zGN=-Ui5sX=gT0+Md;Jv#+1G{{hmm!vBD#HM@TO?om7&sJvs;eA-#5nNSKQCj14vg2W|+y};<0>>%O^}sNc`!jaup^xK629g0sKU$ zoKJ>(_HI5Y_v{sEVR2HrL}Vp28Tvv8gAim>ev&vOq7Wn*qR3$!%SibJtanJd1xPec zJo~#+Y}a8J&E-pn{Fv+h z=bC;Qpwy^vjwOjOdKB0-z04crk5|kM*AFC{FjV7CRW}09cB;*&L}bt^<~H~JFRoXi zjx2&?7`_2&q`R-vM!UC#ZuI4=h*v!;#6nv?u|z|5=&R6aZ@5RECEnWd76-d;WlnaH zL=TcGo+R-U^9*Y7&4-OGV^_tqB%Wh|q5t1rn@M}d`VK=6rEjkq#=+K3QN@cSY5$5L z`(HsA#;?g~DYk0*fyXVn=;07s3S_)5U3AvX>C_KIoy4h%Ak=N3t!syJsjyDlK?+kc z!&I*04!6uhnvA8^OoY<5Tnr-@G>V>mEW9#zcvVWBqB@tO!%*(5*qV$Ej2k`IPa?9o zMgNg}BA~lQlD;Y0>9jIhW7B6~-@pze9=O7h>f?I^MQ73u(1&FDf&$8RZ;_#aJfxl@3NB!R~}bQcws&f{YPF9z&SN z?U2Aq6Qo5zq3IgJFcIm;Bt|ewWX6!8+)=8RC%PH36gnNH%6EzQ7-7gJnkVm(b)P&6 MtqP{_zvQCZ1c!;=Y9kc$mebEEcj@w6KI_6OT=- zFl4s9(2I8%(v|8FgRv{yf??Y6Lh-R5w1hh3EuWC0BVFzvapmcF3>tCQix^fMR|a;w zB~FBLy-3(?F72fLQzXrD+ik zbQ?*wAA7#t;61_(m*@A_gVWVuITA* zBNI<3ZpyxL#d}YCQu=qs7rNaXZoo3}G=~bR4D-kBmRk>oG-BPheeGgbMsdAXd$~dL zC@Eux?5o$cH|ralZ%wS`@C<7V%h&LfVd;vhvFYzxQLMO2>ZOUt%>!pL5W`G@k4zXw zu?XlobVQt3KYR9R{xZKj(b-epK&S=}c}FOQJh9F{A48*Z+0E-9SKkIK!lYZQei~wV&)QBW@WGq`i$c71&c&Y75GDu$H&=khfV8%!qc{Bpt zEoqyiX=vJX-;%Cr(GdlLUK40NWfn~5v_MN_U|zsKYGn<9 z-Ep&EB+L0F!=BZba@2(4Rz}aw>$WN1J*D5dVwMCB#xqtvmR&M#7+R&%lX0=Kppg=;dpyIOY4Tr8m%sc+3L zO6y*XBB*1!yEX9Ke;0Eqq(ScQkw#-_!6oo)9=Tm86&1@KkbkCM2Cd$u%g70hi0e-0AM|e}gTN-|hpJ@0g-qi3j`S>}0 zq2X;D)$mLFO5pIl*VjLI>-~SfwEnO47sFeFwUi88WKoK+<)3q;F+Zrx0Azl$fG${B564jR=JR^0pDVkUMul{akwlSjyreu zROeE|qE}UN>?WIg1#)rT?ccik57Tb4i1}-U$f?Z(|B(!aATCtVr4+p=F|NqNX>eui56h) zQydigs+?~f>6PY{n463R+De8~;Y&`KsT}}u!YB+-;klhs{aWbYEtM%d##}MW`Rd+# zQv!iZ&ML__tIYCxcZO*(x>=C13_Z_ER0!FsW~8Frl#_SO4h4`SzPnLBd&Rb{%S+Uq z{+gH0`LbcJNjMF~Xq>8{8k;q(JYU8Qrpv4QIkG~SRaUn2=MJsqsRW*C%*@j^^VzJC zsJ5W39)fus<{yk<{y72y;EcghK9BJ&#$O?|M{YyhqTs`EK3iR78y=;sRW{%R9&^_@ zZMjPt{{t=D35?u*(cwdK z$UnG&U7Oh5f}sG#&WhMdaZg3uL`Yy^XcKz{qMO(!@E-Pux;Aj&9dsn_qGvIB8xQ>L zmP_h1Cug^Z|8aCMUN5r@V;Aeyg9q_29wPoeUU2Z?c9YK?dK(7!XLZnC5 zc*P^)BQ+wbcn=Dk^!NBT@lgW5i{8Z^f9TLA!ah(qTooR4h1+>?q(ENef@J58|XS?C3Vf1dC!vB)~ky0lEPr2@E6qb23h z(o3u}IL87{)0ZS8K$|*MD>bTC=zGMYN`?3kmq=BuX}ZZ(8&XJDxWZ+(m4N=c=v%yv z{`jDzBlJip5*i@#4IE)F42IY&(G3jMPg}@swF#&!S`Q1>$CAmicF`}rVHR`zRf&0? N=(jiR0@r+a_J6M0Egb*= literal 0 HcmV?d00001 diff --git a/Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDaoAbstract.class b/Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDaoAbstract.class new file mode 100644 index 0000000000000000000000000000000000000000..84434abc3cfe1709426b95f1fb95921a4e26583c GIT binary patch literal 2665 zcmaJ@TUQfT6#h;~m=FfAk&9T=;DrVOBWksZ)lv)<3?K;?(OMaj5eJh@oJ<6JwXJQf z*497Jx31NfK44c1i@H|(-k(zJL!W%>>USm~i3Gb?O!n-v&))m{_9glA-`{=*Z~~8g z=)eUZ4j|&iNG(P&=0g)M)?yq{DaGVtLcUJQ$CNags=+iac`@U|Wn5A4u7ayRY{PqA zT$4t#wa_r9AnrxK6cb+PUR;-+=H>g8f*U@x;er>27Ykn8ly6BdQt~q`y_yO#3T_Eh zpElBleMX=v*f}NO9xxNSKtsex>!Z2UoNi5Mb4hCa5i_nOr!>ou?**mXzF}kq_DAAo zDwLShmvk#`Wc5%&GeeVE-8!e4{c~B{(&BcXKz&NPsSlXxv>vw&GcC{(?2IgEx3y6A zRx(sNps6ps6xTD-iteklL_%Osup)|?(u}kdsL#ngPTvAeFY)Qh&{tdO@S>$>G)qs! zY|YkFdRnF^h_t0-5*v>c6XB^lM@-VkX1HaE2-MMG{N{+3aY$0Y8`W7oNzej^gL&sk zEj=HK*_M%>@9X@3cP@)*He*b391U z#{!DP$=V6*tH_O&?VpYniaV6bBxSW?X3mQ1gNAIB#=_Y~;Sb3Qt9T7T6^9TK=p7o3 zg`*RJq0x!4fQ*z48j0?-meRX3S~k0AT8YlURDWbL91EW9=3l3RtO^@B6}PddU`fRt zyszQ|EUNfWK0d<7Dn3C_!Ce)f;xmEv^+(IkzW?R#d&_?<-whaPhOqM6HcYVx%j+$$)6qMnissU`kE(;em<3=KKSL(Xo*{ zw!rlHa5PMdz?*@yD!#&f1z)RpfQJn5@;*}W4IZ(Kk`@8)1~D@3w?w!3VntQh$|ra| znzM4e-h1Tev0IC}rJ@%{c+{)nO`MVNzZ2NIg|kgH6xdecVr*`~>E%F4HIQWCMooLr z%%u}WlGt8FW=qpeUzz;m6$kHSb5Xp#)u?*rb$f{I-?*_v%4ce$cyh5+To$Ow>UMtm zgGSV`dPli_;)Z1|%Ejy~LbZ_Lcuu$ONQ7l; zwtRi~iv$<7vgPz8rpvE`%Or}(H;C#e4_Mq?r6wq-1Ws;YSV?iEM((8-(B?ahklgM3 z0`1@zD&T>TyM)h9zJ>THr1sz{#1jfG9OSdwQP!f1vYIzQH+lfKkUNN)!#r{Gvw{Dd z3Eq?L{y`PBz@>vLaE)~PtJdIlVYJ8HwF1u?s;kiBp{V4=YKq>xxP}^m>7F(C1iIHy zEATT^f87e|e?;BLQ*4{*Ud1baJaKXv#t7q9Ihh_u9pg0-RtxH}1FihqkDbi14aczy zr?DGvV-JS0kGIp4agG}IJ{IL#yOggg<#PYSDPxKJR%UnF7!?{;l&D%LQni47+UBY9LOjPT zsdAXACO-`%x&{L{m*)!C$&{qJ<0;x^R-WBXy!TwT{ s`khug123~`WnKpuRp#HE_r}5w^36-k?+{bIWo4w(%s^m>XD$r?2V&NOr~m)} literal 0 HcmV?d00001 diff --git a/Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDaoConnectionMaker.class b/Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDaoConnectionMaker.class new file mode 100644 index 0000000000000000000000000000000000000000..804656464bbbb3b24668f1c2a0427845e89d9cf3 GIT binary patch literal 2806 zcma)8+fx%)9R5y7$b|(l3W}lztr{R0L0hXR)MBW#373S6Krb%I7FUyO+$4g%+SayK zYiqA>ed|nL`hXpUq0F@J{Zop4>x^%mekTb@B(c-k*^_hoUB2&k$^P-rufG8}f$v@L zBIv{(gk0E*VFyO)Fp4o3nh~x;1mkixA%{u1oRY%@dF6r=)0lB!)`eH`njNp(@rDaq zanS))UYe^z6frwA2L|NyO$X*3xFj{{a(%&$%XVCmR)a3uk2{cXAnAZ1S1AXs%3o7z zPur0ZaH|XH0VA2zq8Z&thSV#XDR4L#H4^^VoVKW$Q9Z5sW2)glI~Cbw4T&6 zeF7cc|0&ZxDPSEiVw%8~pq|u*vxzy)99QS!+;Inus2ZPCO!j zGta3;rDHW}EGDq8(kmmO>Pf$p>&>|mC3u0R;AQoi>Q7&d`%Air&yu3$*3#jqsijm? zi$yYOMoVbP4DSd!zN2&{G8POhMzxgWlc&}!O-UV_DJ^qEpq>h&S3+v4fZ0`4!7ydX zb6SftL;^>>c}sCMIq#2TOg%Z@+y39WEhaH+FF6?2(%E<>qDkK^I$3g8s-)kNCxK?~ zY~^W=IMtk|-fdNm1?&eWE+FA-GNUK7V(=uW&jtLEKrk>c?%C|WXD~bx z%473PoezWqyx}?H=~r+UU)b@bf_wOi2A-Ze3ckiS43?xtz_CG$wEL|<`({CwarF=g z9ISG;vgD;=A5;DWZHBWZGt<%CbL{xl1Y#bHB0?xFS$rq`tq@n7SWT%1QT>R=d8!hBEdji{UG@H>T zQZY8094kWtwrJc)b5+J{13J4B(C=>{FrlhVAVCW;(Axy?#V$xCtB0;_cv zhGA#<{`e)+SdhIr*F2SihhtgIye<)z#izW>xQhfAcV*6Mi*%Q7b_{Q+>y!k1loLR5)#_@@95=!xZulH#L>z*bDm=tSA($d0bCs`5FMQl zVY$zh1xGkGpoU{TB^uzw7Wlbp&fmsSbaO?yoK{weEEb+goqto#%HP?J2e2%oCggKl zS7EbYxXaqPjM`P$YtUum)RCXoa_Y=aSK$(v>RLsefNvFwz%QtGH!NezPpA*AVe7PS z1@7PP=KzKHfze1~(%I+eD9{84cJT9JCtA^h!`MZ)T5*yj^z#cMfPDzz0HxY6hW(hq z!5paLuu(36<9L=3w&FCkouJ+^!hW98lAzfl`dAqjPq$dzJ65sN0!~^sCcAQz73@A`lXqJg zz%rUzY)d72a_r3U^J#;f9w>C8gD5+R&qr>$$bp~1>meh@Fiz|dItCkcsk}fBimuVe4zpGIbj!qT z6Y~r?ugg$v@AD(>_&nHkwp8c^yG;fo;61@m?DHskFGDITtb2i{o-pJai#t@%l3gmO zw7o!V9`-sS+~yshZmMnRa({=1o<66ShT8KYhMBf2drr3_K8VouBH?spk9&dhCK4h2 z^igA2%D>!bJtMn9Jtvv9#^Nx9!KBZdaZ97LdwtebQOTrdhVqs?3|+C|=`KoI(yBJb zf`u^)MU*U*br?m7VdANjDpDcuzZ7aucB4uG3q{*LKY^YwvYs>csRO9n1iZ#}g~yGZdsk*zQO*SBG(Of2aZ9ESOGm0oZp z4@5c~iGmI8Dj6P|xKESOmh#}R&tN?d0ui=+a#xV7kAt#Oj>N5JJm~r&nooeuVHpEA zzX7+8`y!+K-9UX}X>)K2Qi>M${Vh+4rilj(3q$>7X=9lEdmZNJRhjgt^2q5SpKE1V2t88oz^Hb$|Lqyu+MQ>g<_dtAOeFR6ST9EB3y!gv6|pAMNQySr9ru- z3GAg4H$i1fOyfQ!HGIs>RZ^lA4}#YKmSI zuB3l#vOz_n+@Os<^DYQv8tvoH` nRQq$0X?B3An%a}cwYbx1tWqwM0n50D6}r7i=OUf!wB~*ST8t#N literal 0 HcmV?d00001 diff --git a/Java-Mysql-Connect/out/test/classes/com/dbexercise/UserDaoConnectionMakerTest.class b/Java-Mysql-Connect/out/test/classes/com/dbexercise/UserDaoConnectionMakerTest.class new file mode 100644 index 0000000000000000000000000000000000000000..f1d3a032139f93c90bde41cab72429c16ed9f413 GIT binary patch literal 1366 zcma)6Yf}Be*`kdKz{$ykMAq->`jI7bWRQ>N#uMj?V)RmE3Ww=6Qp-qwzxe!ZrDY zG}}GuMW^9b#EDeY%@3zzRlzrK2XTf}4~fIOXILEIoBdSmAzUTiBc|3j7-o7SI%E)I zK3xq>>l>R}Drnz81_uUS;?Te=yw;F4@CLblki%PJnCRTi+wysE*$W+0uEssD;P@v_ z!?ymB&oC9Zc$YP^_%7dNUrP4fC&{C~>5P)`Ub0^p|6@_HVbUjET7S6?V?mA4mVg-6 z1{6#6f$fSW(N~3E;B^wmWHQwcjA3E0ys{pNwJkw|_@mA7WrNq~PnhUN(c(MPmAP$6 zm9T&qeKph*qL-uxhP$*fX=XH!EH%Nt2gj2%jt0hYOwrnCIp7}d(++q*!QmkI8%F2{ z?A#!9c7yO)6OkrH^6}Br8)#?C@o4;36M7-Na*eU{@->Y8NIW_nxyJYp-0oDHqYo4a zUMv6>$2?_!MzzyabDOFv6kDxIZ4@yiFpU{P7AMb#n5DMn$@3BB2wNIsw3|bO+E%@U T@EA|@j4NrB%u$ab@hFlu?G?sNFv7*pb zwXCV@x(*W?8a6d-F{BQpBZF5A@m#*jkT`NJ!7x&ijwrXAHQ}A|noUTiGmQ{4Dim*jJV9?qfDZ`U~JBzz! z@lz!-f75K)WFC{2qCe+fxM_2zVO9c9It`K}l&4$hEw{;~6Goxv{g7B#$}NL_d|4N* zK)Q~vVOzrv!{mpy6Ue5hN?%fPMaOXi9%?A(uGcWn+f*c4TQU%y$y?Hla?>kr+pCKc zscJMD1+HZ4DqaI47-d-KE6-q>l;!3I!&JXwHxbGBTztRg%5@OyUc6N<;DU*16gXGz2CY8~ykuI;SUE$8k>J{|; zL?$(vxWdqP7+soKXkqNnc(9+Dm-{VXOiMfpq+ i@(9xuRF=>gIwdemmMN0WQRWNbnc*?*^w4RIA^QjRY$wbB literal 0 HcmV?d00001 From 1c2d04c48db227b64a7c6f0c9c077dce51f25890 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Thu, 20 Oct 2022 10:21:05 +0900 Subject: [PATCH 178/307] Delete Java-Mysql-Connect directory --- Java-Mysql-Connect/.idea/vcs.xml | 6 - Java-Mysql-Connect/gradlew | 234 ------------------ Java-Mysql-Connect/gradlew.bat | 89 ------- .../dbexercise/dao/AWSConnectionMaker.class | Bin 1131 -> 0 bytes .../com/dbexercise/dao/AWSUserDaoImpl.class | Bin 1137 -> 0 bytes .../com/dbexercise/dao/LocalUserDaoImpl.class | Bin 928 -> 0 bytes .../classes/com/dbexercise/dao/UserDao.class | Bin 3326 -> 0 bytes .../com/dbexercise/dao/UserDaoAbstract.class | Bin 2665 -> 0 bytes .../dao/UserDaoConnectionMaker.class | Bin 2806 -> 0 bytes .../classes/com/dbexercise/domain/User.class | Bin 1398 -> 0 bytes .../UserDaoConnectionMakerTest.class | Bin 1366 -> 0 bytes .../classes/com/dbexercise/UserDaoTest.class | Bin 1200 -> 0 bytes Java-Mysql-Connect/settings.gradle | 2 - .../dbexercise/dao/AWSConnectionMaker.java | 24 -- .../com/dbexercise/dao/AWSUserDaoImpl.java | 26 -- .../com/dbexercise/dao/LocalUserDaoImpl.java | 24 -- .../main/java/com/dbexercise/dao/UserDao.java | 74 ------ .../com/dbexercise/dao/UserDaoAbstract.java | 67 ----- .../dao/UserDaoConnectionMaker.java | 65 ----- .../main/java/com/dbexercise/domain/User.java | 32 --- .../UserDaoConnectionMakerTest.java | 24 -- .../test/java/com/dbexercise/UserDaoTest.java | 22 -- 22 files changed, 689 deletions(-) delete mode 100644 Java-Mysql-Connect/.idea/vcs.xml delete mode 100644 Java-Mysql-Connect/gradlew delete mode 100644 Java-Mysql-Connect/gradlew.bat delete mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/AWSConnectionMaker.class delete mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/AWSUserDaoImpl.class delete mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/LocalUserDaoImpl.class delete mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDao.class delete mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDaoAbstract.class delete mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDaoConnectionMaker.class delete mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/domain/User.class delete mode 100644 Java-Mysql-Connect/out/test/classes/com/dbexercise/UserDaoConnectionMakerTest.class delete mode 100644 Java-Mysql-Connect/out/test/classes/com/dbexercise/UserDaoTest.class delete mode 100644 Java-Mysql-Connect/settings.gradle delete mode 100644 Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSConnectionMaker.java delete mode 100644 Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSUserDaoImpl.java delete mode 100644 Java-Mysql-Connect/src/main/java/com/dbexercise/dao/LocalUserDaoImpl.java delete mode 100644 Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDao.java delete mode 100644 Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java delete mode 100644 Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoConnectionMaker.java delete mode 100644 Java-Mysql-Connect/src/main/java/com/dbexercise/domain/User.java delete mode 100644 Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoConnectionMakerTest.java delete mode 100644 Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java diff --git a/Java-Mysql-Connect/.idea/vcs.xml b/Java-Mysql-Connect/.idea/vcs.xml deleted file mode 100644 index 6c0b863..0000000 --- a/Java-Mysql-Connect/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Java-Mysql-Connect/gradlew b/Java-Mysql-Connect/gradlew deleted file mode 100644 index 1b6c787..0000000 --- a/Java-Mysql-Connect/gradlew +++ /dev/null @@ -1,234 +0,0 @@ -#!/bin/sh - -# -# Copyright © 2015-2021 the original authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# Darwin, MinGW, and NonStop. -# -# (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt -# within the Gradle project. -# -# You can find Gradle at https://github.com/gradle/gradle/. -# -############################################################################## - -# Attempt to set APP_HOME - -# Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac -done - -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" -APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD=maximum - -warn () { - echo "$*" -} >&2 - -die () { - echo - echo "$*" - echo - exit 1 -} >&2 - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac -fi - -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. - -# For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done -fi - -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. - -set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" - -# Use "xargs" to parse quoted args. -# -# With -n1 it outputs one arg per line, with the quotes and backslashes removed. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' - -exec "$JAVACMD" "$@" diff --git a/Java-Mysql-Connect/gradlew.bat b/Java-Mysql-Connect/gradlew.bat deleted file mode 100644 index 107acd3..0000000 --- a/Java-Mysql-Connect/gradlew.bat +++ /dev/null @@ -1,89 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/AWSConnectionMaker.class b/Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/AWSConnectionMaker.class deleted file mode 100644 index 16932c6f45276ad850c878f17011a28b1aa33be7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1131 zcma)5T~pdn5Iq+Hp%4_QLbde6wkn94)|P&#O#;<_)jnza z(CKr3RHu6bD3m(W%p`a3*}Z#q@7etN{rv}kS9lXe6px~Kj3*Jy#4w9F8QBPO5zI%C z$AXMS8A}Y|HPbS^b%tOzcg!Gd*;URkS~4xZ+iFy}bEsG9gd|J0q1TUf#}xZ6D0v@D zmtn4C*bTK>;b+`2OqZ)w-BveFv@P4RxZ#<$Rn|XpXO&^3LB=)Akj~~xr+Qmg-A{G( z+CiZ~ZnZ@rzPII>b+xQF2@h8*JGSeIihNgHw`!{9Ii^+Xc#mA}Fhr}Becg3G+fJ3b zGN=-Ui5sX=gT0+Md;Jv#+1G{{hmm!vBD#HM@TO?om7&sJvs;eA-#5nNSKQCj14vg2W|+y};<0>>%O^}sNc`!jaup^xK629g0sKU$ zoKJ>(_HI5Y_v{sEVR2HrL}Vp28Tvv8gAim>ev&vOq7Wn*qR3$!%SibJtanJd1xPec zJo~#+Y}a8J&E-pn{Fv+h z=bC;Qpwy^vjwOjOdKB0-z04crk5|kM*AFC{FjV7CRW}09cB;*&L}bt^<~H~JFRoXi zjx2&?7`_2&q`R-vM!UC#ZuI4=h*v!;#6nv?u|z|5=&R6aZ@5RECEnWd76-d;WlnaH zL=TcGo+R-U^9*Y7&4-OGV^_tqB%Wh|q5t1rn@M}d`VK=6rEjkq#=+K3QN@cSY5$5L z`(HsA#;?g~DYk0*fyXVn=;07s3S_)5U3AvX>C_KIoy4h%Ak=N3t!syJsjyDlK?+kc z!&I*04!6uhnvA8^OoY<5Tnr-@G>V>mEW9#zcvVWBqB@tO!%*(5*qV$Ej2k`IPa?9o zMgNg}BA~lQlD;Y0>9jIhW7B6~-@pze9=O7h>f?I^MQ73u(1&FDf&$8RZ;_#aJfxl@3NB!R~}bQcws&f{YPF9z&SN z?U2Aq6Qo5zq3IgJFcIm;Bt|ewWX6!8+)=8RC%PH36gnNH%6EzQ7-7gJnkVm(b)P&6 MtqP{_zvQCZ1c!;=Y9kc$mebEEcj@w6KI_6OT=- zFl4s9(2I8%(v|8FgRv{yf??Y6Lh-R5w1hh3EuWC0BVFzvapmcF3>tCQix^fMR|a;w zB~FBLy-3(?F72fLQzXrD+ik zbQ?*wAA7#t;61_(m*@A_gVWVuITA* zBNI<3ZpyxL#d}YCQu=qs7rNaXZoo3}G=~bR4D-kBmRk>oG-BPheeGgbMsdAXd$~dL zC@Eux?5o$cH|ralZ%wS`@C<7V%h&LfVd;vhvFYzxQLMO2>ZOUt%>!pL5W`G@k4zXw zu?XlobVQt3KYR9R{xZKj(b-epK&S=}c}FOQJh9F{A48*Z+0E-9SKkIK!lYZQei~wV&)QBW@WGq`i$c71&c&Y75GDu$H&=khfV8%!qc{Bpt zEoqyiX=vJX-;%Cr(GdlLUK40NWfn~5v_MN_U|zsKYGn<9 z-Ep&EB+L0F!=BZba@2(4Rz}aw>$WN1J*D5dVwMCB#xqtvmR&M#7+R&%lX0=Kppg=;dpyIOY4Tr8m%sc+3L zO6y*XBB*1!yEX9Ke;0Eqq(ScQkw#-_!6oo)9=Tm86&1@KkbkCM2Cd$u%g70hi0e-0AM|e}gTN-|hpJ@0g-qi3j`S>}0 zq2X;D)$mLFO5pIl*VjLI>-~SfwEnO47sFeFwUi88WKoK+<)3q;F+Zrx0Azl$fG${B564jR=JR^0pDVkUMul{akwlSjyreu zROeE|qE}UN>?WIg1#)rT?ccik57Tb4i1}-U$f?Z(|B(!aATCtVr4+p=F|NqNX>eui56h) zQydigs+?~f>6PY{n463R+De8~;Y&`KsT}}u!YB+-;klhs{aWbYEtM%d##}MW`Rd+# zQv!iZ&ML__tIYCxcZO*(x>=C13_Z_ER0!FsW~8Frl#_SO4h4`SzPnLBd&Rb{%S+Uq z{+gH0`LbcJNjMF~Xq>8{8k;q(JYU8Qrpv4QIkG~SRaUn2=MJsqsRW*C%*@j^^VzJC zsJ5W39)fus<{yk<{y72y;EcghK9BJ&#$O?|M{YyhqTs`EK3iR78y=;sRW{%R9&^_@ zZMjPt{{t=D35?u*(cwdK z$UnG&U7Oh5f}sG#&WhMdaZg3uL`Yy^XcKz{qMO(!@E-Pux;Aj&9dsn_qGvIB8xQ>L zmP_h1Cug^Z|8aCMUN5r@V;Aeyg9q_29wPoeUU2Z?c9YK?dK(7!XLZnC5 zc*P^)BQ+wbcn=Dk^!NBT@lgW5i{8Z^f9TLA!ah(qTooR4h1+>?q(ENef@J58|XS?C3Vf1dC!vB)~ky0lEPr2@E6qb23h z(o3u}IL87{)0ZS8K$|*MD>bTC=zGMYN`?3kmq=BuX}ZZ(8&XJDxWZ+(m4N=c=v%yv z{`jDzBlJip5*i@#4IE)F42IY&(G3jMPg}@swF#&!S`Q1>$CAmicF`}rVHR`zRf&0? N=(jiR0@r+a_J6M0Egb*= diff --git a/Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDaoAbstract.class b/Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDaoAbstract.class deleted file mode 100644 index 84434abc3cfe1709426b95f1fb95921a4e26583c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2665 zcmaJ@TUQfT6#h;~m=FfAk&9T=;DrVOBWksZ)lv)<3?K;?(OMaj5eJh@oJ<6JwXJQf z*497Jx31NfK44c1i@H|(-k(zJL!W%>>USm~i3Gb?O!n-v&))m{_9glA-`{=*Z~~8g z=)eUZ4j|&iNG(P&=0g)M)?yq{DaGVtLcUJQ$CNags=+iac`@U|Wn5A4u7ayRY{PqA zT$4t#wa_r9AnrxK6cb+PUR;-+=H>g8f*U@x;er>27Ykn8ly6BdQt~q`y_yO#3T_Eh zpElBleMX=v*f}NO9xxNSKtsex>!Z2UoNi5Mb4hCa5i_nOr!>ou?**mXzF}kq_DAAo zDwLShmvk#`Wc5%&GeeVE-8!e4{c~B{(&BcXKz&NPsSlXxv>vw&GcC{(?2IgEx3y6A zRx(sNps6ps6xTD-iteklL_%Osup)|?(u}kdsL#ngPTvAeFY)Qh&{tdO@S>$>G)qs! zY|YkFdRnF^h_t0-5*v>c6XB^lM@-VkX1HaE2-MMG{N{+3aY$0Y8`W7oNzej^gL&sk zEj=HK*_M%>@9X@3cP@)*He*b391U z#{!DP$=V6*tH_O&?VpYniaV6bBxSW?X3mQ1gNAIB#=_Y~;Sb3Qt9T7T6^9TK=p7o3 zg`*RJq0x!4fQ*z48j0?-meRX3S~k0AT8YlURDWbL91EW9=3l3RtO^@B6}PddU`fRt zyszQ|EUNfWK0d<7Dn3C_!Ce)f;xmEv^+(IkzW?R#d&_?<-whaPhOqM6HcYVx%j+$$)6qMnissU`kE(;em<3=KKSL(Xo*{ zw!rlHa5PMdz?*@yD!#&f1z)RpfQJn5@;*}W4IZ(Kk`@8)1~D@3w?w!3VntQh$|ra| znzM4e-h1Tev0IC}rJ@%{c+{)nO`MVNzZ2NIg|kgH6xdecVr*`~>E%F4HIQWCMooLr z%%u}WlGt8FW=qpeUzz;m6$kHSb5Xp#)u?*rb$f{I-?*_v%4ce$cyh5+To$Ow>UMtm zgGSV`dPli_;)Z1|%Ejy~LbZ_Lcuu$ONQ7l; zwtRi~iv$<7vgPz8rpvE`%Or}(H;C#e4_Mq?r6wq-1Ws;YSV?iEM((8-(B?ahklgM3 z0`1@zD&T>TyM)h9zJ>THr1sz{#1jfG9OSdwQP!f1vYIzQH+lfKkUNN)!#r{Gvw{Dd z3Eq?L{y`PBz@>vLaE)~PtJdIlVYJ8HwF1u?s;kiBp{V4=YKq>xxP}^m>7F(C1iIHy zEATT^f87e|e?;BLQ*4{*Ud1baJaKXv#t7q9Ihh_u9pg0-RtxH}1FihqkDbi14aczy zr?DGvV-JS0kGIp4agG}IJ{IL#yOggg<#PYSDPxKJR%UnF7!?{;l&D%LQni47+UBY9LOjPT zsdAXACO-`%x&{L{m*)!C$&{qJ<0;x^R-WBXy!TwT{ s`khug123~`WnKpuRp#HE_r}5w^36-k?+{bIWo4w(%s^m>XD$r?2V&NOr~m)} diff --git a/Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDaoConnectionMaker.class b/Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDaoConnectionMaker.class deleted file mode 100644 index 804656464bbbb3b24668f1c2a0427845e89d9cf3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2806 zcma)8+fx%)9R5y7$b|(l3W}lztr{R0L0hXR)MBW#373S6Krb%I7FUyO+$4g%+SayK zYiqA>ed|nL`hXpUq0F@J{Zop4>x^%mekTb@B(c-k*^_hoUB2&k$^P-rufG8}f$v@L zBIv{(gk0E*VFyO)Fp4o3nh~x;1mkixA%{u1oRY%@dF6r=)0lB!)`eH`njNp(@rDaq zanS))UYe^z6frwA2L|NyO$X*3xFj{{a(%&$%XVCmR)a3uk2{cXAnAZ1S1AXs%3o7z zPur0ZaH|XH0VA2zq8Z&thSV#XDR4L#H4^^VoVKW$Q9Z5sW2)glI~Cbw4T&6 zeF7cc|0&ZxDPSEiVw%8~pq|u*vxzy)99QS!+;Inus2ZPCO!j zGta3;rDHW}EGDq8(kmmO>Pf$p>&>|mC3u0R;AQoi>Q7&d`%Air&yu3$*3#jqsijm? zi$yYOMoVbP4DSd!zN2&{G8POhMzxgWlc&}!O-UV_DJ^qEpq>h&S3+v4fZ0`4!7ydX zb6SftL;^>>c}sCMIq#2TOg%Z@+y39WEhaH+FF6?2(%E<>qDkK^I$3g8s-)kNCxK?~ zY~^W=IMtk|-fdNm1?&eWE+FA-GNUK7V(=uW&jtLEKrk>c?%C|WXD~bx z%473PoezWqyx}?H=~r+UU)b@bf_wOi2A-Ze3ckiS43?xtz_CG$wEL|<`({CwarF=g z9ISG;vgD;=A5;DWZHBWZGt<%CbL{xl1Y#bHB0?xFS$rq`tq@n7SWT%1QT>R=d8!hBEdji{UG@H>T zQZY8094kWtwrJc)b5+J{13J4B(C=>{FrlhVAVCW;(Axy?#V$xCtB0;_cv zhGA#<{`e)+SdhIr*F2SihhtgIye<)z#izW>xQhfAcV*6Mi*%Q7b_{Q+>y!k1loLR5)#_@@95=!xZulH#L>z*bDm=tSA($d0bCs`5FMQl zVY$zh1xGkGpoU{TB^uzw7Wlbp&fmsSbaO?yoK{weEEb+goqto#%HP?J2e2%oCggKl zS7EbYxXaqPjM`P$YtUum)RCXoa_Y=aSK$(v>RLsefNvFwz%QtGH!NezPpA*AVe7PS z1@7PP=KzKHfze1~(%I+eD9{84cJT9JCtA^h!`MZ)T5*yj^z#cMfPDzz0HxY6hW(hq z!5paLuu(36<9L=3w&FCkouJ+^!hW98lAzfl`dAqjPq$dzJ65sN0!~^sCcAQz73@A`lXqJg zz%rUzY)d72a_r3U^J#;f9w>C8gD5+R&qr>$$bp~1>meh@Fiz|dItCkcsk}fBimuVe4zpGIbj!qT z6Y~r?ugg$v@AD(>_&nHkwp8c^yG;fo;61@m?DHskFGDITtb2i{o-pJai#t@%l3gmO zw7o!V9`-sS+~yshZmMnRa({=1o<66ShT8KYhMBf2drr3_K8VouBH?spk9&dhCK4h2 z^igA2%D>!bJtMn9Jtvv9#^Nx9!KBZdaZ97LdwtebQOTrdhVqs?3|+C|=`KoI(yBJb zf`u^)MU*U*br?m7VdANjDpDcuzZ7aucB4uG3q{*LKY^YwvYs>csRO9n1iZ#}g~yGZdsk*zQO*SBG(Of2aZ9ESOGm0oZp z4@5c~iGmI8Dj6P|xKESOmh#}R&tN?d0ui=+a#xV7kAt#Oj>N5JJm~r&nooeuVHpEA zzX7+8`y!+K-9UX}X>)K2Qi>M${Vh+4rilj(3q$>7X=9lEdmZNJRhjgt^2q5SpKE1V2t88oz^Hb$|Lqyu+MQ>g<_dtAOeFR6ST9EB3y!gv6|pAMNQySr9ru- z3GAg4H$i1fOyfQ!HGIs>RZ^lA4}#YKmSI zuB3l#vOz_n+@Os<^DYQv8tvoH` nRQq$0X?B3An%a}cwYbx1tWqwM0n50D6}r7i=OUf!wB~*ST8t#N diff --git a/Java-Mysql-Connect/out/test/classes/com/dbexercise/UserDaoConnectionMakerTest.class b/Java-Mysql-Connect/out/test/classes/com/dbexercise/UserDaoConnectionMakerTest.class deleted file mode 100644 index f1d3a032139f93c90bde41cab72429c16ed9f413..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1366 zcma)6Yf}Be*`kdKz{$ykMAq->`jI7bWRQ>N#uMj?V)RmE3Ww=6Qp-qwzxe!ZrDY zG}}GuMW^9b#EDeY%@3zzRlzrK2XTf}4~fIOXILEIoBdSmAzUTiBc|3j7-o7SI%E)I zK3xq>>l>R}Drnz81_uUS;?Te=yw;F4@CLblki%PJnCRTi+wysE*$W+0uEssD;P@v_ z!?ymB&oC9Zc$YP^_%7dNUrP4fC&{C~>5P)`Ub0^p|6@_HVbUjET7S6?V?mA4mVg-6 z1{6#6f$fSW(N~3E;B^wmWHQwcjA3E0ys{pNwJkw|_@mA7WrNq~PnhUN(c(MPmAP$6 zm9T&qeKph*qL-uxhP$*fX=XH!EH%Nt2gj2%jt0hYOwrnCIp7}d(++q*!QmkI8%F2{ z?A#!9c7yO)6OkrH^6}Br8)#?C@o4;36M7-Na*eU{@->Y8NIW_nxyJYp-0oDHqYo4a zUMv6>$2?_!MzzyabDOFv6kDxIZ4@yiFpU{P7AMb#n5DMn$@3BB2wNIsw3|bO+E%@U T@EA|@j4NrB%u$ab@hFlu?G?sNFv7*pb zwXCV@x(*W?8a6d-F{BQpBZF5A@m#*jkT`NJ!7x&ijwrXAHQ}A|noUTiGmQ{4Dim*jJV9?qfDZ`U~JBzz! z@lz!-f75K)WFC{2qCe+fxM_2zVO9c9It`K}l&4$hEw{;~6Goxv{g7B#$}NL_d|4N* zK)Q~vVOzrv!{mpy6Ue5hN?%fPMaOXi9%?A(uGcWn+f*c4TQU%y$y?Hla?>kr+pCKc zscJMD1+HZ4DqaI47-d-KE6-q>l;!3I!&JXwHxbGBTztRg%5@OyUc6N<;DU*16gXGz2CY8~ykuI;SUE$8k>J{|; zL?$(vxWdqP7+soKXkqNnc(9+Dm-{VXOiMfpq+ i@(9xuRF=>gIwdemmMN0WQRWNbnc*?*^w4RIA^QjRY$wbB diff --git a/Java-Mysql-Connect/settings.gradle b/Java-Mysql-Connect/settings.gradle deleted file mode 100644 index 6e01e4f..0000000 --- a/Java-Mysql-Connect/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -rootProject.name = 'Java-Mysql-Connect' - diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSConnectionMaker.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSConnectionMaker.java deleted file mode 100644 index 19a04e8..0000000 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSConnectionMaker.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.dbexercise.dao; - - -// 2번째 방식을 클래스로 따로 빼내어 사용하는 방식 (3번째 방법) - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.Map; - -public class AWSConnectionMaker { - public Connection makeConnection() throws SQLException { - Map env = System.getenv(); // 아래의 값들은 해킹 위험이 있으므로 코드상에 데이터를 넣지말고 - // 왼쪽 위에 메뉴바에서 망치 옆에 프로젝트를 눌러 edit configurations를 누르고 - // environments variables를 눌러 값을 입력해 준다. - String dbHost = env.get("DB_HOST"); // DB 호스트 번호(AWS 주소) 가져옴 - String dbUser = env.get("DB_USER"); // DB 호스트 이름 가져옴 - String dbPassword = env.get("DB_PASSWORD"); // DB 비밀번호 가져옴 - - Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); - - return conn; - } -} diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSUserDaoImpl.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSUserDaoImpl.java deleted file mode 100644 index ea05152..0000000 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSUserDaoImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.dbexercise.dao; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.Map; - -// 추상화 클래스 상속 받음 -// AWS 저장소에 연결함 (2번째 방식) -public class AWSUserDaoImpl extends UserDaoAbstract{ - @Override - public Connection makeConnection() throws SQLException { - Map env = System.getenv(); // 아래의 값들은 해킹 위험이 있으므로 코드상에 데이터를 넣지말고 - // 왼쪽 위에 메뉴바에서 망치 옆에 프로젝트를 눌러 edit configurations를 누르고 - // environments variables를 눌러 값을 입력해 준다. - String dbHost = env.get("DB_HOST"); // DB 호스트 번호(AWS 주소) 가져옴 - String dbUser = env.get("DB_USER"); // DB 호스트 이름 가져옴 - String dbPassword = env.get("DB_PASSWORD"); // DB 비밀번호 가져옴 - - Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); - - // 외부에서 주소와 호스트정보 비밀번호 입력 - - return conn; - } -} diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/LocalUserDaoImpl.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/LocalUserDaoImpl.java deleted file mode 100644 index 471dc6c..0000000 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/LocalUserDaoImpl.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.dbexercise.dao; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.Map; - -// 추상화 상속받음 -// 로컬 저장소 연결 (2번째 방식) -public class LocalUserDaoImpl extends UserDaoAbstract{ - @Override - public Connection makeConnection() throws SQLException { - Map env = System.getenv(); // 아래의 값들은 해킹 위험이 있으므로 코드상에 데이터를 넣지말고 - // 왼쪽 위에 메뉴바에서 망치 옆에 프로젝트를 눌러 edit configurations를 누르고 - // environments variables를 눌러 값을 입력해 준다. - - Connection conn = DriverManager.getConnection( - "jdbc:mysql://localhost:3306" - ,"root","12345678"); - // Local 저장소는 데이터를 코드상에 입력해도 해커가 털어가기 힘들다. - - return conn; - } -} diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDao.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDao.java deleted file mode 100644 index 0fea1a4..0000000 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDao.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.dbexercise.dao; - -import com.dbexercise.domain.User; - -import java.sql.*; -import java.util.Map; - -// 중복코드만 따로 빼내서 작성한 코드 (첫번째 방식) -public class UserDao { - - private Connection makeConnection() throws ClassNotFoundException, SQLException { - Map env = System.getenv(); // 아래의 값들은 해킹 위험이 있으므로 코드상에 데이터를 넣지말고 - // 왼쪽 위에 메뉴바에서 망치 옆에 프로젝트를 눌러 edit configurations를 누르고 - // environments variables를 눌러 값을 입력해 준다. - String dbHost = env.get("DB_HOST"); // DB 호스트 번호(AWS 주소) 가져옴 - String dbUser = env.get("DB_USER"); // DB 호스트 이름 가져옴 - String dbPassword = env.get("DB_PASSWORD"); // DB 비밀번호 가져옴 - - Class.forName("com.mysql.cj.jdbc.Driver"); // 만약 DB드라이버가 2개 이상일때 어떤 DB에 데이터를 삽입할 것인지 구분하기 위해 사용함 - // 지금은 mysql 1개만 사용하기 때문에 없어도 됨 - Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); - - return conn; - } - - public void add(User user) throws ClassNotFoundException { - - try{ - // db 연결(호스트,이름,비밀번호) - Connection conn = makeConnection(); // 설정들을 모아둔 메서드 호출 - - PreparedStatement ps = conn.prepareStatement("INSERT INTO users(id,name,password) VALUES(?,?,?)"); - ps.setString(1,user.getId()); // mysql 테이블로 값 insert - ps.setString(2,user.getName()); - ps.setString(3,user.getPassword()); - - ps.executeUpdate(); // ctrl + enter 즉, mysql에서 번개모양을 눌러 최신화 한다는 느낌 - ps.close(); - conn.close(); - System.out.println("데이터가 insert 됬습니다."); - - }catch (SQLException e){ - throw new RuntimeException(e); - } - - } - - public User select(String id) throws SQLException, ClassNotFoundException { - - try { - Connection conn = makeConnection(); - PreparedStatement ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); - ps.setString(1, id); // id는 get(String id)로 받은 id - ResultSet rs = ps.executeQuery(); // 쿼리문을 저장함 insert문과 달리 excuteQuery() 사용 - // rs에는 쿼리 실행 결과가 담겨져 있다. (select * from users where id = 1;) - rs.next(); - - // User 생성자를 통해 쿼리문에 id값을 넣어 찾은 id, name,password 값을 저장한다. - User user = new User(rs.getString("id"), rs.getString("name"), rs.getString("password")); - rs.close(); - ps.close(); - conn.close(); - return user; - }catch (SQLException e){ - throw new RuntimeException(e); - } - } - - public static void main(String[] args) throws ClassNotFoundException, SQLException { - UserDao userDao = new UserDao(); - userDao.add(new User("7","Ruru","1234qwer")); // user로 값을 받아 DTO에 저장한 후 mysql로 데이터 보냄 - System.out.println(userDao.select("1")); - } -} \ No newline at end of file diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java deleted file mode 100644 index cb9357e..0000000 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.dbexercise.dao; - -import com.dbexercise.domain.User; - -import java.sql.*; -import java.util.Map; - -// 추상화를 통해 여러 DB의 값들을 따로 호출하여 사용하는 방법 (2번째 방식) -import java.util.Map; - -public abstract class UserDaoAbstract { - - public abstract Connection makeConnection() throws SQLException; - // DB를 여러개 동시에 사용하는 경우 각 DB에 연결시켜야 하므로 추상화 클래스를 상속받아 - // 원하는 DB로 연결시키는 방식에 사용 - - public void add(User user) throws ClassNotFoundException { - - try{ - // db 연결(호스트,이름,비밀번호) - Connection conn = makeConnection(); // 설정들을 모아둔 메서드 호출 - - PreparedStatement ps = conn.prepareStatement("INSERT INTO users(id,name,password) VALUES(?,?,?)"); - ps.setString(1,user.getId()); // mysql 테이블로 값 insert - ps.setString(2,user.getName()); - ps.setString(3,user.getPassword()); - - ps.executeUpdate(); // ctrl + enter 즉, mysql에서 번개모양을 눌러 최신화 한다는 느낌 - ps.close(); - conn.close(); - System.out.println("데이터가 insert 됬습니다."); - - }catch (SQLException e){ - throw new RuntimeException(e); - } - - } - - public User select(String id) throws SQLException, ClassNotFoundException { - - try { - Connection conn = makeConnection(); - PreparedStatement ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); - ps.setString(1, id); // id는 get(String id)로 받은 id - ResultSet rs = ps.executeQuery(); // 쿼리문을 저장함 insert문과 달리 excuteQuery() 사용 - // rs에는 쿼리 실행 결과가 담겨져 있다. (select * from users where id = 1;) - rs.next(); - - // User 생성자를 통해 쿼리문에 id값을 넣어 찾은 id, name,password 값을 저장한다. - User user = new User(rs.getString("id"), rs.getString("name"), rs.getString("password")); - rs.close(); - ps.close(); - conn.close(); - return user; - }catch (SQLException e){ - throw new RuntimeException(e); - } - } - - - public static void main(String[] args) throws ClassNotFoundException, SQLException { - AWSUserDaoImpl userDao = new AWSUserDaoImpl(); - userDao.add(new User("7","Ruru","1234qwer")); // user로 값을 받아 DTO에 저장한 후 mysql로 데이터 보냄 - System.out.println(userDao.select("1")); - } - -} diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoConnectionMaker.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoConnectionMaker.java deleted file mode 100644 index 03a3691..0000000 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoConnectionMaker.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.dbexercise.dao; - -import com.dbexercise.domain.User; - -import java.sql.*; -import java.util.Map; - -// 2번째 방식을 클래스로 따로 빼내어 사용하는 방식 (3번째 방법) -public class UserDaoConnectionMaker { - - AWSConnectionMaker awsConnectionMaker; - - public UserDaoConnectionMaker(AWSConnectionMaker awsConnectionMaker) { - this.awsConnectionMaker = awsConnectionMaker; - } - - public void add(User user) throws ClassNotFoundException { - - try{ - // db 연결(호스트,이름,비밀번호) - Connection conn = awsConnectionMaker.makeConnection(); // 설정들을 모아둔 메서드 호출 - - PreparedStatement ps = conn.prepareStatement("INSERT INTO users(id,name,password) VALUES(?,?,?)"); - ps.setString(1,user.getId()); // mysql 테이블로 값 insert - ps.setString(2,user.getName()); - ps.setString(3,user.getPassword()); - - ps.executeUpdate(); // ctrl + enter 즉, mysql에서 번개모양을 눌러 최신화 한다는 느낌 - ps.close(); - conn.close(); - System.out.println("데이터가 insert 됬습니다."); - - }catch (SQLException e){ - throw new RuntimeException(e); - } - - } - - public User select(String id) throws SQLException, ClassNotFoundException { - - try { - Connection conn = awsConnectionMaker.makeConnection(); - PreparedStatement ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); - ps.setString(1, id); // id는 get(String id)로 받은 id - ResultSet rs = ps.executeQuery(); // 쿼리문을 저장함 insert문과 달리 excuteQuery() 사용 - // rs에는 쿼리 실행 결과가 담겨져 있다. (select * from users where id = 1;) - rs.next(); - - // User 생성자를 통해 쿼리문에 id값을 넣어 찾은 id, name,password 값을 저장한다. - User user = new User(rs.getString("id"), rs.getString("name"), rs.getString("password")); - rs.close(); - ps.close(); - conn.close(); - return user; - }catch (SQLException e){ - throw new RuntimeException(e); - } - } - - public static void main(String[] args) throws ClassNotFoundException, SQLException { - UserDaoConnectionMaker userDao = new UserDaoConnectionMaker(new AWSConnectionMaker()); - userDao.add(new User("7","Ruru","1234qwer")); // user로 값을 받아 DTO에 저장한 후 mysql로 데이터 보냄 - System.out.println(userDao.select("1")); - } -} \ No newline at end of file diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/domain/User.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/domain/User.java deleted file mode 100644 index b0dcdd1..0000000 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/domain/User.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.dbexercise.domain; - -public class User { - private String id; - private String name; - private String password; - - public User() { - } - - public User(String id, String name, String password) { - this.id = id; - this.name = name; - this.password = password; - } - - public String getId() { - return id; - } - - public String getName() { - return name; - } - - public String getPassword() { - return password; - } - - public String toString(){ - return "id = "+this.id + " name = "+this.name+" password = "+this.password; - } -} diff --git a/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoConnectionMakerTest.java b/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoConnectionMakerTest.java deleted file mode 100644 index fed8527..0000000 --- a/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoConnectionMakerTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.dbexercise; - -import com.dbexercise.dao.AWSConnectionMaker; -import com.dbexercise.dao.UserDaoConnectionMaker; -import com.dbexercise.domain.User; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.sql.SQLException; - - -// 3번째 방식 테스트 -class UserDaoConnectionMakerTest { - @Test - void addAndSelect() throws ClassNotFoundException, SQLException { - UserDaoConnectionMaker userDao = new UserDaoConnectionMaker(new AWSConnectionMaker()); - String id = "12"; - User user = new User(id,"test","1234"); // user 값을 DTO에 저장함 - userDao.add(user); - - User selectedUser = userDao.select(id); // DTO에 저장되어 있는 데이터를 가져와 비교함 - Assertions.assertEquals("test",selectedUser.getName()); - } -} \ No newline at end of file diff --git a/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java b/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java deleted file mode 100644 index f331a64..0000000 --- a/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.dbexercise; - -import com.dbexercise.dao.AWSUserDaoImpl; -import com.dbexercise.domain.User; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.sql.SQLException; - -class UserDaoTest { - - @Test - void addAndSelect() throws ClassNotFoundException, SQLException { - AWSUserDaoImpl userDao = new AWSUserDaoImpl(); - String id = "10"; - User user = new User(id,"test","1234"); // user 값을 DTO에 저장함 - userDao.add(user); - - User selectedUser = userDao.select(id); // DTO에 저장되어 있는 데이터를 가져와 비교함 - Assertions.assertEquals("test",selectedUser.getName()); - } -} \ No newline at end of file From 087a0a736f2b419156f2796ab732532e072e3c31 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 20 Oct 2022 10:38:10 +0900 Subject: [PATCH 179/307] Delete --- Java-Mysql-Connect/.idea/vcs.xml | 6 - Java-Mysql-Connect/gradlew | 234 ------------------ Java-Mysql-Connect/gradlew.bat | 89 ------- .../dbexercise/dao/AWSConnectionMaker.class | Bin 1131 -> 0 bytes .../com/dbexercise/dao/AWSUserDaoImpl.class | Bin 1137 -> 0 bytes .../com/dbexercise/dao/LocalUserDaoImpl.class | Bin 928 -> 0 bytes .../classes/com/dbexercise/dao/UserDao.class | Bin 3326 -> 0 bytes .../com/dbexercise/dao/UserDaoAbstract.class | Bin 2665 -> 0 bytes .../dao/UserDaoConnectionMaker.class | Bin 2806 -> 0 bytes .../classes/com/dbexercise/domain/User.class | Bin 1398 -> 0 bytes .../UserDaoConnectionMakerTest.class | Bin 1366 -> 0 bytes .../classes/com/dbexercise/UserDaoTest.class | Bin 1200 -> 0 bytes Java-Mysql-Connect/settings.gradle | 2 - .../dbexercise/dao/AWSConnectionMaker.java | 24 -- 14 files changed, 355 deletions(-) delete mode 100644 Java-Mysql-Connect/.idea/vcs.xml delete mode 100644 Java-Mysql-Connect/gradlew delete mode 100644 Java-Mysql-Connect/gradlew.bat delete mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/AWSConnectionMaker.class delete mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/AWSUserDaoImpl.class delete mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/LocalUserDaoImpl.class delete mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDao.class delete mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDaoAbstract.class delete mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDaoConnectionMaker.class delete mode 100644 Java-Mysql-Connect/out/production/classes/com/dbexercise/domain/User.class delete mode 100644 Java-Mysql-Connect/out/test/classes/com/dbexercise/UserDaoConnectionMakerTest.class delete mode 100644 Java-Mysql-Connect/out/test/classes/com/dbexercise/UserDaoTest.class delete mode 100644 Java-Mysql-Connect/settings.gradle delete mode 100644 Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSConnectionMaker.java diff --git a/Java-Mysql-Connect/.idea/vcs.xml b/Java-Mysql-Connect/.idea/vcs.xml deleted file mode 100644 index 6c0b863..0000000 --- a/Java-Mysql-Connect/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Java-Mysql-Connect/gradlew b/Java-Mysql-Connect/gradlew deleted file mode 100644 index 1b6c787..0000000 --- a/Java-Mysql-Connect/gradlew +++ /dev/null @@ -1,234 +0,0 @@ -#!/bin/sh - -# -# Copyright © 2015-2021 the original authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# Darwin, MinGW, and NonStop. -# -# (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt -# within the Gradle project. -# -# You can find Gradle at https://github.com/gradle/gradle/. -# -############################################################################## - -# Attempt to set APP_HOME - -# Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac -done - -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" -APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD=maximum - -warn () { - echo "$*" -} >&2 - -die () { - echo - echo "$*" - echo - exit 1 -} >&2 - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac -fi - -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. - -# For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done -fi - -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. - -set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" - -# Use "xargs" to parse quoted args. -# -# With -n1 it outputs one arg per line, with the quotes and backslashes removed. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' - -exec "$JAVACMD" "$@" diff --git a/Java-Mysql-Connect/gradlew.bat b/Java-Mysql-Connect/gradlew.bat deleted file mode 100644 index 107acd3..0000000 --- a/Java-Mysql-Connect/gradlew.bat +++ /dev/null @@ -1,89 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/AWSConnectionMaker.class b/Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/AWSConnectionMaker.class deleted file mode 100644 index 16932c6f45276ad850c878f17011a28b1aa33be7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1131 zcma)5T~pdn5Iq+Hp%4_QLbde6wkn94)|P&#O#;<_)jnza z(CKr3RHu6bD3m(W%p`a3*}Z#q@7etN{rv}kS9lXe6px~Kj3*Jy#4w9F8QBPO5zI%C z$AXMS8A}Y|HPbS^b%tOzcg!Gd*;URkS~4xZ+iFy}bEsG9gd|J0q1TUf#}xZ6D0v@D zmtn4C*bTK>;b+`2OqZ)w-BveFv@P4RxZ#<$Rn|XpXO&^3LB=)Akj~~xr+Qmg-A{G( z+CiZ~ZnZ@rzPII>b+xQF2@h8*JGSeIihNgHw`!{9Ii^+Xc#mA}Fhr}Becg3G+fJ3b zGN=-Ui5sX=gT0+Md;Jv#+1G{{hmm!vBD#HM@TO?om7&sJvs;eA-#5nNSKQCj14vg2W|+y};<0>>%O^}sNc`!jaup^xK629g0sKU$ zoKJ>(_HI5Y_v{sEVR2HrL}Vp28Tvv8gAim>ev&vOq7Wn*qR3$!%SibJtanJd1xPec zJo~#+Y}a8J&E-pn{Fv+h z=bC;Qpwy^vjwOjOdKB0-z04crk5|kM*AFC{FjV7CRW}09cB;*&L}bt^<~H~JFRoXi zjx2&?7`_2&q`R-vM!UC#ZuI4=h*v!;#6nv?u|z|5=&R6aZ@5RECEnWd76-d;WlnaH zL=TcGo+R-U^9*Y7&4-OGV^_tqB%Wh|q5t1rn@M}d`VK=6rEjkq#=+K3QN@cSY5$5L z`(HsA#;?g~DYk0*fyXVn=;07s3S_)5U3AvX>C_KIoy4h%Ak=N3t!syJsjyDlK?+kc z!&I*04!6uhnvA8^OoY<5Tnr-@G>V>mEW9#zcvVWBqB@tO!%*(5*qV$Ej2k`IPa?9o zMgNg}BA~lQlD;Y0>9jIhW7B6~-@pze9=O7h>f?I^MQ73u(1&FDf&$8RZ;_#aJfxl@3NB!R~}bQcws&f{YPF9z&SN z?U2Aq6Qo5zq3IgJFcIm;Bt|ewWX6!8+)=8RC%PH36gnNH%6EzQ7-7gJnkVm(b)P&6 MtqP{_zvQCZ1c!;=Y9kc$mebEEcj@w6KI_6OT=- zFl4s9(2I8%(v|8FgRv{yf??Y6Lh-R5w1hh3EuWC0BVFzvapmcF3>tCQix^fMR|a;w zB~FBLy-3(?F72fLQzXrD+ik zbQ?*wAA7#t;61_(m*@A_gVWVuITA* zBNI<3ZpyxL#d}YCQu=qs7rNaXZoo3}G=~bR4D-kBmRk>oG-BPheeGgbMsdAXd$~dL zC@Eux?5o$cH|ralZ%wS`@C<7V%h&LfVd;vhvFYzxQLMO2>ZOUt%>!pL5W`G@k4zXw zu?XlobVQt3KYR9R{xZKj(b-epK&S=}c}FOQJh9F{A48*Z+0E-9SKkIK!lYZQei~wV&)QBW@WGq`i$c71&c&Y75GDu$H&=khfV8%!qc{Bpt zEoqyiX=vJX-;%Cr(GdlLUK40NWfn~5v_MN_U|zsKYGn<9 z-Ep&EB+L0F!=BZba@2(4Rz}aw>$WN1J*D5dVwMCB#xqtvmR&M#7+R&%lX0=Kppg=;dpyIOY4Tr8m%sc+3L zO6y*XBB*1!yEX9Ke;0Eqq(ScQkw#-_!6oo)9=Tm86&1@KkbkCM2Cd$u%g70hi0e-0AM|e}gTN-|hpJ@0g-qi3j`S>}0 zq2X;D)$mLFO5pIl*VjLI>-~SfwEnO47sFeFwUi88WKoK+<)3q;F+Zrx0Azl$fG${B564jR=JR^0pDVkUMul{akwlSjyreu zROeE|qE}UN>?WIg1#)rT?ccik57Tb4i1}-U$f?Z(|B(!aATCtVr4+p=F|NqNX>eui56h) zQydigs+?~f>6PY{n463R+De8~;Y&`KsT}}u!YB+-;klhs{aWbYEtM%d##}MW`Rd+# zQv!iZ&ML__tIYCxcZO*(x>=C13_Z_ER0!FsW~8Frl#_SO4h4`SzPnLBd&Rb{%S+Uq z{+gH0`LbcJNjMF~Xq>8{8k;q(JYU8Qrpv4QIkG~SRaUn2=MJsqsRW*C%*@j^^VzJC zsJ5W39)fus<{yk<{y72y;EcghK9BJ&#$O?|M{YyhqTs`EK3iR78y=;sRW{%R9&^_@ zZMjPt{{t=D35?u*(cwdK z$UnG&U7Oh5f}sG#&WhMdaZg3uL`Yy^XcKz{qMO(!@E-Pux;Aj&9dsn_qGvIB8xQ>L zmP_h1Cug^Z|8aCMUN5r@V;Aeyg9q_29wPoeUU2Z?c9YK?dK(7!XLZnC5 zc*P^)BQ+wbcn=Dk^!NBT@lgW5i{8Z^f9TLA!ah(qTooR4h1+>?q(ENef@J58|XS?C3Vf1dC!vB)~ky0lEPr2@E6qb23h z(o3u}IL87{)0ZS8K$|*MD>bTC=zGMYN`?3kmq=BuX}ZZ(8&XJDxWZ+(m4N=c=v%yv z{`jDzBlJip5*i@#4IE)F42IY&(G3jMPg}@swF#&!S`Q1>$CAmicF`}rVHR`zRf&0? N=(jiR0@r+a_J6M0Egb*= diff --git a/Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDaoAbstract.class b/Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDaoAbstract.class deleted file mode 100644 index 84434abc3cfe1709426b95f1fb95921a4e26583c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2665 zcmaJ@TUQfT6#h;~m=FfAk&9T=;DrVOBWksZ)lv)<3?K;?(OMaj5eJh@oJ<6JwXJQf z*497Jx31NfK44c1i@H|(-k(zJL!W%>>USm~i3Gb?O!n-v&))m{_9glA-`{=*Z~~8g z=)eUZ4j|&iNG(P&=0g)M)?yq{DaGVtLcUJQ$CNags=+iac`@U|Wn5A4u7ayRY{PqA zT$4t#wa_r9AnrxK6cb+PUR;-+=H>g8f*U@x;er>27Ykn8ly6BdQt~q`y_yO#3T_Eh zpElBleMX=v*f}NO9xxNSKtsex>!Z2UoNi5Mb4hCa5i_nOr!>ou?**mXzF}kq_DAAo zDwLShmvk#`Wc5%&GeeVE-8!e4{c~B{(&BcXKz&NPsSlXxv>vw&GcC{(?2IgEx3y6A zRx(sNps6ps6xTD-iteklL_%Osup)|?(u}kdsL#ngPTvAeFY)Qh&{tdO@S>$>G)qs! zY|YkFdRnF^h_t0-5*v>c6XB^lM@-VkX1HaE2-MMG{N{+3aY$0Y8`W7oNzej^gL&sk zEj=HK*_M%>@9X@3cP@)*He*b391U z#{!DP$=V6*tH_O&?VpYniaV6bBxSW?X3mQ1gNAIB#=_Y~;Sb3Qt9T7T6^9TK=p7o3 zg`*RJq0x!4fQ*z48j0?-meRX3S~k0AT8YlURDWbL91EW9=3l3RtO^@B6}PddU`fRt zyszQ|EUNfWK0d<7Dn3C_!Ce)f;xmEv^+(IkzW?R#d&_?<-whaPhOqM6HcYVx%j+$$)6qMnissU`kE(;em<3=KKSL(Xo*{ zw!rlHa5PMdz?*@yD!#&f1z)RpfQJn5@;*}W4IZ(Kk`@8)1~D@3w?w!3VntQh$|ra| znzM4e-h1Tev0IC}rJ@%{c+{)nO`MVNzZ2NIg|kgH6xdecVr*`~>E%F4HIQWCMooLr z%%u}WlGt8FW=qpeUzz;m6$kHSb5Xp#)u?*rb$f{I-?*_v%4ce$cyh5+To$Ow>UMtm zgGSV`dPli_;)Z1|%Ejy~LbZ_Lcuu$ONQ7l; zwtRi~iv$<7vgPz8rpvE`%Or}(H;C#e4_Mq?r6wq-1Ws;YSV?iEM((8-(B?ahklgM3 z0`1@zD&T>TyM)h9zJ>THr1sz{#1jfG9OSdwQP!f1vYIzQH+lfKkUNN)!#r{Gvw{Dd z3Eq?L{y`PBz@>vLaE)~PtJdIlVYJ8HwF1u?s;kiBp{V4=YKq>xxP}^m>7F(C1iIHy zEATT^f87e|e?;BLQ*4{*Ud1baJaKXv#t7q9Ihh_u9pg0-RtxH}1FihqkDbi14aczy zr?DGvV-JS0kGIp4agG}IJ{IL#yOggg<#PYSDPxKJR%UnF7!?{;l&D%LQni47+UBY9LOjPT zsdAXACO-`%x&{L{m*)!C$&{qJ<0;x^R-WBXy!TwT{ s`khug123~`WnKpuRp#HE_r}5w^36-k?+{bIWo4w(%s^m>XD$r?2V&NOr~m)} diff --git a/Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDaoConnectionMaker.class b/Java-Mysql-Connect/out/production/classes/com/dbexercise/dao/UserDaoConnectionMaker.class deleted file mode 100644 index 804656464bbbb3b24668f1c2a0427845e89d9cf3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2806 zcma)8+fx%)9R5y7$b|(l3W}lztr{R0L0hXR)MBW#373S6Krb%I7FUyO+$4g%+SayK zYiqA>ed|nL`hXpUq0F@J{Zop4>x^%mekTb@B(c-k*^_hoUB2&k$^P-rufG8}f$v@L zBIv{(gk0E*VFyO)Fp4o3nh~x;1mkixA%{u1oRY%@dF6r=)0lB!)`eH`njNp(@rDaq zanS))UYe^z6frwA2L|NyO$X*3xFj{{a(%&$%XVCmR)a3uk2{cXAnAZ1S1AXs%3o7z zPur0ZaH|XH0VA2zq8Z&thSV#XDR4L#H4^^VoVKW$Q9Z5sW2)glI~Cbw4T&6 zeF7cc|0&ZxDPSEiVw%8~pq|u*vxzy)99QS!+;Inus2ZPCO!j zGta3;rDHW}EGDq8(kmmO>Pf$p>&>|mC3u0R;AQoi>Q7&d`%Air&yu3$*3#jqsijm? zi$yYOMoVbP4DSd!zN2&{G8POhMzxgWlc&}!O-UV_DJ^qEpq>h&S3+v4fZ0`4!7ydX zb6SftL;^>>c}sCMIq#2TOg%Z@+y39WEhaH+FF6?2(%E<>qDkK^I$3g8s-)kNCxK?~ zY~^W=IMtk|-fdNm1?&eWE+FA-GNUK7V(=uW&jtLEKrk>c?%C|WXD~bx z%473PoezWqyx}?H=~r+UU)b@bf_wOi2A-Ze3ckiS43?xtz_CG$wEL|<`({CwarF=g z9ISG;vgD;=A5;DWZHBWZGt<%CbL{xl1Y#bHB0?xFS$rq`tq@n7SWT%1QT>R=d8!hBEdji{UG@H>T zQZY8094kWtwrJc)b5+J{13J4B(C=>{FrlhVAVCW;(Axy?#V$xCtB0;_cv zhGA#<{`e)+SdhIr*F2SihhtgIye<)z#izW>xQhfAcV*6Mi*%Q7b_{Q+>y!k1loLR5)#_@@95=!xZulH#L>z*bDm=tSA($d0bCs`5FMQl zVY$zh1xGkGpoU{TB^uzw7Wlbp&fmsSbaO?yoK{weEEb+goqto#%HP?J2e2%oCggKl zS7EbYxXaqPjM`P$YtUum)RCXoa_Y=aSK$(v>RLsefNvFwz%QtGH!NezPpA*AVe7PS z1@7PP=KzKHfze1~(%I+eD9{84cJT9JCtA^h!`MZ)T5*yj^z#cMfPDzz0HxY6hW(hq z!5paLuu(36<9L=3w&FCkouJ+^!hW98lAzfl`dAqjPq$dzJ65sN0!~^sCcAQz73@A`lXqJg zz%rUzY)d72a_r3U^J#;f9w>C8gD5+R&qr>$$bp~1>meh@Fiz|dItCkcsk}fBimuVe4zpGIbj!qT z6Y~r?ugg$v@AD(>_&nHkwp8c^yG;fo;61@m?DHskFGDITtb2i{o-pJai#t@%l3gmO zw7o!V9`-sS+~yshZmMnRa({=1o<66ShT8KYhMBf2drr3_K8VouBH?spk9&dhCK4h2 z^igA2%D>!bJtMn9Jtvv9#^Nx9!KBZdaZ97LdwtebQOTrdhVqs?3|+C|=`KoI(yBJb zf`u^)MU*U*br?m7VdANjDpDcuzZ7aucB4uG3q{*LKY^YwvYs>csRO9n1iZ#}g~yGZdsk*zQO*SBG(Of2aZ9ESOGm0oZp z4@5c~iGmI8Dj6P|xKESOmh#}R&tN?d0ui=+a#xV7kAt#Oj>N5JJm~r&nooeuVHpEA zzX7+8`y!+K-9UX}X>)K2Qi>M${Vh+4rilj(3q$>7X=9lEdmZNJRhjgt^2q5SpKE1V2t88oz^Hb$|Lqyu+MQ>g<_dtAOeFR6ST9EB3y!gv6|pAMNQySr9ru- z3GAg4H$i1fOyfQ!HGIs>RZ^lA4}#YKmSI zuB3l#vOz_n+@Os<^DYQv8tvoH` nRQq$0X?B3An%a}cwYbx1tWqwM0n50D6}r7i=OUf!wB~*ST8t#N diff --git a/Java-Mysql-Connect/out/test/classes/com/dbexercise/UserDaoConnectionMakerTest.class b/Java-Mysql-Connect/out/test/classes/com/dbexercise/UserDaoConnectionMakerTest.class deleted file mode 100644 index f1d3a032139f93c90bde41cab72429c16ed9f413..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1366 zcma)6Yf}Be*`kdKz{$ykMAq->`jI7bWRQ>N#uMj?V)RmE3Ww=6Qp-qwzxe!ZrDY zG}}GuMW^9b#EDeY%@3zzRlzrK2XTf}4~fIOXILEIoBdSmAzUTiBc|3j7-o7SI%E)I zK3xq>>l>R}Drnz81_uUS;?Te=yw;F4@CLblki%PJnCRTi+wysE*$W+0uEssD;P@v_ z!?ymB&oC9Zc$YP^_%7dNUrP4fC&{C~>5P)`Ub0^p|6@_HVbUjET7S6?V?mA4mVg-6 z1{6#6f$fSW(N~3E;B^wmWHQwcjA3E0ys{pNwJkw|_@mA7WrNq~PnhUN(c(MPmAP$6 zm9T&qeKph*qL-uxhP$*fX=XH!EH%Nt2gj2%jt0hYOwrnCIp7}d(++q*!QmkI8%F2{ z?A#!9c7yO)6OkrH^6}Br8)#?C@o4;36M7-Na*eU{@->Y8NIW_nxyJYp-0oDHqYo4a zUMv6>$2?_!MzzyabDOFv6kDxIZ4@yiFpU{P7AMb#n5DMn$@3BB2wNIsw3|bO+E%@U T@EA|@j4NrB%u$ab@hFlu?G?sNFv7*pb zwXCV@x(*W?8a6d-F{BQpBZF5A@m#*jkT`NJ!7x&ijwrXAHQ}A|noUTiGmQ{4Dim*jJV9?qfDZ`U~JBzz! z@lz!-f75K)WFC{2qCe+fxM_2zVO9c9It`K}l&4$hEw{;~6Goxv{g7B#$}NL_d|4N* zK)Q~vVOzrv!{mpy6Ue5hN?%fPMaOXi9%?A(uGcWn+f*c4TQU%y$y?Hla?>kr+pCKc zscJMD1+HZ4DqaI47-d-KE6-q>l;!3I!&JXwHxbGBTztRg%5@OyUc6N<;DU*16gXGz2CY8~ykuI;SUE$8k>J{|; zL?$(vxWdqP7+soKXkqNnc(9+Dm-{VXOiMfpq+ i@(9xuRF=>gIwdemmMN0WQRWNbnc*?*^w4RIA^QjRY$wbB diff --git a/Java-Mysql-Connect/settings.gradle b/Java-Mysql-Connect/settings.gradle deleted file mode 100644 index 6e01e4f..0000000 --- a/Java-Mysql-Connect/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -rootProject.name = 'Java-Mysql-Connect' - diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSConnectionMaker.java b/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSConnectionMaker.java deleted file mode 100644 index 19a04e8..0000000 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSConnectionMaker.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.dbexercise.dao; - - -// 2번째 방식을 클래스로 따로 빼내어 사용하는 방식 (3번째 방법) - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.Map; - -public class AWSConnectionMaker { - public Connection makeConnection() throws SQLException { - Map env = System.getenv(); // 아래의 값들은 해킹 위험이 있으므로 코드상에 데이터를 넣지말고 - // 왼쪽 위에 메뉴바에서 망치 옆에 프로젝트를 눌러 edit configurations를 누르고 - // environments variables를 눌러 값을 입력해 준다. - String dbHost = env.get("DB_HOST"); // DB 호스트 번호(AWS 주소) 가져옴 - String dbUser = env.get("DB_USER"); // DB 호스트 이름 가져옴 - String dbPassword = env.get("DB_PASSWORD"); // DB 비밀번호 가져옴 - - Connection conn = DriverManager.getConnection(dbHost,dbUser,dbPassword); - - return conn; - } -} From 76b971000cfd1c05a015facd229c4cb1ec114543 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 20 Oct 2022 10:39:24 +0900 Subject: [PATCH 180/307] TDD(Factory test) --- .../Factory/UserDaoInterfaceTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Project/src/test/java/Date10_20/Factory/UserDaoInterfaceTest.java diff --git a/Project/src/test/java/Date10_20/Factory/UserDaoInterfaceTest.java b/Project/src/test/java/Date10_20/Factory/UserDaoInterfaceTest.java new file mode 100644 index 0000000..c84537c --- /dev/null +++ b/Project/src/test/java/Date10_20/Factory/UserDaoInterfaceTest.java @@ -0,0 +1,23 @@ +package Date10_20.Factory; + +import Date10_20.dao.Factory.UserDaoFactory; +import Date10_20.dao.Factory.UserDaoInterface; +import Date10_20.domain.User; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.sql.SQLException; + +class UserDaoInterfaceTest { + + @Test + void addAndSelect() throws ClassNotFoundException, SQLException { + UserDaoInterface userDao = new UserDaoFactory().awsUserDao(); + // awsUserDao()가 UserDaoInterface를 반환하기 때문에 다형성 가능 + String id = "2"; + userDao.add(new User(id,"Nunu","123")); + + User user = userDao.select(id); + Assertions.assertEquals("Nunu",user.getName()); + } +} \ No newline at end of file From fcfb8a1f00f0d243d18835031341483e7be9755d Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 20 Oct 2022 10:39:44 +0900 Subject: [PATCH 181/307] TDD --- .../test/java/Date10_20}/UserDaoConnectionMakerTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) rename {Java-Mysql-Connect/src/test/java/com/dbexercise => Project/src/test/java/Date10_20}/UserDaoConnectionMakerTest.java (81%) diff --git a/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoConnectionMakerTest.java b/Project/src/test/java/Date10_20/UserDaoConnectionMakerTest.java similarity index 81% rename from Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoConnectionMakerTest.java rename to Project/src/test/java/Date10_20/UserDaoConnectionMakerTest.java index fed8527..8144e3c 100644 --- a/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoConnectionMakerTest.java +++ b/Project/src/test/java/Date10_20/UserDaoConnectionMakerTest.java @@ -1,8 +1,9 @@ -package com.dbexercise; +package Date10_20; -import com.dbexercise.dao.AWSConnectionMaker; -import com.dbexercise.dao.UserDaoConnectionMaker; -import com.dbexercise.domain.User; + +import Date10_20.dao.Factory.AWSConnectionMaker; +import Date10_20.dao.UserDaoConnectionMaker; +import Date10_20.domain.User; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; From f5e6d912d7660f8137fff9d1e704f60bbfcb07b4 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 20 Oct 2022 10:40:10 +0900 Subject: [PATCH 182/307] Factory --- .../dao/Factory/AWSConnectionMaker.java | 23 +++++++ .../dao/Factory/ConnectionMaker.java | 8 +++ .../dao/Factory/LocalConnectionMaker.java | 16 +++++ .../Date10_20/dao/Factory/UserDaoFactory.java | 23 +++++++ .../dao/Factory/UserDaoInterface.java | 69 +++++++++++++++++++ 5 files changed, 139 insertions(+) create mode 100644 Project/src/main/java/Date10_20/dao/Factory/AWSConnectionMaker.java create mode 100644 Project/src/main/java/Date10_20/dao/Factory/ConnectionMaker.java create mode 100644 Project/src/main/java/Date10_20/dao/Factory/LocalConnectionMaker.java create mode 100644 Project/src/main/java/Date10_20/dao/Factory/UserDaoFactory.java create mode 100644 Project/src/main/java/Date10_20/dao/Factory/UserDaoInterface.java diff --git a/Project/src/main/java/Date10_20/dao/Factory/AWSConnectionMaker.java b/Project/src/main/java/Date10_20/dao/Factory/AWSConnectionMaker.java new file mode 100644 index 0000000..9149314 --- /dev/null +++ b/Project/src/main/java/Date10_20/dao/Factory/AWSConnectionMaker.java @@ -0,0 +1,23 @@ +package Date10_20.dao.Factory; + +// AWS DB 연결 +// 2번째 방식을 클래스로 따로 빼내어 사용하는 방식 (3번째 방법) +// interface 상속 +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Map; + +public class AWSConnectionMaker implements ConnectionMaker{ + @Override + public Connection makeConnection() throws SQLException, ClassNotFoundException { + Map env = System.getenv(); // 환경변수를 사용하여 + String dbHost = env.get("DB_HOST"); + String dbUser = env.get("DB_USER"); + String dbPassword = env.get("DB_PASSWORD"); + + Class.forName("com.mysql.cj.jdbc.Driver"); + Connection conn = DriverManager.getConnection(dbHost, dbUser, dbPassword); + return conn; + } +} diff --git a/Project/src/main/java/Date10_20/dao/Factory/ConnectionMaker.java b/Project/src/main/java/Date10_20/dao/Factory/ConnectionMaker.java new file mode 100644 index 0000000..7424cdf --- /dev/null +++ b/Project/src/main/java/Date10_20/dao/Factory/ConnectionMaker.java @@ -0,0 +1,8 @@ +package Date10_20.dao.Factory; + +import java.sql.Connection; +import java.sql.SQLException; + +public interface ConnectionMaker { // makeConnection을 각 DB에 맞게 사용할 수 있도록 불러오기 위한 interface + Connection makeConnection() throws SQLException, ClassNotFoundException; +} diff --git a/Project/src/main/java/Date10_20/dao/Factory/LocalConnectionMaker.java b/Project/src/main/java/Date10_20/dao/Factory/LocalConnectionMaker.java new file mode 100644 index 0000000..edeab66 --- /dev/null +++ b/Project/src/main/java/Date10_20/dao/Factory/LocalConnectionMaker.java @@ -0,0 +1,16 @@ +package Date10_20.dao.Factory; + + +// local DB 연결 +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class LocalConnectionMaker implements ConnectionMaker{ + @Override + public Connection makeConnection() throws SQLException { + Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/likelion-db","root","password"); + + return conn; + } +} \ No newline at end of file diff --git a/Project/src/main/java/Date10_20/dao/Factory/UserDaoFactory.java b/Project/src/main/java/Date10_20/dao/Factory/UserDaoFactory.java new file mode 100644 index 0000000..cc699fe --- /dev/null +++ b/Project/src/main/java/Date10_20/dao/Factory/UserDaoFactory.java @@ -0,0 +1,23 @@ +package Date10_20.dao.Factory; + + +// 인터페이스로 받은 것을 어떤것을 UserDaoInterface로 넘겨줄것인지 설정 +// 즉, 인터페이스로 DB별 연결 설정을 나눠놨는데 여기서 메서드별로 다시 DB별로 나누어 +// UserDaoInterface로 해당 DB 연결 설정 값을 보냄 +// (4번째 방식) +public class UserDaoFactory { + public static void main(String[] args) { + + } + + public UserDaoInterface awsUserDao(){ + AWSConnectionMaker awsConnectionMaker = new AWSConnectionMaker(); + UserDaoInterface userDao = new UserDaoInterface(awsConnectionMaker); + return userDao; + } + + public UserDaoInterface localUserDao(){ + UserDaoInterface userDao = new UserDaoInterface(new LocalConnectionMaker()); + return userDao; + } +} diff --git a/Project/src/main/java/Date10_20/dao/Factory/UserDaoInterface.java b/Project/src/main/java/Date10_20/dao/Factory/UserDaoInterface.java new file mode 100644 index 0000000..3da91fc --- /dev/null +++ b/Project/src/main/java/Date10_20/dao/Factory/UserDaoInterface.java @@ -0,0 +1,69 @@ +package Date10_20.dao.Factory; + +import Date10_20.domain.User; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +// 중복코드만 따로 빼내서 작성한 코드 (3번째 방식) +public class UserDaoInterface { + + private ConnectionMaker connectionMaker; // interface의 makeConnection()를 가져옴 + public UserDaoInterface(){ // 생성자를 통해 AWS DB의 makeConnection()을 오버라이딩하여 사용 + this.connectionMaker = new AWSConnectionMaker(); + } + public UserDaoInterface(ConnectionMaker connectionMaker){ + this.connectionMaker = connectionMaker; + } + + public void add(User user) throws ClassNotFoundException { + + try{ + // db 연결(호스트,이름,비밀번호) + Connection conn = connectionMaker.makeConnection(); // 설정들을 모아둔 메서드 호출 + + PreparedStatement ps = conn.prepareStatement("INSERT INTO users(id,name,password) VALUES(?,?,?)"); + ps.setString(1,user.getId()); // mysql 테이블로 값 insert + ps.setString(2,user.getName()); + ps.setString(3,user.getPassword()); + + ps.executeUpdate(); // ctrl + enter 즉, mysql에서 번개모양을 눌러 최신화 한다는 느낌 + ps.close(); + conn.close(); + System.out.println("데이터가 insert 됬습니다."); + + }catch (SQLException e){ + throw new RuntimeException(e); + } + + } + + public User select(String id) throws SQLException, ClassNotFoundException { + + try { + Connection conn = connectionMaker.makeConnection(); + PreparedStatement ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); + ps.setString(1, id); // id는 get(String id)로 받은 id + ResultSet rs = ps.executeQuery(); // 쿼리문을 저장함 insert문과 달리 excuteQuery() 사용 + // rs에는 쿼리 실행 결과가 담겨져 있다. (select * from users where id = 1;) + rs.next(); + + // User 생성자를 통해 쿼리문에 id값을 넣어 찾은 id, name,password 값을 저장한다. + User user = new User(rs.getString("id"), rs.getString("name"), rs.getString("password")); + rs.close(); + ps.close(); + conn.close(); + return user; + }catch (SQLException e){ + throw new RuntimeException(e); + } + } + + public static void main(String[] args) throws ClassNotFoundException, SQLException { + UserDaoInterface userDao = new UserDaoInterface(); + userDao.add(new User("7","Ruru","1234qwer")); // user로 값을 받아 DTO에 저장한 후 mysql로 데이터 보냄 + System.out.println(userDao.select("1")); + } +} \ No newline at end of file From 4f72d1ac29eeb47a3d4f5dcc960acfcdad818db4 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 20 Oct 2022 10:40:31 +0900 Subject: [PATCH 183/307] Interface --- .../dao/Interface/AWSConnectionMaker.java | 24 +++++++ .../dao/Interface/ConnectionMaker.java | 8 +++ .../dao/Interface/LocalConnectionMaker.java | 17 +++++ .../dao/Interface/UserDaoInterface.java | 69 +++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 Project/src/main/java/Date10_20/dao/Interface/AWSConnectionMaker.java create mode 100644 Project/src/main/java/Date10_20/dao/Interface/ConnectionMaker.java create mode 100644 Project/src/main/java/Date10_20/dao/Interface/LocalConnectionMaker.java create mode 100644 Project/src/main/java/Date10_20/dao/Interface/UserDaoInterface.java diff --git a/Project/src/main/java/Date10_20/dao/Interface/AWSConnectionMaker.java b/Project/src/main/java/Date10_20/dao/Interface/AWSConnectionMaker.java new file mode 100644 index 0000000..8394084 --- /dev/null +++ b/Project/src/main/java/Date10_20/dao/Interface/AWSConnectionMaker.java @@ -0,0 +1,24 @@ +package Date10_20.dao.Interface; + +// AWS DB 연결 +// 2번째 방식을 클래스로 따로 빼내어 사용하는 방식 (3번째 방법) +// interface 상속 + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Map; + +public class AWSConnectionMaker implements ConnectionMaker { + @Override + public Connection makeConnection() throws SQLException, ClassNotFoundException { + Map env = System.getenv(); // 환경변수를 사용하여 + String dbHost = env.get("DB_HOST"); + String dbUser = env.get("DB_USER"); + String dbPassword = env.get("DB_PASSWORD"); + + Class.forName("com.mysql.cj.jdbc.Driver"); + Connection conn = DriverManager.getConnection(dbHost, dbUser, dbPassword); + return conn; + } +} diff --git a/Project/src/main/java/Date10_20/dao/Interface/ConnectionMaker.java b/Project/src/main/java/Date10_20/dao/Interface/ConnectionMaker.java new file mode 100644 index 0000000..764d309 --- /dev/null +++ b/Project/src/main/java/Date10_20/dao/Interface/ConnectionMaker.java @@ -0,0 +1,8 @@ +package Date10_20.dao.Interface; + +import java.sql.Connection; +import java.sql.SQLException; + +public interface ConnectionMaker { // makeConnection을 각 DB에 맞게 사용할 수 있도록 불러오기 위한 interface + Connection makeConnection() throws SQLException, ClassNotFoundException; +} diff --git a/Project/src/main/java/Date10_20/dao/Interface/LocalConnectionMaker.java b/Project/src/main/java/Date10_20/dao/Interface/LocalConnectionMaker.java new file mode 100644 index 0000000..77846fe --- /dev/null +++ b/Project/src/main/java/Date10_20/dao/Interface/LocalConnectionMaker.java @@ -0,0 +1,17 @@ +package Date10_20.dao.Interface; + + +// local DB 연결 + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class LocalConnectionMaker implements ConnectionMaker { + @Override + public Connection makeConnection() throws SQLException { + Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/likelion-db","root","password"); + + return conn; + } +} \ No newline at end of file diff --git a/Project/src/main/java/Date10_20/dao/Interface/UserDaoInterface.java b/Project/src/main/java/Date10_20/dao/Interface/UserDaoInterface.java new file mode 100644 index 0000000..dd01437 --- /dev/null +++ b/Project/src/main/java/Date10_20/dao/Interface/UserDaoInterface.java @@ -0,0 +1,69 @@ +package Date10_20.dao.Interface; + +import Date10_20.domain.User; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +// 중복코드만 따로 빼내서 작성한 코드 (3번째 방식) +public class UserDaoInterface { + + private ConnectionMaker connectionMaker; // interface의 makeConnection()를 가져옴 + public UserDaoInterface(){ // 생성자를 통해 AWS DB의 makeConnection()을 오버라이딩하여 사용 + this.connectionMaker = new AWSConnectionMaker(); + } + public UserDaoInterface(ConnectionMaker connectionMaker){ + this.connectionMaker = connectionMaker; + } + + public void add(User user) throws ClassNotFoundException { + + try{ + // db 연결(호스트,이름,비밀번호) + Connection conn = connectionMaker.makeConnection(); // 설정들을 모아둔 메서드 호출 + + PreparedStatement ps = conn.prepareStatement("INSERT INTO users(id,name,password) VALUES(?,?,?)"); + ps.setString(1,user.getId()); // mysql 테이블로 값 insert + ps.setString(2,user.getName()); + ps.setString(3,user.getPassword()); + + ps.executeUpdate(); // ctrl + enter 즉, mysql에서 번개모양을 눌러 최신화 한다는 느낌 + ps.close(); + conn.close(); + System.out.println("데이터가 insert 됬습니다."); + + }catch (SQLException e){ + throw new RuntimeException(e); + } + + } + + public User select(String id) throws SQLException, ClassNotFoundException { + + try { + Connection conn = connectionMaker.makeConnection(); + PreparedStatement ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); + ps.setString(1, id); // id는 get(String id)로 받은 id + ResultSet rs = ps.executeQuery(); // 쿼리문을 저장함 insert문과 달리 excuteQuery() 사용 + // rs에는 쿼리 실행 결과가 담겨져 있다. (select * from users where id = 1;) + rs.next(); + + // User 생성자를 통해 쿼리문에 id값을 넣어 찾은 id, name,password 값을 저장한다. + User user = new User(rs.getString("id"), rs.getString("name"), rs.getString("password")); + rs.close(); + ps.close(); + conn.close(); + return user; + }catch (SQLException e){ + throw new RuntimeException(e); + } + } + + public static void main(String[] args) throws ClassNotFoundException, SQLException { + UserDaoInterface userDao = new UserDaoInterface(); + userDao.add(new User("7","Ruru","1234qwer")); // user로 값을 받아 DTO에 저장한 후 mysql로 데이터 보냄 + System.out.println(userDao.select("1")); + } +} \ No newline at end of file From 8816c237303dc5ee09387db666ab1a3b6f4d606a Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 20 Oct 2022 10:41:07 +0900 Subject: [PATCH 184/307] Abstract --- .../java/Date10_20/dao/Abstract}/AWSUserDaoImpl.java | 2 +- .../Date10_20/dao/Abstract}/LocalUserDaoImpl.java | 2 +- .../Date10_20/dao/Abstract}/UserDaoAbstract.java | 12 +++++++----- 3 files changed, 9 insertions(+), 7 deletions(-) rename {Java-Mysql-Connect/src/main/java/com/dbexercise/dao => Project/src/main/java/Date10_20/dao/Abstract}/AWSUserDaoImpl.java (97%) rename {Java-Mysql-Connect/src/main/java/com/dbexercise/dao => Project/src/main/java/Date10_20/dao/Abstract}/LocalUserDaoImpl.java (96%) rename {Java-Mysql-Connect/src/main/java/com/dbexercise/dao => Project/src/main/java/Date10_20/dao/Abstract}/UserDaoAbstract.java (93%) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSUserDaoImpl.java b/Project/src/main/java/Date10_20/dao/Abstract/AWSUserDaoImpl.java similarity index 97% rename from Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSUserDaoImpl.java rename to Project/src/main/java/Date10_20/dao/Abstract/AWSUserDaoImpl.java index ea05152..f881ebb 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/AWSUserDaoImpl.java +++ b/Project/src/main/java/Date10_20/dao/Abstract/AWSUserDaoImpl.java @@ -1,4 +1,4 @@ -package com.dbexercise.dao; +package Date10_20.dao.Abstract; import java.sql.Connection; import java.sql.DriverManager; diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/LocalUserDaoImpl.java b/Project/src/main/java/Date10_20/dao/Abstract/LocalUserDaoImpl.java similarity index 96% rename from Java-Mysql-Connect/src/main/java/com/dbexercise/dao/LocalUserDaoImpl.java rename to Project/src/main/java/Date10_20/dao/Abstract/LocalUserDaoImpl.java index 471dc6c..c2af8eb 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/LocalUserDaoImpl.java +++ b/Project/src/main/java/Date10_20/dao/Abstract/LocalUserDaoImpl.java @@ -1,4 +1,4 @@ -package com.dbexercise.dao; +package Date10_20.dao.Abstract; import java.sql.Connection; import java.sql.DriverManager; diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java b/Project/src/main/java/Date10_20/dao/Abstract/UserDaoAbstract.java similarity index 93% rename from Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java rename to Project/src/main/java/Date10_20/dao/Abstract/UserDaoAbstract.java index cb9357e..918c200 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoAbstract.java +++ b/Project/src/main/java/Date10_20/dao/Abstract/UserDaoAbstract.java @@ -1,12 +1,14 @@ -package com.dbexercise.dao; +package Date10_20.dao.Abstract; -import com.dbexercise.domain.User; +import Date10_20.domain.User; -import java.sql.*; -import java.util.Map; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; // 추상화를 통해 여러 DB의 값들을 따로 호출하여 사용하는 방법 (2번째 방식) -import java.util.Map; + public abstract class UserDaoAbstract { From 551c19f4d1a10730ff0073097e4392f212680a0e Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 20 Oct 2022 10:41:25 +0900 Subject: [PATCH 185/307] =?UTF-8?q?DAO(=EC=A4=91=EB=B3=B5=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EB=A7=8C=20=EB=B6=84=EB=A6=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/Date10_20}/domain/User.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename {Java-Mysql-Connect/src/main/java/com/dbexercise => Project/src/main/java/Date10_20}/domain/User.java (94%) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/domain/User.java b/Project/src/main/java/Date10_20/domain/User.java similarity index 94% rename from Java-Mysql-Connect/src/main/java/com/dbexercise/domain/User.java rename to Project/src/main/java/Date10_20/domain/User.java index b0dcdd1..522ee85 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/domain/User.java +++ b/Project/src/main/java/Date10_20/domain/User.java @@ -1,4 +1,4 @@ -package com.dbexercise.domain; +package Date10_20.domain; public class User { private String id; From c48534708222143de8cba7f0c7e898b05f655baa Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 20 Oct 2022 10:41:33 +0900 Subject: [PATCH 186/307] TDD --- .../src/test/java/Date10_20}/UserDaoTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename {Java-Mysql-Connect/src/test/java/com/dbexercise => Project/src/test/java/Date10_20}/UserDaoTest.java (85%) diff --git a/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java b/Project/src/test/java/Date10_20/UserDaoTest.java similarity index 85% rename from Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java rename to Project/src/test/java/Date10_20/UserDaoTest.java index f331a64..f4d3907 100644 --- a/Java-Mysql-Connect/src/test/java/com/dbexercise/UserDaoTest.java +++ b/Project/src/test/java/Date10_20/UserDaoTest.java @@ -1,7 +1,7 @@ -package com.dbexercise; +package Date10_20; -import com.dbexercise.dao.AWSUserDaoImpl; -import com.dbexercise.domain.User; +import Date10_20.dao.Abstract.AWSUserDaoImpl; +import Date10_20.domain.User; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; From f2a301a00a93e0b1d1486ed61d615dc64dcc8134 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 20 Oct 2022 10:42:11 +0900 Subject: [PATCH 187/307] =?UTF-8?q?DAO(=EC=A4=91=EB=B3=B5=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EB=A7=8C=20=EB=B6=84=EB=A6=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/Date10_20/dao/Connection}/UserDao.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename {Java-Mysql-Connect/src/main/java/com/dbexercise/dao => Project/src/main/java/Date10_20/dao/Connection}/UserDao.java (98%) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDao.java b/Project/src/main/java/Date10_20/dao/Connection/UserDao.java similarity index 98% rename from Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDao.java rename to Project/src/main/java/Date10_20/dao/Connection/UserDao.java index 0fea1a4..f0fe6ba 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDao.java +++ b/Project/src/main/java/Date10_20/dao/Connection/UserDao.java @@ -1,6 +1,6 @@ -package com.dbexercise.dao; +package Date10_20.dao.Connection; -import com.dbexercise.domain.User; +import Date10_20.domain.User; import java.sql.*; import java.util.Map; From 086673558678c2fe07eb1f75e657cda2459cf41d Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 20 Oct 2022 10:42:16 +0900 Subject: [PATCH 188/307] - --- .../java/Date10_20}/dao/UserDaoConnectionMaker.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) rename {Java-Mysql-Connect/src/main/java/com/dbexercise => Project/src/main/java/Date10_20}/dao/UserDaoConnectionMaker.java (91%) diff --git a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoConnectionMaker.java b/Project/src/main/java/Date10_20/dao/UserDaoConnectionMaker.java similarity index 91% rename from Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoConnectionMaker.java rename to Project/src/main/java/Date10_20/dao/UserDaoConnectionMaker.java index 03a3691..fcc4ec2 100644 --- a/Java-Mysql-Connect/src/main/java/com/dbexercise/dao/UserDaoConnectionMaker.java +++ b/Project/src/main/java/Date10_20/dao/UserDaoConnectionMaker.java @@ -1,9 +1,11 @@ -package com.dbexercise.dao; +package Date10_20.dao; -import com.dbexercise.domain.User; - -import java.sql.*; -import java.util.Map; +import Date10_20.dao.Factory.AWSConnectionMaker; +import Date10_20.domain.User; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; // 2번째 방식을 클래스로 따로 빼내어 사용하는 방식 (3번째 방법) public class UserDaoConnectionMaker { From ec7413713b4a8e4ff57e0e0e7dc1ed0b676dee26 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Thu, 20 Oct 2022 10:44:36 +0900 Subject: [PATCH 189/307] DTO --- Project/src/main/java/Date10_20/domain/User.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project/src/main/java/Date10_20/domain/User.java b/Project/src/main/java/Date10_20/domain/User.java index 522ee85..81a462a 100644 --- a/Project/src/main/java/Date10_20/domain/User.java +++ b/Project/src/main/java/Date10_20/domain/User.java @@ -29,4 +29,4 @@ public String getPassword() { public String toString(){ return "id = "+this.id + " name = "+this.name+" password = "+this.password; } -} +} From a11d3d025981a5269c2593014743317967ecb5ec Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Thu, 20 Oct 2022 10:45:23 +0900 Subject: [PATCH 190/307] =?UTF-8?q?DAO(=EC=A4=91=EB=B3=B5=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EB=A7=8C=20=EB=B6=84=EB=A6=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/src/main/java/Date10_20/dao/Connection/UserDao.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Project/src/main/java/Date10_20/dao/Connection/UserDao.java b/Project/src/main/java/Date10_20/dao/Connection/UserDao.java index 8195339..ceacfa7 100644 --- a/Project/src/main/java/Date10_20/dao/Connection/UserDao.java +++ b/Project/src/main/java/Date10_20/dao/Connection/UserDao.java @@ -70,5 +70,5 @@ public static void main(String[] args) throws ClassNotFoundException, SQLExcepti UserDao userDao = new UserDao(); userDao.add(new User("7","Ruru","1234qwer")); // user로 값을 받아 DTO에 저장한 후 mysql로 데이터 보냄 System.out.println(userDao.select("1")); - } -} \ No newline at end of file + } +} From 948145e07b38b848b58f6ce5b375b9c61d8b8b49 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Thu, 20 Oct 2022 10:51:09 +0900 Subject: [PATCH 191/307] Update README.md --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4bc6095..add6f34 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,12 @@ - 2022-10-14 : 알고리즘[삽입정렬] + Mysql(기초 문법) + TDD - 2022-10-17 : 알고리즘[For문 별찍기] + Java/Mysql 연결(Insert) - + +- 2022-10-18 : 알고리즘[For문 사각형 만들기] + Java/Mysql 연결(리팩토링 : 중복 코드 분리, Abstract하여 DB별 설정 나누기) + +- 2022-10-19 : 알고리즘[Stack(1)] + Java/Mysql 연결(리팩토링 : Interface, class, Factory 분리) + +- 2022-10-20 : 알고리즘[Stack(2)]
# ⚙️ 기술 스택 From e3a269c44568fe4c75d5d80828d147f5588d18dc Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Thu, 20 Oct 2022 10:55:05 +0900 Subject: [PATCH 192/307] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index add6f34..50c7115 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ - 2022-10-18 : 알고리즘[For문 사각형 만들기] + Java/Mysql 연결(리팩토링 : 중복 코드 분리, Abstract하여 DB별 설정 나누기) -- 2022-10-19 : 알고리즘[Stack(1)] + Java/Mysql 연결(리팩토링 : Interface, class, Factory 분리) +- 2022-10-19 : 알고리즘[Stack(1)] + Java/Mysql 연결(리팩토링 : Interface, class, Factory 분리) + spring 연동(spring 시작) - 2022-10-20 : 알고리즘[Stack(2)]
From bcd9b1db55bd3826a81f341ffe2c993483a3252e Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 20 Oct 2022 10:59:56 +0900 Subject: [PATCH 193/307] =?UTF-8?q?spring=20=EC=84=A4=EC=A0=95=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/build.gradle | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Project/build.gradle b/Project/build.gradle index db6e684..cc5f37e 100644 --- a/Project/build.gradle +++ b/Project/build.gradle @@ -10,10 +10,11 @@ repositories { } dependencies { - implementation 'mysql:mysql-connector-java:8.0.30' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' - + implementation 'mysql:mysql-connector-java:8.0.30' + implementation 'org.springframework.boot:spring-boot-starter-jdbc:2.7.4' + implementation 'org.springframework.boot:spring-boot-starter-test:2.7.4' } test { From f42a994e67add8d95a871196351f21e2a0a55be9 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 20 Oct 2022 11:00:16 +0900 Subject: [PATCH 194/307] =?UTF-8?q?DAO-Factory(spring=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/Date10_20/dao/Factory/UserDaoFactory.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Project/src/main/java/Date10_20/dao/Factory/UserDaoFactory.java b/Project/src/main/java/Date10_20/dao/Factory/UserDaoFactory.java index cc699fe..c020bca 100644 --- a/Project/src/main/java/Date10_20/dao/Factory/UserDaoFactory.java +++ b/Project/src/main/java/Date10_20/dao/Factory/UserDaoFactory.java @@ -5,17 +5,20 @@ // 즉, 인터페이스로 DB별 연결 설정을 나눠놨는데 여기서 메서드별로 다시 DB별로 나누어 // UserDaoInterface로 해당 DB 연결 설정 값을 보냄 // (4번째 방식) -public class UserDaoFactory { - public static void main(String[] args) { +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; - } +@Configuration +public class UserDaoFactory { + @Bean public UserDaoInterface awsUserDao(){ AWSConnectionMaker awsConnectionMaker = new AWSConnectionMaker(); UserDaoInterface userDao = new UserDaoInterface(awsConnectionMaker); return userDao; } + @Bean public UserDaoInterface localUserDao(){ UserDaoInterface userDao = new UserDaoInterface(new LocalConnectionMaker()); return userDao; From ce1ea0db817c49a2d9a12f94391d7e49628f386f Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 20 Oct 2022 11:00:24 +0900 Subject: [PATCH 195/307] =?UTF-8?q?TDD(spring=20=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_20/Factory/UserDaoInterfaceTest.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Project/src/test/java/Date10_20/Factory/UserDaoInterfaceTest.java b/Project/src/test/java/Date10_20/Factory/UserDaoInterfaceTest.java index c84537c..1bb5217 100644 --- a/Project/src/test/java/Date10_20/Factory/UserDaoInterfaceTest.java +++ b/Project/src/test/java/Date10_20/Factory/UserDaoInterfaceTest.java @@ -5,19 +5,30 @@ import Date10_20.domain.User; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.sql.SQLException; +@ExtendWith(SpringExtension.class) // spring에서 테스트 하기 위한 설정 +@ContextConfiguration(classes = UserDaoFactory.class) class UserDaoInterfaceTest { + @Autowired + ApplicationContext context; // Spring ApplicationContext를 사용하기 위해서는 + // @ExtendWith 과 @ContextConfiguration를 추가해줘야 한다. + @Test void addAndSelect() throws ClassNotFoundException, SQLException { UserDaoInterface userDao = new UserDaoFactory().awsUserDao(); // awsUserDao()가 UserDaoInterface를 반환하기 때문에 다형성 가능 - String id = "2"; - userDao.add(new User(id,"Nunu","123")); + String id = "3"; + userDao.add(new User(id,"Spring","123")); User user = userDao.select(id); - Assertions.assertEquals("Nunu",user.getName()); + Assertions.assertEquals("Spring",user.getName()); } } \ No newline at end of file From 3fbf6689074d0b45b0ea0de47afa7c599de6eb0a Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 20 Oct 2022 23:41:58 +0900 Subject: [PATCH 196/307] TDD(test) --- .../java/Date10_20/Algorithm/stackTest.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Project/src/test/java/Date10_20/Algorithm/stackTest.java diff --git a/Project/src/test/java/Date10_20/Algorithm/stackTest.java b/Project/src/test/java/Date10_20/Algorithm/stackTest.java new file mode 100644 index 0000000..e389773 --- /dev/null +++ b/Project/src/test/java/Date10_20/Algorithm/stackTest.java @@ -0,0 +1,83 @@ +package Date10_20.Algorithm; + + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.EmptyStackException; +import java.util.Stack; + +import static org.junit.jupiter.api.Assertions.*; + +class stackTest { + + @BeforeEach + void setUp() { + // db에서 데이터를 지우는 코드 + // db에서 데이터를 넣는 코드 + System.out.println("before each"); + } + + @Test + @DisplayName("push가 잘되는지") + void push(){ + stack st = new stack(); + st.push(10); + st.push(20); + Integer[] arr = st.getArr(); + + assertEquals(20,arr[1]); + assertEquals(10,arr[0]); + } + + @Test + void pushAndPop(){ + + stack st = new stack(); + st.push(10); + st.push(20); + + assertEquals(20, st.pop()); + assertEquals(10, st.pop()); + // st.pop() 비어 있을땐? + // Exception 예외의 검증 + assertThrows(RuntimeException.class,()->{ + st.pop(); + }); +// st.pop(); + } + + @Test + void isEmpty() { + stack st = new stack(); + assertTrue(st.isEmpty()); + st.push(20); + assertFalse(st.isEmpty()); + st.pop(); + assertTrue(st.isEmpty()); + } + + @Test + void realStack() { + // 자바 스택 구현채 (미리 해놓은거) + Stack st = new Stack<>(); + assertThrows(EmptyStackException.class, ()->{ + st.pop(); + }); +// st.pop(); + + } + + @Test + void peek() { + stack st = new stack(); + // 스택이 비었는데 peek 할 때 + assertThrows(EmptyStackException.class,()->{ + st.peek(); + }); + st.push(10); + int peeked = st.peek(); + assertEquals(10,peeked); + } +} From 1ca9efdf9b4888f8649f97f755c78d154c4ea0f2 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 20 Oct 2022 23:42:14 +0900 Subject: [PATCH 197/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20stack?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/Date10_20/Algorithm/stack.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Project/src/main/java/Date10_20/Algorithm/stack.java diff --git a/Project/src/main/java/Date10_20/Algorithm/stack.java b/Project/src/main/java/Date10_20/Algorithm/stack.java new file mode 100644 index 0000000..b23bcd6 --- /dev/null +++ b/Project/src/main/java/Date10_20/Algorithm/stack.java @@ -0,0 +1,50 @@ +package Date10_20.Algorithm; + + +import java.util.EmptyStackException; + +public class stack { + private Integer[] arr; // 스택 저장하는 공간 + private int top = 0; // 현재 스택 최고점 위치 나타냄 + + public stack() { // 생성자를 통해 배열의 크기를 초기화함 + this.arr = new Integer[10000]; + } + + public stack(int size) { + this.arr = new Integer[10000]; + } + + public Integer[] getArr() { + return arr; + } + + public void push(int value) { + // 10을 넣으면 arr[0] = 10 + this.arr[top++] = value; + } + +// 예외처리 전 +// public int pop() { +// return this.arr[--this.top]; +// } + + public int pop() { + if (this.isEmpty()) { + throw new RuntimeException("스택이 비었습니다."); + } + return this.arr[--this.top]; + } + + public boolean isEmpty() { + boolean isEmpty = this.top == 0; + return isEmpty; + } + + public int peek() { + if (this.isEmpty()) { + throw new EmptyStackException(); + } + return this.arr[this.top - 1]; + } +} From dd7837b49e25b43d590a624b0319a87683469b60 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Fri, 21 Oct 2022 08:45:40 +0900 Subject: [PATCH 198/307] Interface --- .../main/java/Date10_20/dao/Interface/AWSConnectionMaker.java | 1 - .../main/java/Date10_20/dao/Interface/LocalConnectionMaker.java | 1 - .../src/main/java/Date10_20/dao/Interface/UserDaoInterface.java | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Project/src/main/java/Date10_20/dao/Interface/AWSConnectionMaker.java b/Project/src/main/java/Date10_20/dao/Interface/AWSConnectionMaker.java index 8394084..071b794 100644 --- a/Project/src/main/java/Date10_20/dao/Interface/AWSConnectionMaker.java +++ b/Project/src/main/java/Date10_20/dao/Interface/AWSConnectionMaker.java @@ -3,7 +3,6 @@ // AWS DB 연결 // 2번째 방식을 클래스로 따로 빼내어 사용하는 방식 (3번째 방법) // interface 상속 - import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; diff --git a/Project/src/main/java/Date10_20/dao/Interface/LocalConnectionMaker.java b/Project/src/main/java/Date10_20/dao/Interface/LocalConnectionMaker.java index 77846fe..33efe51 100644 --- a/Project/src/main/java/Date10_20/dao/Interface/LocalConnectionMaker.java +++ b/Project/src/main/java/Date10_20/dao/Interface/LocalConnectionMaker.java @@ -2,7 +2,6 @@ // local DB 연결 - import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; diff --git a/Project/src/main/java/Date10_20/dao/Interface/UserDaoInterface.java b/Project/src/main/java/Date10_20/dao/Interface/UserDaoInterface.java index dd01437..0d2281a 100644 --- a/Project/src/main/java/Date10_20/dao/Interface/UserDaoInterface.java +++ b/Project/src/main/java/Date10_20/dao/Interface/UserDaoInterface.java @@ -13,7 +13,7 @@ public class UserDaoInterface { private ConnectionMaker connectionMaker; // interface의 makeConnection()를 가져옴 public UserDaoInterface(){ // 생성자를 통해 AWS DB의 makeConnection()을 오버라이딩하여 사용 this.connectionMaker = new AWSConnectionMaker(); - } + } // 생성자 기본값을 AWS주소로 설정 public UserDaoInterface(ConnectionMaker connectionMaker){ this.connectionMaker = connectionMaker; } From b7fa0535e03258e09679d3f3bb6bc838d245e104 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Fri, 21 Oct 2022 08:45:51 +0900 Subject: [PATCH 199/307] =?UTF-8?q?spring=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/Project/build.gradle b/Project/build.gradle index cc5f37e..c4f3a6c 100644 --- a/Project/build.gradle +++ b/Project/build.gradle @@ -15,6 +15,7 @@ dependencies { implementation 'mysql:mysql-connector-java:8.0.30' implementation 'org.springframework.boot:spring-boot-starter-jdbc:2.7.4' implementation 'org.springframework.boot:spring-boot-starter-test:2.7.4' + implementation 'org.springframework.boot:spring-boot-starter-web:2.7.4' } test { From 54890cd6ce361a35c798e76f1b7dcc165ddd7852 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Fri, 21 Oct 2022 08:46:11 +0900 Subject: [PATCH 200/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20stack=20TDD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/test/java/Date10_20/Algorithm/stackTest.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Project/src/test/java/Date10_20/Algorithm/stackTest.java b/Project/src/test/java/Date10_20/Algorithm/stackTest.java index e389773..3be6c6b 100644 --- a/Project/src/test/java/Date10_20/Algorithm/stackTest.java +++ b/Project/src/test/java/Date10_20/Algorithm/stackTest.java @@ -11,18 +11,17 @@ import static org.junit.jupiter.api.Assertions.*; class stackTest { + stack st = new stack(); - @BeforeEach + @BeforeEach // 무조건 제일 먼저 실행하고 시작함(공통값을 넣을때 주로 사용) void setUp() { - // db에서 데이터를 지우는 코드 - // db에서 데이터를 넣는 코드 + System.out.println("before each"); } @Test @DisplayName("push가 잘되는지") void push(){ - stack st = new stack(); st.push(10); st.push(20); Integer[] arr = st.getArr(); @@ -33,8 +32,6 @@ void push(){ @Test void pushAndPop(){ - - stack st = new stack(); st.push(10); st.push(20); @@ -50,7 +47,6 @@ void pushAndPop(){ @Test void isEmpty() { - stack st = new stack(); assertTrue(st.isEmpty()); st.push(20); assertFalse(st.isEmpty()); From 5d9dcdbd822628953418d5494102fa237c259d63 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Fri, 21 Oct 2022 08:46:27 +0900 Subject: [PATCH 201/307] DAO[Factory] --- .../{UserDaoInterface.java => UserDao.java} | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) rename Project/src/main/java/Date10_20/dao/Factory/{UserDaoInterface.java => UserDao.java} (70%) diff --git a/Project/src/main/java/Date10_20/dao/Factory/UserDaoInterface.java b/Project/src/main/java/Date10_20/dao/Factory/UserDao.java similarity index 70% rename from Project/src/main/java/Date10_20/dao/Factory/UserDaoInterface.java rename to Project/src/main/java/Date10_20/dao/Factory/UserDao.java index 3da91fc..514f2e1 100644 --- a/Project/src/main/java/Date10_20/dao/Factory/UserDaoInterface.java +++ b/Project/src/main/java/Date10_20/dao/Factory/UserDao.java @@ -8,16 +8,39 @@ import java.sql.SQLException; // 중복코드만 따로 빼내서 작성한 코드 (3번째 방식) -public class UserDaoInterface { +public class UserDao { private ConnectionMaker connectionMaker; // interface의 makeConnection()를 가져옴 - public UserDaoInterface(){ // 생성자를 통해 AWS DB의 makeConnection()을 오버라이딩하여 사용 + public UserDao(){ // 생성자를 통해 AWS DB의 makeConnection()을 오버라이딩하여 사용 this.connectionMaker = new AWSConnectionMaker(); } - public UserDaoInterface(ConnectionMaker connectionMaker){ + public UserDao(ConnectionMaker connectionMaker){ this.connectionMaker = connectionMaker; } + + public void deleteAll() throws SQLException, ClassNotFoundException { // DB 모든값 삭제 + Connection conn = connectionMaker.makeConnection(); + PreparedStatement ps = conn.prepareStatement("delete from user "); + ps.executeUpdate(); + ps.close(); + conn.close(); + } + + public int getCount() throws SQLException, ClassNotFoundException { // user테이블의 레코드 개수를 구하기 + Connection conn = connectionMaker.makeConnection(); + PreparedStatement ps = conn.prepareStatement("select count(*) from users "); + ResultSet rs = ps.executeQuery(); + rs.next(); + int count = rs.getInt(1); + + rs.close(); + ps.close(); + conn.close(); + + return count; + } + public void add(User user) throws ClassNotFoundException { try{ @@ -60,10 +83,4 @@ public User select(String id) throws SQLException, ClassNotFoundException { throw new RuntimeException(e); } } - - public static void main(String[] args) throws ClassNotFoundException, SQLException { - UserDaoInterface userDao = new UserDaoInterface(); - userDao.add(new User("7","Ruru","1234qwer")); // user로 값을 받아 DTO에 저장한 후 mysql로 데이터 보냄 - System.out.println(userDao.select("1")); - } } \ No newline at end of file From 802bfa0c6fa98f6422071a25374c590f349e4b33 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Fri, 21 Oct 2022 08:47:07 +0900 Subject: [PATCH 202/307] Factory[Spring bean] --- .../main/java/Date10_20/dao/Factory/UserDaoFactory.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Project/src/main/java/Date10_20/dao/Factory/UserDaoFactory.java b/Project/src/main/java/Date10_20/dao/Factory/UserDaoFactory.java index c020bca..b018620 100644 --- a/Project/src/main/java/Date10_20/dao/Factory/UserDaoFactory.java +++ b/Project/src/main/java/Date10_20/dao/Factory/UserDaoFactory.java @@ -12,15 +12,15 @@ public class UserDaoFactory { @Bean - public UserDaoInterface awsUserDao(){ + public UserDao awsUserDao(){ AWSConnectionMaker awsConnectionMaker = new AWSConnectionMaker(); - UserDaoInterface userDao = new UserDaoInterface(awsConnectionMaker); + UserDao userDao = new UserDao(awsConnectionMaker); return userDao; } @Bean - public UserDaoInterface localUserDao(){ - UserDaoInterface userDao = new UserDaoInterface(new LocalConnectionMaker()); + public UserDao localUserDao(){ + UserDao userDao = new UserDao(new LocalConnectionMaker()); return userDao; } } From 40fc17b5ef980ff2ca6b0720cfa09676e82d5a35 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Fri, 21 Oct 2022 08:47:18 +0900 Subject: [PATCH 203/307] TDD --- ...oConnectionMakerTest.java => UserDaoInterfaceTest.java} | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) rename Project/src/test/java/Date10_20/{UserDaoConnectionMakerTest.java => UserDaoInterfaceTest.java} (72%) diff --git a/Project/src/test/java/Date10_20/UserDaoConnectionMakerTest.java b/Project/src/test/java/Date10_20/UserDaoInterfaceTest.java similarity index 72% rename from Project/src/test/java/Date10_20/UserDaoConnectionMakerTest.java rename to Project/src/test/java/Date10_20/UserDaoInterfaceTest.java index 8144e3c..409c7c5 100644 --- a/Project/src/test/java/Date10_20/UserDaoConnectionMakerTest.java +++ b/Project/src/test/java/Date10_20/UserDaoInterfaceTest.java @@ -1,8 +1,7 @@ package Date10_20; -import Date10_20.dao.Factory.AWSConnectionMaker; -import Date10_20.dao.UserDaoConnectionMaker; +import Date10_20.dao.Interface.UserDaoInterface; import Date10_20.domain.User; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -11,10 +10,10 @@ // 3번째 방식 테스트 -class UserDaoConnectionMakerTest { +class UserDaoTest { @Test void addAndSelect() throws ClassNotFoundException, SQLException { - UserDaoConnectionMaker userDao = new UserDaoConnectionMaker(new AWSConnectionMaker()); + UserDaoInterface userDao = new UserDaoInterface(); String id = "12"; User user = new User(id,"test","1234"); // user 값을 DTO에 저장함 userDao.add(user); From 97438107e50ec984f60fd03d3d3d08b59b842744 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Fri, 21 Oct 2022 10:42:32 +0900 Subject: [PATCH 204/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20replace=EC=82=AC=EC=9A=A9=ED=95=98=EC=97=AC=20=EA=B4=84?= =?UTF-8?q?=ED=98=B8=20=EA=B5=AC=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/Date10_21/Algorithm/bracket.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Project/src/main/java/Date10_21/Algorithm/bracket.java diff --git a/Project/src/main/java/Date10_21/Algorithm/bracket.java b/Project/src/main/java/Date10_21/Algorithm/bracket.java new file mode 100644 index 0000000..57b1fba --- /dev/null +++ b/Project/src/main/java/Date10_21/Algorithm/bracket.java @@ -0,0 +1,17 @@ +package Date10_21.Algorithm; + +// 알고리즘 스택 괄호 +// 스택사용하지 않고 풀어보기 +// 프로그래머스 올바른 괄호문제 +public class bracket { + public boolean result(String s){ + while(s.indexOf("()") >= 0){ // ()를 문자열에서 index 값을 찾음 + // 만약 인덱스 값이 0보다 크면 + s = s.replace("()",""); // ()를 ""으로 바꿈 + // 예시. (()) 일때 () = index 1이므로 while문 동작 + // "" 자리 바꿔서 () 출력후 다시 반복 + } + + return s.length()==0; // s 문자열의 길이가 0이면 ()가 짝수 이므로 True 반환 + } +} From e130bb31572a15ca07e134be05975b5cb67e443f Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Fri, 21 Oct 2022 10:42:49 +0900 Subject: [PATCH 205/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20split,join=20=EC=82=AC=EC=9A=A9=ED=95=98=EC=97=AC=20?= =?UTF-8?q?=EA=B4=84=ED=98=B8=20=EA=B5=AC=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/Date10_21/Algorithm/bracket2.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Project/src/main/java/Date10_21/Algorithm/bracket2.java diff --git a/Project/src/main/java/Date10_21/Algorithm/bracket2.java b/Project/src/main/java/Date10_21/Algorithm/bracket2.java new file mode 100644 index 0000000..08c73a2 --- /dev/null +++ b/Project/src/main/java/Date10_21/Algorithm/bracket2.java @@ -0,0 +1,13 @@ +package Date10_21.Algorithm; + +// split, join 사용하여 풀기 + +public class bracket2{ + public boolean result2(String s){ + while(s.indexOf("()")>= 0){ + String[] splitted = s.split("\\(\\)"); + s = String.join("",splitted); // join 배열을 문자열로 변경 + } + return s.length()==0; + } +} From aa9cad241ce5db6415443c080d49b7edd72ef192 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Fri, 21 Oct 2022 10:43:08 +0900 Subject: [PATCH 206/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20stack=20=EC=82=AC=EC=9A=A9=ED=95=98=EC=97=AC=20=EA=B4=84?= =?UTF-8?q?=ED=98=B8=20=EA=B5=AC=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_21/Algorithm/StackBracket.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Project/src/main/java/Date10_21/Algorithm/StackBracket.java diff --git a/Project/src/main/java/Date10_21/Algorithm/StackBracket.java b/Project/src/main/java/Date10_21/Algorithm/StackBracket.java new file mode 100644 index 0000000..27799cf --- /dev/null +++ b/Project/src/main/java/Date10_21/Algorithm/StackBracket.java @@ -0,0 +1,22 @@ +package Date10_21.Algorithm; + +import java.util.Stack; + +public class StackBracket { + boolean answer(String s){ + Stack stack = new Stack<>(); + + for(int i =0; i Date: Fri, 21 Oct 2022 10:43:27 +0900 Subject: [PATCH 207/307] =?UTF-8?q?TDD=20-=20Stack=20=EA=B4=84=ED=98=B8=20?= =?UTF-8?q?=EA=B5=AC=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date10_21/Algorithm/bracketTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Project/src/test/java/Date10_21/Algorithm/bracketTest.java diff --git a/Project/src/test/java/Date10_21/Algorithm/bracketTest.java b/Project/src/test/java/Date10_21/Algorithm/bracketTest.java new file mode 100644 index 0000000..6a95b4a --- /dev/null +++ b/Project/src/test/java/Date10_21/Algorithm/bracketTest.java @@ -0,0 +1,21 @@ +package Date10_21.Algorithm; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class bracketTest { + + @Test + @DisplayName("괄호가 잘 풀리는지") + void bracket(){ + bracket sb = new bracket(); + assertFalse(sb.result("()())")); + assertFalse(sb.result(")()()(")); + assertTrue(sb.result("()()")); + assertTrue(sb.result("((()()))")); + assertTrue(sb.result("((((((((((()))))))))))")); + assertFalse(sb.result("(()(")); + } +} \ No newline at end of file From 989e4a766820379d20ba57ee8f3822a42cacf000 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Fri, 21 Oct 2022 10:46:08 +0900 Subject: [PATCH 208/307] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 50c7115..94a186c 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,9 @@ - 2022-10-19 : 알고리즘[Stack(1)] + Java/Mysql 연결(리팩토링 : Interface, class, Factory 분리) + spring 연동(spring 시작) -- 2022-10-20 : 알고리즘[Stack(2)] +- 2022-10-20 : 알고리즘[Stack(2)] + + +- 2022-10-21 : 알고리즘[Stack(3)] +
# ⚙️ 기술 스택 From ce0c51cfe892ae5ee612188fc0745d7b4002d17c Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Fri, 21 Oct 2022 13:50:01 +0900 Subject: [PATCH 209/307] =?UTF-8?q?DAO[Factory]=20-=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date10_20/dao/Factory/UserDao.java | 150 +++++++++++++----- 1 file changed, 112 insertions(+), 38 deletions(-) diff --git a/Project/src/main/java/Date10_20/dao/Factory/UserDao.java b/Project/src/main/java/Date10_20/dao/Factory/UserDao.java index 514f2e1..cc8859c 100644 --- a/Project/src/main/java/Date10_20/dao/Factory/UserDao.java +++ b/Project/src/main/java/Date10_20/dao/Factory/UserDao.java @@ -20,67 +20,141 @@ public UserDao(ConnectionMaker connectionMaker){ public void deleteAll() throws SQLException, ClassNotFoundException { // DB 모든값 삭제 - Connection conn = connectionMaker.makeConnection(); - PreparedStatement ps = conn.prepareStatement("delete from user "); - ps.executeUpdate(); - ps.close(); - conn.close(); + Connection conn = null; + PreparedStatement ps = null; + + try { // 예외처리 + conn = connectionMaker.makeConnection(); + ps = conn.prepareStatement("delete from user "); + ps.executeUpdate(); + } catch (SQLException e) { + throw new RuntimeException(e); + }finally { // error 발생해도 실행함 + if(ps != null){ + try { + ps.close(); + } catch (SQLException e) { + } + } + + if(conn != null){ + try { + conn.close(); + } catch (SQLException e) { + } + } + } } public int getCount() throws SQLException, ClassNotFoundException { // user테이블의 레코드 개수를 구하기 - Connection conn = connectionMaker.makeConnection(); - PreparedStatement ps = conn.prepareStatement("select count(*) from users "); - ResultSet rs = ps.executeQuery(); - rs.next(); - int count = rs.getInt(1); - - rs.close(); - ps.close(); - conn.close(); + Connection conn = null; + PreparedStatement ps = null; + ResultSet rs = null; + try { + conn = connectionMaker.makeConnection(); + ps = conn.prepareStatement("select count(*) from users "); + rs = ps.executeQuery(); + rs.next(); + return rs.getInt(1); - return count; + } catch (SQLException e) { + throw new RuntimeException(e); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } finally { + if(rs != null) { + try { + rs.close(); + } catch (SQLException e) { + } + } + if(ps != null){ + try { + ps.close(); + } catch (SQLException e) { + } + } + + if(conn != null){ + try { + conn.close(); + } catch (SQLException e) { + } + } + } } - public void add(User user) throws ClassNotFoundException { - - try{ + public void add(User user) throws ClassNotFoundException, SQLException { // db 연결(호스트,이름,비밀번호) - Connection conn = connectionMaker.makeConnection(); // 설정들을 모아둔 메서드 호출 - - PreparedStatement ps = conn.prepareStatement("INSERT INTO users(id,name,password) VALUES(?,?,?)"); + Connection conn = null; // 설정들을 모아둔 메서드 호출 + PreparedStatement ps = null; + try { + conn = connectionMaker.makeConnection(); + + ps = conn.prepareStatement("INSERT INTO users(id,name,password) VALUES(?,?,?)"); ps.setString(1,user.getId()); // mysql 테이블로 값 insert ps.setString(2,user.getName()); ps.setString(3,user.getPassword()); - ps.executeUpdate(); // ctrl + enter 즉, mysql에서 번개모양을 눌러 최신화 한다는 느낌 - ps.close(); - conn.close(); - System.out.println("데이터가 insert 됬습니다."); - - }catch (SQLException e){ + } catch (SQLException e) { throw new RuntimeException(e); + }finally { + if(ps != null){ + try { + ps.close(); + } catch (SQLException e) { + } + } + + if(conn != null){ + try { + conn.close(); + } catch (SQLException e) { + } + } + System.out.println("데이터가 insert 됬습니다."); } - } public User select(String id) throws SQLException, ClassNotFoundException { + Connection conn = null; + PreparedStatement ps = null; + ResultSet rs = null; // 쿼리문을 저장함 insert문과 달리 excuteQuery() 사용 + User user = null; try { - Connection conn = connectionMaker.makeConnection(); - PreparedStatement ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); + conn = connectionMaker.makeConnection(); + ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); ps.setString(1, id); // id는 get(String id)로 받은 id - ResultSet rs = ps.executeQuery(); // 쿼리문을 저장함 insert문과 달리 excuteQuery() 사용 + rs = ps.executeQuery(); // rs에는 쿼리 실행 결과가 담겨져 있다. (select * from users where id = 1;) rs.next(); - // User 생성자를 통해 쿼리문에 id값을 넣어 찾은 id, name,password 값을 저장한다. - User user = new User(rs.getString("id"), rs.getString("name"), rs.getString("password")); - rs.close(); - ps.close(); - conn.close(); - return user; - }catch (SQLException e){ + return new User(rs.getString("id"), rs.getString("name"), rs.getString("password")); + } + catch (SQLException e) { throw new RuntimeException(e); } + finally { + if(rs != null) { + try { + rs.close(); + } catch (SQLException e) { + } + } + if(ps != null){ + try { + ps.close(); + } catch (SQLException e) { + } + } + + if(conn != null){ + try { + conn.close(); + } catch (SQLException e) { + } + } + } } } \ No newline at end of file From f52c7819ee63470dc1c00f301542a9cb21d46b48 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Fri, 21 Oct 2022 13:50:28 +0900 Subject: [PATCH 210/307] TDD - Spring test --- .../Factory/UserDaoInterfaceTest.java | 34 ------------ .../java/Date10_20/Factory/UserDaoTest.java | 53 +++++++++++++++++++ 2 files changed, 53 insertions(+), 34 deletions(-) delete mode 100644 Project/src/test/java/Date10_20/Factory/UserDaoInterfaceTest.java create mode 100644 Project/src/test/java/Date10_20/Factory/UserDaoTest.java diff --git a/Project/src/test/java/Date10_20/Factory/UserDaoInterfaceTest.java b/Project/src/test/java/Date10_20/Factory/UserDaoInterfaceTest.java deleted file mode 100644 index 1bb5217..0000000 --- a/Project/src/test/java/Date10_20/Factory/UserDaoInterfaceTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package Date10_20.Factory; - -import Date10_20.dao.Factory.UserDaoFactory; -import Date10_20.dao.Factory.UserDaoInterface; -import Date10_20.domain.User; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import java.sql.SQLException; - -@ExtendWith(SpringExtension.class) // spring에서 테스트 하기 위한 설정 -@ContextConfiguration(classes = UserDaoFactory.class) -class UserDaoInterfaceTest { - - @Autowired - ApplicationContext context; // Spring ApplicationContext를 사용하기 위해서는 - // @ExtendWith 과 @ContextConfiguration를 추가해줘야 한다. - - @Test - void addAndSelect() throws ClassNotFoundException, SQLException { - UserDaoInterface userDao = new UserDaoFactory().awsUserDao(); - // awsUserDao()가 UserDaoInterface를 반환하기 때문에 다형성 가능 - String id = "3"; - userDao.add(new User(id,"Spring","123")); - - User user = userDao.select(id); - Assertions.assertEquals("Spring",user.getName()); - } -} \ No newline at end of file diff --git a/Project/src/test/java/Date10_20/Factory/UserDaoTest.java b/Project/src/test/java/Date10_20/Factory/UserDaoTest.java new file mode 100644 index 0000000..9659f1e --- /dev/null +++ b/Project/src/test/java/Date10_20/Factory/UserDaoTest.java @@ -0,0 +1,53 @@ +package Date10_20.Factory; + +import Date10_20.dao.Factory.UserDaoFactory; +import Date10_20.dao.Factory.UserDao; +import Date10_20.domain.User; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import java.sql.SQLException; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@ExtendWith(SpringExtension.class) // spring에서 테스트 하기 위한 설정 +@ContextConfiguration(classes = UserDaoFactory.class) +class UserDaoTest { + // 싱글톤을 위해 Autowired 사용 + @Autowired // 새로운 객체를 사용하지 않고 이전에 사용했던 객체의 주소를 그대로 사용한다는 설정 + // new 객체 생성을 한번만 사용함(고정값) + ApplicationContext context; // Spring ApplicationContext를 사용하기 위해서는 + // @ExtendWith 과 @ContextConfiguration를 추가해줘야 한다. + + @Test + void addAndSelect() throws ClassNotFoundException, SQLException { + User user1 = new User("1","홍길동","1234"); + User user2 = new User("2","이순신","4567"); + User user3 = new User("3","세종","7896"); + + UserDao userDao = context.getBean("awsUserDao", UserDao.class); // bean 파일에서 awsUserDao 메서드를 가져온다 + // UserDao userDao1 = context.getBean("awsUserDao",UserDao.class); userDao와 같은 객체를 사용함 + + userDao.deleteAll(); + Assertions.assertThat(0).isEqualTo(userDao.getCount()); + + String id = "3"; + userDao.add(user1); + Assertions.assertThat(1).isEqualTo(userDao.getCount()); + + User user = userDao.select(id); + + Assertions.assertThat("Spring").isEqualTo(user.getName()); + // assertEquals("Spring",user.getName()); + } + + @Test + void count(){ + + } +} \ No newline at end of file From 3c171b56ab64e664efe5831856e9fe40d8d1700c Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Fri, 21 Oct 2022 14:11:20 +0900 Subject: [PATCH 211/307] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 94a186c..556f7a1 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ - 2022-10-19 : 알고리즘[Stack(1)] + Java/Mysql 연결(리팩토링 : Interface, class, Factory 분리) + spring 연동(spring 시작) -- 2022-10-20 : 알고리즘[Stack(2)] + +- 2022-10-20 : 알고리즘[Stack(2)] + Spring bean 설정 + 예외 처리 + Spring TDD - 2022-10-21 : 알고리즘[Stack(3)] +
From c91d95b8e3d927f3cb2a364d948afd612a94171e Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Sat, 22 Oct 2022 19:48:34 +0900 Subject: [PATCH 212/307] Update stack.java --- Project/src/main/java/Date10_20/Algorithm/stack.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Project/src/main/java/Date10_20/Algorithm/stack.java b/Project/src/main/java/Date10_20/Algorithm/stack.java index b23bcd6..1f6e592 100644 --- a/Project/src/main/java/Date10_20/Algorithm/stack.java +++ b/Project/src/main/java/Date10_20/Algorithm/stack.java @@ -48,3 +48,4 @@ public int peek() { return this.arr[this.top - 1]; } } + From d963402ebeb0e8d28d729f5d3e5ed36a43628283 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Sat, 22 Oct 2022 23:18:13 +0900 Subject: [PATCH 213/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20TDD=20Stack?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/src/test/java/Date10_20/Algorithm/stackTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Project/src/test/java/Date10_20/Algorithm/stackTest.java b/Project/src/test/java/Date10_20/Algorithm/stackTest.java index 3be6c6b..6928263 100644 --- a/Project/src/test/java/Date10_20/Algorithm/stackTest.java +++ b/Project/src/test/java/Date10_20/Algorithm/stackTest.java @@ -14,8 +14,7 @@ class stackTest { stack st = new stack(); @BeforeEach // 무조건 제일 먼저 실행하고 시작함(공통값을 넣을때 주로 사용) - void setUp() { - + void setUp() { // 각 테스트가 실행되기 전에 실행되어 테스트별 구분함 System.out.println("before each"); } From 574d71f82ca83c7be8c85ca0099a0fc84d31df43 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Sat, 22 Oct 2022 23:18:48 +0900 Subject: [PATCH 214/307] TDD [Spring - Factory] --- .../java/Date10_20/Factory/UserDaoTest.java | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/Project/src/test/java/Date10_20/Factory/UserDaoTest.java b/Project/src/test/java/Date10_20/Factory/UserDaoTest.java index 9659f1e..509bb18 100644 --- a/Project/src/test/java/Date10_20/Factory/UserDaoTest.java +++ b/Project/src/test/java/Date10_20/Factory/UserDaoTest.java @@ -4,16 +4,19 @@ import Date10_20.dao.Factory.UserDao; import Date10_20.domain.User; import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; import java.sql.SQLException; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; @ExtendWith(SpringExtension.class) // spring에서 테스트 하기 위한 설정 @ContextConfiguration(classes = UserDaoFactory.class) @@ -23,16 +26,22 @@ class UserDaoTest { // new 객체 생성을 한번만 사용함(고정값) ApplicationContext context; // Spring ApplicationContext를 사용하기 위해서는 // @ExtendWith 과 @ContextConfiguration를 추가해줘야 한다. - + UserDao userDao; + User user1; + User user2; + User user3; + + @BeforeEach + void setUp(){ // 각각의 테스트 시작전 필수로 동작하는 부분 + userDao = context.getBean("awsUserDao", UserDao.class); + user1 = new User("1","홍길동","1234"); + user2 = new User("2","이순신","4567"); + user3 = new User("3","세종","7896"); + } @Test void addAndSelect() throws ClassNotFoundException, SQLException { - User user1 = new User("1","홍길동","1234"); - User user2 = new User("2","이순신","4567"); - User user3 = new User("3","세종","7896"); - UserDao userDao = context.getBean("awsUserDao", UserDao.class); // bean 파일에서 awsUserDao 메서드를 가져온다 - // UserDao userDao1 = context.getBean("awsUserDao",UserDao.class); userDao와 같은 객체를 사용함 - + // .deleteAll() 오류 검증 userDao.deleteAll(); Assertions.assertThat(0).isEqualTo(userDao.getCount()); @@ -45,9 +54,26 @@ void addAndSelect() throws ClassNotFoundException, SQLException { Assertions.assertThat("Spring").isEqualTo(user.getName()); // assertEquals("Spring",user.getName()); } - @Test - void count(){ + //.count test만들기 + void count() throws SQLException, ClassNotFoundException { + + UserDao userDao = context.getBean("AwsUserDao", UserDao.class); + //.deleteAll() 오류 검증 + userDao.deleteAll(); + assertEquals(0, userDao.getCount()); + userDao.add(user1); + assertEquals(1, userDao.getCount()); + userDao.add(user2); + assertEquals(2, userDao.getCount()); + userDao.add(user3); + assertEquals(3, userDao.getCount()); + } + @Test + void findById() { + assertThrows(EmptyResultDataAccessException.class, ()-> { + userDao.select("30"); // 데이터가 없을때 ResultSet이 빈 경우 null로 오류가 난다. + }); } } \ No newline at end of file From 85dd110fac795c566d8142784b3c017b177bc2ef Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Sat, 22 Oct 2022 23:19:14 +0900 Subject: [PATCH 215/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20TDD-Stack?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_21/Algorithm/StackSolutionTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Project/src/test/java/Date10_21/Algorithm/StackSolutionTest.java diff --git a/Project/src/test/java/Date10_21/Algorithm/StackSolutionTest.java b/Project/src/test/java/Date10_21/Algorithm/StackSolutionTest.java new file mode 100644 index 0000000..bd42529 --- /dev/null +++ b/Project/src/test/java/Date10_21/Algorithm/StackSolutionTest.java @@ -0,0 +1,17 @@ +package Date10_21.Algorithm; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class StackSolutionTest { + + @Test + @DisplayName("괄호 구분") + void bracket(){ + StackSolution s = new StackSolution(); + assertTrue(s.solution("{}()[](({}))")); + assertFalse(s.solution("{}()[](({))")); + } +} \ No newline at end of file From b5dff2ee1c231662dac6ba365c5ffc9257546f72 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Sun, 23 Oct 2022 14:01:40 +0900 Subject: [PATCH 216/307] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 556f7a1..fb4322d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ - 2022-10-07 : Project(대용량데이터처리) - 2022-10-11 : Aws + docker + Mysql 연결 - + - 2022-10-12 : 알고리즘[max,min 구하기] + 대용량 데이터 처리 - 2022-10-13 : 알고리즘[버블정렬] + 대용량 데이터 처리(Mysql에 파일로 데이터 삽입) From 7cfa5d67460de8c4059d13e9e078e85ba6e00f4f Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Sun, 23 Oct 2022 23:30:01 +0900 Subject: [PATCH 217/307] =?UTF-8?q?AddStrategy(=EC=BF=BC=EB=A6=AC=EB=AC=B8?= =?UTF-8?q?=20interface=EB=A1=9C=20=EA=B5=AC=EB=B6=84)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date10_21/Factory/AddStrategy.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Project/src/main/java/Date10_21/Factory/AddStrategy.java diff --git a/Project/src/main/java/Date10_21/Factory/AddStrategy.java b/Project/src/main/java/Date10_21/Factory/AddStrategy.java new file mode 100644 index 0000000..8bff2fc --- /dev/null +++ b/Project/src/main/java/Date10_21/Factory/AddStrategy.java @@ -0,0 +1,26 @@ +package Date10_21.Factory; + +import Date10_21.domain.User; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; + +public class AddStrategy implements StatementStrategy{ + + private User user; + + public AddStrategy(User user){ + this.user =user; + } + + @Override + public PreparedStatement makepreparedStatement(Connection connection) throws SQLException { + PreparedStatement ps = connection.prepareStatement("INSERT INTO users(id,name,password) VALUES(?,?,?)"); + ps.setString(1,user.getId()); // mysql 테이블로 값 insert + ps.setString(2,user.getName()); + ps.setString(3,user.getPassword()); + + return ps; + } +} From ef31817f3c9f4f51d026319f62e4888535205565 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Sun, 23 Oct 2022 23:30:14 +0900 Subject: [PATCH 218/307] =?UTF-8?q?DeleteAllStrategy(=EC=BF=BC=EB=A6=AC?= =?UTF-8?q?=EB=AC=B8=20interface=EB=A1=9C=20=EA=B5=AC=EB=B6=84)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_21/Factory/DeleteAllStrategy.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Project/src/main/java/Date10_21/Factory/DeleteAllStrategy.java diff --git a/Project/src/main/java/Date10_21/Factory/DeleteAllStrategy.java b/Project/src/main/java/Date10_21/Factory/DeleteAllStrategy.java new file mode 100644 index 0000000..be2dca1 --- /dev/null +++ b/Project/src/main/java/Date10_21/Factory/DeleteAllStrategy.java @@ -0,0 +1,17 @@ +package Date10_21.Factory; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; + + +// Delete 쿼리문 클래스 +public class DeleteAllStrategy implements StatementStrategy{ + + @Override + public PreparedStatement makepreparedStatement(Connection connection) throws SQLException { + return connection.prepareStatement("delete from users"); + } +} + + From 45d8d53e047a525e660668f27d2fdaeafcb5c60f Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Sun, 23 Oct 2022 23:31:33 +0900 Subject: [PATCH 219/307] =?UTF-8?q?Aws=20=EB=94=94=EB=B9=84=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EA=B0=92=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_21/Factory/AWSConnectionMaker.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Project/src/main/java/Date10_21/Factory/AWSConnectionMaker.java diff --git a/Project/src/main/java/Date10_21/Factory/AWSConnectionMaker.java b/Project/src/main/java/Date10_21/Factory/AWSConnectionMaker.java new file mode 100644 index 0000000..833c3b2 --- /dev/null +++ b/Project/src/main/java/Date10_21/Factory/AWSConnectionMaker.java @@ -0,0 +1,24 @@ +package Date10_21.Factory; + +// AWS DB 연결 +// 2번째 방식을 클래스로 따로 빼내어 사용하는 방식 (3번째 방법) +// interface 상속 + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Map; + +public class AWSConnectionMaker implements ConnectionMaker { + @Override + public Connection makeConnection() throws SQLException, ClassNotFoundException { + Map env = System.getenv(); // 환경변수를 사용하여 + String dbHost = env.get("DB_HOST"); + String dbUser = env.get("DB_USER"); + String dbPassword = env.get("DB_PASSWORD"); + + Class.forName("com.mysql.cj.jdbc.Driver"); + Connection conn = DriverManager.getConnection(dbHost, dbUser, dbPassword); + return conn; + } +} From 096e1f2537a4c7acbcf3b5a1fd96b2bec883dd02 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Sun, 23 Oct 2022 23:32:54 +0900 Subject: [PATCH 220/307] =?UTF-8?q?=EA=B0=81=20DB=EB=B3=84=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=EC=9D=84=20=EA=B5=AC=EB=B6=84=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20=EC=9D=B8=ED=84=B0=ED=8E=98=EC=8B=9C?= =?UTF-8?q?=EC=9C=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/Date10_21/Factory/ConnectionMaker.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Project/src/main/java/Date10_21/Factory/ConnectionMaker.java diff --git a/Project/src/main/java/Date10_21/Factory/ConnectionMaker.java b/Project/src/main/java/Date10_21/Factory/ConnectionMaker.java new file mode 100644 index 0000000..dd28402 --- /dev/null +++ b/Project/src/main/java/Date10_21/Factory/ConnectionMaker.java @@ -0,0 +1,8 @@ +package Date10_21.Factory; + +import java.sql.Connection; +import java.sql.SQLException; + +public interface ConnectionMaker { // makeConnection을 각 DB에 맞게 사용할 수 있도록 불러오기 위한 interface + Connection makeConnection() throws SQLException, ClassNotFoundException; +} From 70f3574e9a4b692161703f95752ad41a848f574d Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Sun, 23 Oct 2022 23:33:26 +0900 Subject: [PATCH 221/307] =?UTF-8?q?TDD(=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Algorithm/Factory/JdbcUserDaoTest.java | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 Project/src/test/java/Date10_21/Algorithm/Factory/JdbcUserDaoTest.java diff --git a/Project/src/test/java/Date10_21/Algorithm/Factory/JdbcUserDaoTest.java b/Project/src/test/java/Date10_21/Algorithm/Factory/JdbcUserDaoTest.java new file mode 100644 index 0000000..b0dab4b --- /dev/null +++ b/Project/src/test/java/Date10_21/Algorithm/Factory/JdbcUserDaoTest.java @@ -0,0 +1,88 @@ +package Date10_21.Algorithm.Factory; + +import Date10_20.dao.Factory.UserDao; +import Date10_20.dao.Factory.UserDaoFactory; +import Date10_20.domain.User; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.dao.EmptyResultDataAccessException; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import java.sql.SQLException; + +import static org.junit.jupiter.api.Assertions.*; + +@ExtendWith(SpringExtension.class) // spring에서 테스트 하기 위한 설정 +@ContextConfiguration(classes = UserDaoFactory.class) +class JdbcUserDaoTest { + // 싱글톤을 위해 Autowired 사용 + @Autowired // 새로운 객체를 사용하지 않고 이전에 사용했던 객체의 주소를 그대로 사용한다는 설정 + // new 객체 생성을 한번만 사용함(고정값) + ApplicationContext context; // Spring ApplicationContext를 사용하기 위해서는 + // @ExtendWith 과 @ContextConfiguration를 추가해줘야 한다. + Date10_20.dao.Factory.UserDao userDao; + User user1; + User user2; + User user3; + + @BeforeEach + void setUp(){ // 각각의 테스트 시작전 필수로 동작하는 부분 + userDao = context.getBean("awsUserDao", Date10_20.dao.Factory.UserDao.class); + user1 = new User("1","홍길동","1234"); + user2 = new User("2","이순신","4567"); + user3 = new User("3","세종","7896"); + System.out.println("Before Each"); + } + @Test + @DisplayName("insert/select 테스트") + void addAndSelect() throws ClassNotFoundException, SQLException { + + // .deleteAll() 오류 검증 + userDao.deleteAll(); + Assertions.assertThat(0).isEqualTo(userDao.getCount()); + + String id = "3"; + userDao.add(user3); + Assertions.assertThat(1).isEqualTo(userDao.getCount()); + + User user = userDao.select(id); + + Assertions.assertThat("세종").isEqualTo(user.getName()); + // assertEquals("Spring",user.getName()); + } + @Test + //.count test만들기 + @DisplayName("count 테스트") + void count() throws SQLException, ClassNotFoundException { + + Date10_20.dao.Factory.UserDao userDao = context.getBean("awsUserDao", UserDao.class); + //.deleteAll() 오류 검증 + userDao.deleteAll(); + assertEquals(0, userDao.getCount()); + + userDao.add(user1); + assertEquals(1, userDao.getCount()); + userDao.add(user2); + assertEquals(2, userDao.getCount()); + userDao.add(user3); + assertEquals(3, userDao.getCount()); + } + + +/* @Test + void findById() { + assertThrows(EmptyResultDataAccessException.class, () -> { + userDao.select("1"); + }); + } + + */ + + +} \ No newline at end of file From e57af6d8df87c2edc050b575e5a3bd92fe9e3652 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Sun, 23 Oct 2022 23:33:44 +0900 Subject: [PATCH 222/307] =?UTF-8?q?=EB=A1=9C=EC=BB=AC=20DB=20=EC=A3=BC?= =?UTF-8?q?=EC=86=8C=20=EC=84=A4=EC=A0=95=20=EA=B0=92=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Factory/LocalConnectionMaker.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Project/src/main/java/Date10_21/Factory/LocalConnectionMaker.java diff --git a/Project/src/main/java/Date10_21/Factory/LocalConnectionMaker.java b/Project/src/main/java/Date10_21/Factory/LocalConnectionMaker.java new file mode 100644 index 0000000..8083788 --- /dev/null +++ b/Project/src/main/java/Date10_21/Factory/LocalConnectionMaker.java @@ -0,0 +1,18 @@ +package Date10_21.Factory; + + +// local DB 연결 + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + + +public class LocalConnectionMaker implements ConnectionMaker { + @Override + public Connection makeConnection() throws SQLException { + Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/likelion-db","root","password"); + + return conn; + } +} \ No newline at end of file From a9b6e1b5ce326b9a3ab4b658019d44fd09f87576 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Sun, 23 Oct 2022 23:34:16 +0900 Subject: [PATCH 223/307] =?UTF-8?q?=EC=BF=BC=EB=A6=AC=EB=B3=84=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EA=B5=AC=EB=B6=84=EC=9D=84=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date10_21/Factory/StatementStrategy.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Project/src/main/java/Date10_21/Factory/StatementStrategy.java diff --git a/Project/src/main/java/Date10_21/Factory/StatementStrategy.java b/Project/src/main/java/Date10_21/Factory/StatementStrategy.java new file mode 100644 index 0000000..a6562cf --- /dev/null +++ b/Project/src/main/java/Date10_21/Factory/StatementStrategy.java @@ -0,0 +1,11 @@ +package Date10_21.Factory; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; + +// 쿼리문을 DAO 클래스에 작성하지 않고 따로 interface를 통해 각자 별도 클래스 생성함 +public interface StatementStrategy { + PreparedStatement makepreparedStatement(Connection connection) throws SQLException; + +} From 08beffe63b7d8cdcf579c5828e95b71d11a36017 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Sun, 23 Oct 2022 23:34:25 +0900 Subject: [PATCH 224/307] DTO --- .../src/main/java/Date10_21/domain/User.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Project/src/main/java/Date10_21/domain/User.java diff --git a/Project/src/main/java/Date10_21/domain/User.java b/Project/src/main/java/Date10_21/domain/User.java new file mode 100644 index 0000000..36303d4 --- /dev/null +++ b/Project/src/main/java/Date10_21/domain/User.java @@ -0,0 +1,32 @@ +package Date10_21.domain; + +public class User { + private String id; + private String name; + private String password; + + public User() { + } + + public User(String id, String name, String password) { + this.id = id; + this.name = name; + this.password = password; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getPassword() { + return password; + } + + public String toString(){ + return "id = "+this.id + " name = "+this.name+" password = "+this.password; + } +} From a99a10247e9d5c0bd3f0015a3fd37063aa432773 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Sun, 23 Oct 2022 23:34:50 +0900 Subject: [PATCH 225/307] DAO --- Project/src/main/java/Date10_20/dao/Factory/UserDao.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Project/src/main/java/Date10_20/dao/Factory/UserDao.java b/Project/src/main/java/Date10_20/dao/Factory/UserDao.java index cc8859c..e15acc9 100644 --- a/Project/src/main/java/Date10_20/dao/Factory/UserDao.java +++ b/Project/src/main/java/Date10_20/dao/Factory/UserDao.java @@ -14,7 +14,7 @@ public class UserDao { public UserDao(){ // 생성자를 통해 AWS DB의 makeConnection()을 오버라이딩하여 사용 this.connectionMaker = new AWSConnectionMaker(); } - public UserDao(ConnectionMaker connectionMaker){ + public UserDao(ConnectionMaker connectionMaker){ this.connectionMaker = connectionMaker; } @@ -25,7 +25,7 @@ public void deleteAll() throws SQLException, ClassNotFoundException { // D try { // 예외처리 conn = connectionMaker.makeConnection(); - ps = conn.prepareStatement("delete from user "); + ps = conn.prepareStatement("delete from users "); ps.executeUpdate(); } catch (SQLException e) { throw new RuntimeException(e); From 830a3620c0b78dcd0fca1b2e57576d6fb831214f Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Sun, 23 Oct 2022 23:35:22 +0900 Subject: [PATCH 226/307] DAO - Strategy(JDBC) --- .../main/java/Date10_21/Factory/UserDao.java | 140 ++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 Project/src/main/java/Date10_21/Factory/UserDao.java diff --git a/Project/src/main/java/Date10_21/Factory/UserDao.java b/Project/src/main/java/Date10_21/Factory/UserDao.java new file mode 100644 index 0000000..dc8a3c5 --- /dev/null +++ b/Project/src/main/java/Date10_21/Factory/UserDao.java @@ -0,0 +1,140 @@ +package Date10_21.Factory; + +import Date10_21.domain.User; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +// 중복코드만 따로 빼내서 작성한 코드 (3번째 방식) +public class UserDao { + + private ConnectionMaker connectionMaker; // interface의 makeConnection()를 가져옴 + public UserDao(){ // 생성자를 통해 AWS DB의 makeConnection()을 오버라이딩하여 사용 + this.connectionMaker = new AWSConnectionMaker(); + } + public UserDao(ConnectionMaker connectionMaker){ + this.connectionMaker = connectionMaker; + } + + // add,delete등 sql문을 사용하는 메서드들은 쿼리문(insert, delete,select 등)만 다르지 구조는 모두 같다 + // 따라서 이러한 중복되는 구조들을 하나의 메서드로 정의한 후 호출하여 사용함 + public void jdbcContextWithStatementStatementstrategy(StatementStrategy st){ + Connection conn = null; + PreparedStatement ps = null; + + try { // 예외처리 + conn = connectionMaker.makeConnection(); + ps = new DeleteAllStrategy().makepreparedStatement(conn); + ps.executeUpdate(); + } catch (SQLException | ClassNotFoundException e) { + throw new RuntimeException(e); + }finally { // error 발생해도 실행함 + if(ps != null){ + try { + ps.close(); + } catch (SQLException e) { + } + } + + if(conn != null){ + try { + conn.close(); + } catch (SQLException e) { + } + } + } + } + + public void deleteAll() throws SQLException, ClassNotFoundException { // DB 모든값 삭제 + jdbcContextWithStatementStatementstrategy(new DeleteAllStrategy()); + } + + public int getCount() throws SQLException, ClassNotFoundException { // user테이블의 레코드 개수를 구하기 + Connection conn = null; + PreparedStatement ps = null; + ResultSet rs = null; + try { + conn = connectionMaker.makeConnection(); + ps = conn.prepareStatement("select count(*) from users "); + rs = ps.executeQuery(); + rs.next(); + return rs.getInt(1); + + } catch (SQLException e) { + throw new RuntimeException(e); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } finally { + if(rs != null) { + try { + rs.close(); + } catch (SQLException e) { + } + } + if(ps != null){ + try { + ps.close(); + } catch (SQLException e) { + } + } + + if(conn != null){ + try { + conn.close(); + } catch (SQLException e) { + } + } + } + } + + public void add(User user) throws ClassNotFoundException, SQLException { + AddStrategy addStrategy = new AddStrategy(user); // User DTO에 저장되어 있는 값 가져옴 + jdbcContextWithStatementStatementstrategy(addStrategy); // add 쿼리문과 추가할 값 가져와서 대입 + + System.out.println("데이터가 insert 됬습니다"); + } + + public User select(String id) throws SQLException, ClassNotFoundException { + + Connection conn = null; + PreparedStatement ps = null; + ResultSet rs = null; // 쿼리문을 저장함 insert문과 달리 excuteQuery() 사용 + User user = null; + try { + conn = connectionMaker.makeConnection(); + ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); + ps.setString(1, id); // id는 get(String id)로 받은 id + rs = ps.executeQuery(); + // rs에는 쿼리 실행 결과가 담겨져 있다. (select * from users where id = 1;) + rs.next(); + // User 생성자를 통해 쿼리문에 id값을 넣어 찾은 id, name,password 값을 저장한다. + return new User(rs.getString("id"), rs.getString("name"), rs.getString("password")); + } + catch (SQLException e) { + throw new RuntimeException(e); + } + finally { + if(rs != null) { + try { + rs.close(); + } catch (SQLException e) { + } + } + if(ps != null){ + try { + ps.close(); + } catch (SQLException e) { + } + } + + if(conn != null){ + try { + conn.close(); + } catch (SQLException e) { + } + } + } + } +} \ No newline at end of file From f42224b5604d77b88bf971857fbeabdf393256ca Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Sun, 23 Oct 2022 23:35:34 +0900 Subject: [PATCH 227/307] Bean File --- .../Date10_21/Factory/UserDaoFactory.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Project/src/main/java/Date10_21/Factory/UserDaoFactory.java diff --git a/Project/src/main/java/Date10_21/Factory/UserDaoFactory.java b/Project/src/main/java/Date10_21/Factory/UserDaoFactory.java new file mode 100644 index 0000000..65a0358 --- /dev/null +++ b/Project/src/main/java/Date10_21/Factory/UserDaoFactory.java @@ -0,0 +1,26 @@ +package Date10_21.Factory; + + +// 인터페이스로 받은 것을 어떤것을 UserDaoInterface로 넘겨줄것인지 설정 +// 즉, 인터페이스로 DB별 연결 설정을 나눠놨는데 여기서 메서드별로 다시 DB별로 나누어 +// UserDaoInterface로 해당 DB 연결 설정 값을 보냄 +// (4번째 방식) +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class UserDaoFactory { + + @Bean + public UserDao awsUserDao(){ + AWSConnectionMaker awsConnectionMaker = new AWSConnectionMaker(); + UserDao userDao = new UserDao(awsConnectionMaker); + return userDao; + } + + @Bean + public UserDao localUserDao(){ + UserDao userDao = new UserDao(new LocalConnectionMaker()); + return userDao; + } +} From 62d888ea642b1505dff7b1bba03a4d57d32dd272 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Sun, 23 Oct 2022 23:35:58 +0900 Subject: [PATCH 228/307] TDD --- .../test/java/Date10_20/Factory/UserDaoTest.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Project/src/test/java/Date10_20/Factory/UserDaoTest.java b/Project/src/test/java/Date10_20/Factory/UserDaoTest.java index 509bb18..7341b94 100644 --- a/Project/src/test/java/Date10_20/Factory/UserDaoTest.java +++ b/Project/src/test/java/Date10_20/Factory/UserDaoTest.java @@ -5,6 +5,7 @@ import Date10_20.domain.User; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -20,7 +21,7 @@ @ExtendWith(SpringExtension.class) // spring에서 테스트 하기 위한 설정 @ContextConfiguration(classes = UserDaoFactory.class) -class UserDaoTest { +class UserDaoFactoryTest { // 싱글톤을 위해 Autowired 사용 @Autowired // 새로운 객체를 사용하지 않고 이전에 사용했던 객체의 주소를 그대로 사용한다는 설정 // new 객체 생성을 한번만 사용함(고정값) @@ -46,19 +47,19 @@ void addAndSelect() throws ClassNotFoundException, SQLException { Assertions.assertThat(0).isEqualTo(userDao.getCount()); String id = "3"; - userDao.add(user1); + userDao.add(user3); Assertions.assertThat(1).isEqualTo(userDao.getCount()); User user = userDao.select(id); - Assertions.assertThat("Spring").isEqualTo(user.getName()); + Assertions.assertThat("세종").isEqualTo(user.getName()); // assertEquals("Spring",user.getName()); } @Test //.count test만들기 void count() throws SQLException, ClassNotFoundException { - UserDao userDao = context.getBean("AwsUserDao", UserDao.class); + UserDao userDao = context.getBean("awsUserDao", UserDao.class); //.deleteAll() 오류 검증 userDao.deleteAll(); assertEquals(0, userDao.getCount()); @@ -70,10 +71,15 @@ void count() throws SQLException, ClassNotFoundException { userDao.add(user3); assertEquals(3, userDao.getCount()); } + + @Test + @DisplayName("") void findById() { assertThrows(EmptyResultDataAccessException.class, ()-> { userDao.select("30"); // 데이터가 없을때 ResultSet이 빈 경우 null로 오류가 난다. }); } + + } \ No newline at end of file From 9e853629b322c9444ee2e1284d73b840ea5227a7 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Mon, 24 Oct 2022 09:17:31 +0900 Subject: [PATCH 229/307] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fb4322d..4c5fc05 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ - 2022-10-20 : 알고리즘[Stack(2)] + Spring bean 설정 + 예외 처리 + Spring TDD -- 2022-10-21 : 알고리즘[Stack(3)] + +- 2022-10-21 : 알고리즘[Stack(3)] + Spring Strategy + Jdbc
# ⚙️ 기술 스택 From e2f4e609ff71cec92e8ad708c9390427ac6b985c Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Mon, 24 Oct 2022 09:19:02 +0900 Subject: [PATCH 230/307] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4c5fc05..67f7874 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ - 2022-10-20 : 알고리즘[Stack(2)] + Spring bean 설정 + 예외 처리 + Spring TDD - 2022-10-21 : 알고리즘[Stack(3)] + Spring Strategy + Jdbc + +- 2022-10-24 : 알고리즘[배열 자르고, 정렬, 찾기]
# ⚙️ 기술 스택 From d756ff78be2abb8852f7179412ef5da658a9a352 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Mon, 24 Oct 2022 09:36:45 +0900 Subject: [PATCH 231/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20-=20K=EB=B2=88=EC=A7=B8=EC=88=98=20=EA=B5=AC=ED=95=98?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date10_22/Algorithm/Solution.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Project/src/main/java/Date10_22/Algorithm/Solution.java diff --git a/Project/src/main/java/Date10_22/Algorithm/Solution.java b/Project/src/main/java/Date10_22/Algorithm/Solution.java new file mode 100644 index 0000000..f450346 --- /dev/null +++ b/Project/src/main/java/Date10_22/Algorithm/Solution.java @@ -0,0 +1,25 @@ +package Date10_22.Algorithm; + +import java.util.Arrays; + +// 프로그래머스 K번째 수 +public class Solution { + public int[] solution(int[] arr,int[][]commands){ + int[] answer = new int[commands.length]; + int idx = 0; + for(int[] command : commands){ + int[] slicedArr = Arrays.copyOfRange(arr,command[0]-1,command[1]); // 배열을 자른다 + Arrays.sort(slicedArr); // 배열을 정렬한다. + answer[idx++] = slicedArr[command[2]-1]; + } + return answer; + } + + public static void main(String[] args) { + Solution s = new Solution(); + int[] arr = {1,5,2,6,3,7,4}; + int[][] commands = {{2,5,3},{4,4,1},{1,7,3}}; + + System.out.println(Arrays.toString(s.solution(arr,commands))); + } +} From 39f514eca07497228552c0bb70d84779649c4801 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Mon, 24 Oct 2022 09:45:26 +0900 Subject: [PATCH 232/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20-=20K=EB=B2=88=EC=A7=B8=EC=88=98=20=EA=B5=AC=ED=95=98?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/Date10_22/Algorithm/Solution.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Project/src/main/java/Date10_22/Algorithm/Solution.java b/Project/src/main/java/Date10_22/Algorithm/Solution.java index f450346..9940d88 100644 --- a/Project/src/main/java/Date10_22/Algorithm/Solution.java +++ b/Project/src/main/java/Date10_22/Algorithm/Solution.java @@ -2,15 +2,21 @@ import java.util.Arrays; -// 프로그래머스 K번째 수 +/* 프로그래머스 K번째 수 구하기 +질문 : array가 [1, 5, 2, 6, 3, 7, 4], i = 2, j = 5, k = 3이라면 + array의 2번째부터 5번째까지 자르면 [5, 2, 6, 3]입니다. + 1에서 나온 배열을 정렬하면 [2, 3, 5, 6]입니다. + 2에서 나온 배열의 3번째 숫자는 5입니다. + i는 최소 1이여야함 + */ public class Solution { public int[] solution(int[] arr,int[][]commands){ int[] answer = new int[commands.length]; int idx = 0; - for(int[] command : commands){ - int[] slicedArr = Arrays.copyOfRange(arr,command[0]-1,command[1]); // 배열을 자른다 - Arrays.sort(slicedArr); // 배열을 정렬한다. - answer[idx++] = slicedArr[command[2]-1]; + for(int[] command : commands){ // ex) [2,5,3] 들어감 + int[] slicedArr = Arrays.copyOfRange(arr,command[0]-1,command[1]); // 배열을 자른다 2-1,5 => 1~4까지 자름 [5,2,6,3] + Arrays.sort(slicedArr); // 배열을 정렬한다. [2,3,5,6] + answer[idx++] = slicedArr[command[2]-1]; //3-1 = 2번째 자리 수 저장함, 5 저장 } return answer; } From bc288716e9b0857708d68849116a3006aae77eb7 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 25 Oct 2022 10:33:12 +0900 Subject: [PATCH 233/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20Hash=20=EA=B5=AC=EC=A1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date10_25/Algorithm/HashFunction.java | 16 ++++++++++++++++ .../java/Date10_25/Algorithm/HashSolution.java | 11 +++++++++++ 2 files changed, 27 insertions(+) create mode 100644 Project/src/main/java/Date10_25/Algorithm/HashFunction.java create mode 100644 Project/src/main/java/Date10_25/Algorithm/HashSolution.java diff --git a/Project/src/main/java/Date10_25/Algorithm/HashFunction.java b/Project/src/main/java/Date10_25/Algorithm/HashFunction.java new file mode 100644 index 0000000..599cfce --- /dev/null +++ b/Project/src/main/java/Date10_25/Algorithm/HashFunction.java @@ -0,0 +1,16 @@ +package Date10_25.Algorithm; + +public class HashFunction { + public int hash(String key) { + int asciiSum = 0; + for(int i=0; i Date: Tue, 25 Oct 2022 10:33:22 +0900 Subject: [PATCH 234/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20Hash=20Table=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Algorithm/HashTableSolution.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Project/src/main/java/Date10_25/Algorithm/HashTableSolution.java diff --git a/Project/src/main/java/Date10_25/Algorithm/HashTableSolution.java b/Project/src/main/java/Date10_25/Algorithm/HashTableSolution.java new file mode 100644 index 0000000..459fb61 --- /dev/null +++ b/Project/src/main/java/Date10_25/Algorithm/HashTableSolution.java @@ -0,0 +1,47 @@ +package Date10_25.Algorithm; + +public class HashTableSolution { + private int size = 10000; + private int[] table = new int[size]; + + public HashTableSolution() { + } + + public HashTableSolution(int size) { + this.size = size; + this.table = new int[size]; + } + + public int hash(String key) { + int asciiSum = 0; + for (int i = 0; i < key.length(); i++) { + asciiSum += key.charAt(i); + } + return asciiSum % size; + } + + public void insert(String key, Integer value) { + int hashCode = hash(key); + this.table[hashCode] = value; + System.out.println(key + " " + hashCode + "방에 저장이 완료되었습니다."); + } + + public int search(String key) { + return this.table[hash(key)]; + } + + public static void main(String[] args) { + String[] names = new String[]{"DongyeonKang", + "SubinKang", "KwanwunKo", "HyunseokKo", "KyoungdukKoo", "YeonjiGu", "SoyeonKown", "OhsukKwon", "GunwooKim", "KiheonKim", "NayeongKim", "DohyeonKim", "MinkyoungKim", "MinjiKim", "SanghoKim", "SolbaeKim", "YejinKim", "EungjunKim", "JaegeunKim", "JeonghyeonKim", "JunhoKim", "JisuKim", "kimjinah", "HaneulKim", "HeejungKim", "KimoonPark", "EunbinPark", "JeongHoonPark", "JeminPark", "TaegeunPark", "JiwonBae", "SeunggeunBaek", "JihwanByeon", "HeungseopByeon", "JeongHeeSeo", "TaegeonSeo", "SeeYunSeok", "SuyeonSeong", "SeyoelSon", "MinjiSong", "JinwooSong", "hyunboSim", "SominAhn", "JiyoungAhn", "ChangbumAn", "SoonminEom", + "HyeongsangOh", "SuinWoo", "JuwanWoo", "InkyuYoon", "GahyunLee", "DaonLee", "DohyunLee", "SanghunLee", "SujinLee", "AjinLee", "YeonJae", "HyeonjuLee", "HakjunYim", "SeoyunJang", "SeohyeonJang", "JinseonJang", "SujinJeon", "SeunghwanJeon", "DaehwanJung", "JaeHyunJeung", "HeejunJeong", "GukhyeonCho", "MunjuJo", "YejiJo", "ChanminJu", "MinjunChoi", "SujeongChoi", "SeunghoChoi", "AyeongChoi", "GeonjooHan", "JinhyuckHeo", "MinwooHwang", "SieunHwang", + "JunhaHwang"}; + + HashTableSolution ht = new HashTableSolution(200); + for (int i = 0; i < names.length; i++) { + ht.insert(names[i] , ht.hash(names[i])); + } + System.out.println(ht.search("DongyeonKang")); + System.out.println(ht.search("JiyoungAhn")); + } +} + From 6a8f1104b4696a24038099ae90ce7ab20129c448 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Tue, 25 Oct 2022 15:44:14 +0900 Subject: [PATCH 235/307] Update README.md --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 67f7874..b82dece 100644 --- a/README.md +++ b/README.md @@ -21,13 +21,17 @@ - 2022-10-18 : 알고리즘[For문 사각형 만들기] + Java/Mysql 연결(리팩토링 : 중복 코드 분리, Abstract하여 DB별 설정 나누기) -- 2022-10-19 : 알고리즘[Stack(1)] + Java/Mysql 연결(리팩토링 : Interface, class, Factory 분리) + spring 연동(spring 시작) +------------------------------------------ Spring 시작 ------------------------------------------ +Spring은 별도 Repository를 통해 실습을 함 +https://github.com/Bae-Ji-Won/Toby-spring-jdbc-practice + +- 2022-10-19 : 알고리즘[Stack(1)] + Java/Mysql 연결(리팩토링 : Interface, class, Factory 분리) + spring 연동 - 2022-10-20 : 알고리즘[Stack(2)] + Spring bean 설정 + 예외 처리 + Spring TDD - 2022-10-21 : 알고리즘[Stack(3)] + Spring Strategy + Jdbc -- 2022-10-24 : 알고리즘[배열 자르고, 정렬, 찾기] +- 2022-10-24 : 알고리즘[배열 자르고, 정렬, 찾기] + Spring DataSource + 익명클래스 + JDBC 분리
# ⚙️ 기술 스택 From c0d482a3ab638cfd047b348b0382a7b54b25c515 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Tue, 25 Oct 2022 15:44:32 +0900 Subject: [PATCH 236/307] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b82dece..14a924a 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ - 2022-10-18 : 알고리즘[For문 사각형 만들기] + Java/Mysql 연결(리팩토링 : 중복 코드 분리, Abstract하여 DB별 설정 나누기) ------------------------------------------ Spring 시작 ------------------------------------------ -Spring은 별도 Repository를 통해 실습을 함 +Spring은 별도 Repository를 통해 실습을 함< https://github.com/Bae-Ji-Won/Toby-spring-jdbc-practice - 2022-10-19 : 알고리즘[Stack(1)] + Java/Mysql 연결(리팩토링 : Interface, class, Factory 분리) + spring 연동 From 52a258960da965b14922d8e7d7e46102e7347904 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Tue, 25 Oct 2022 15:44:52 +0900 Subject: [PATCH 237/307] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 14a924a..87e911b 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ - 2022-10-18 : 알고리즘[For문 사각형 만들기] + Java/Mysql 연결(리팩토링 : 중복 코드 분리, Abstract하여 DB별 설정 나누기) ------------------------------------------ Spring 시작 ------------------------------------------ -Spring은 별도 Repository를 통해 실습을 함< +
Spring은 별도 Repository를 통해 실습을 함 https://github.com/Bae-Ji-Won/Toby-spring-jdbc-practice - 2022-10-19 : 알고리즘[Stack(1)] + Java/Mysql 연결(리팩토링 : Interface, class, Factory 분리) + spring 연동 From c967cbe28f6701ea9561f82a17ff2f65523b9281 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Tue, 25 Oct 2022 15:46:06 +0900 Subject: [PATCH 238/307] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 87e911b..5beaf97 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ ------------------------------------------ Spring 시작 ------------------------------------------
Spring은 별도 Repository를 통해 실습을 함 -https://github.com/Bae-Ji-Won/Toby-spring-jdbc-practice +https://github.com/Bae-Ji-Won/Spring-Study - 2022-10-19 : 알고리즘[Stack(1)] + Java/Mysql 연결(리팩토링 : Interface, class, Factory 분리) + spring 연동 From 84dbf92a835b51de1a0542f526dbc75d1a127a15 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Tue, 25 Oct 2022 15:47:49 +0900 Subject: [PATCH 239/307] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5beaf97..a212f0d 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ - 2022-10-18 : 알고리즘[For문 사각형 만들기] + Java/Mysql 연결(리팩토링 : 중복 코드 분리, Abstract하여 DB별 설정 나누기) ------------------------------------------ Spring 시작 ------------------------------------------ -
Spring은 별도 Repository를 통해 실습을 함 +
Spring은 별도 Repository를 통해 공부를 진행 https://github.com/Bae-Ji-Won/Spring-Study - 2022-10-19 : 알고리즘[Stack(1)] + Java/Mysql 연결(리팩토링 : Interface, class, Factory 분리) + spring 연동 From 09a641aa551ac022e452104393729598c378980b Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Tue, 25 Oct 2022 15:52:29 +0900 Subject: [PATCH 240/307] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a212f0d..fa89ced 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ https://github.com/Bae-Ji-Won/Spring-Study # ⚙️ 기술 스택
- Java + Java

From 7b71eb3668d16013055e44593ae416101cc96b28 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Tue, 25 Oct 2022 15:53:14 +0900 Subject: [PATCH 241/307] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fa89ced..a212f0d 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ https://github.com/Bae-Ji-Won/Spring-Study # ⚙️ 기술 스택
- Java + Java

From e67256611e6cc7357cc6adeb55ee0e74bab78ff0 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Tue, 25 Oct 2022 15:56:52 +0900 Subject: [PATCH 242/307] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a212f0d..fdccabf 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ https://github.com/Bae-Ji-Won/Spring-Study # ⚙️ 기술 스택
Java + Mysql

From a1240fa2614215e1bd5e69acdaa5dd90264245b7 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Tue, 25 Oct 2022 15:57:06 +0900 Subject: [PATCH 243/307] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fdccabf..1ea2281 100644 --- a/README.md +++ b/README.md @@ -70,4 +70,4 @@ https://velog.io/@qowl880/Java-%EB%8C%80%EC%9A%A9%EB%9F%89%EC%B2%98%EB%A6%AC-%ED ### 📗 정리 블로그 https://velog.io/@qowl880/Java-%EB%8C%80%EC%9A%A9%EB%9F%89%EC%B2%98%EB%A6%AC-%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B82-owien5hj - + From 14a57b945af9ab214b3b728b4c4a18b0305b0ff8 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Tue, 25 Oct 2022 15:58:19 +0900 Subject: [PATCH 244/307] Update README.md --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1ea2281..9928294 100644 --- a/README.md +++ b/README.md @@ -25,13 +25,15 @@
Spring은 별도 Repository를 통해 공부를 진행 https://github.com/Bae-Ji-Won/Spring-Study -- 2022-10-19 : 알고리즘[Stack(1)] + Java/Mysql 연결(리팩토링 : Interface, class, Factory 분리) + spring 연동 +- 2022-10-19 : 알고리즘[Stack(1)] -- 2022-10-20 : 알고리즘[Stack(2)] + Spring bean 설정 + 예외 처리 + Spring TDD +- 2022-10-20 : 알고리즘[Stack(2)] -- 2022-10-21 : 알고리즘[Stack(3)] + Spring Strategy + Jdbc +- 2022-10-21 : 알고리즘[Stack(3)] -- 2022-10-24 : 알고리즘[배열 자르고, 정렬, 찾기] + Spring DataSource + 익명클래스 + JDBC 분리 +- 2022-10-24 : 알고리즘[배열 자르고, 정렬, 찾기] + +- 2022-10-25 : 알고리즘[Hash]
# ⚙️ 기술 스택 From 052c4acdf400767c36b15a4b7ed324ce13b8a267 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 25 Oct 2022 16:00:36 +0900 Subject: [PATCH 245/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20-=20K=EB=B2=88=EC=A7=B8=EC=88=98=20=EA=B5=AC=ED=95=98?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/{Date10_22 => Date10_24}/Algorithm/Solution.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename Project/src/main/java/{Date10_22 => Date10_24}/Algorithm/Solution.java (96%) diff --git a/Project/src/main/java/Date10_22/Algorithm/Solution.java b/Project/src/main/java/Date10_24/Algorithm/Solution.java similarity index 96% rename from Project/src/main/java/Date10_22/Algorithm/Solution.java rename to Project/src/main/java/Date10_24/Algorithm/Solution.java index 9940d88..127001b 100644 --- a/Project/src/main/java/Date10_22/Algorithm/Solution.java +++ b/Project/src/main/java/Date10_24/Algorithm/Solution.java @@ -1,4 +1,4 @@ -package Date10_22.Algorithm; +package Date10_24.Algorithm; import java.util.Arrays; @@ -14,7 +14,7 @@ public int[] solution(int[] arr,int[][]commands){ int[] answer = new int[commands.length]; int idx = 0; for(int[] command : commands){ // ex) [2,5,3] 들어감 - int[] slicedArr = Arrays.copyOfRange(arr,command[0]-1,command[1]); // 배열을 자른다 2-1,5 => 1~4까지 자름 [5,2,6,3] + int[] slicedArr = Arrays.copyOfRange(arr,command[0]-1,command[1]); // 배열을 자른다 2-1,5 => 1~4까지 자름 [5,2,6,3] Arrays.sort(slicedArr); // 배열을 정렬한다. [2,3,5,6] answer[idx++] = slicedArr[command[2]-1]; //3-1 = 2번째 자리 수 저장함, 5 저장 } From 81376debf50fa2331de137a35e63e7107344777e Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 25 Oct 2022 16:01:03 +0900 Subject: [PATCH 246/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20-=20K=EB=B2=88=EC=A7=B8=EC=88=98=20=EA=B5=AC=ED=95=98?= =?UTF-8?q?=EA=B8=B0(Queue=20=EC=82=AC=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date10_24/Algorithm/Solution2.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Project/src/main/java/Date10_24/Algorithm/Solution2.java diff --git a/Project/src/main/java/Date10_24/Algorithm/Solution2.java b/Project/src/main/java/Date10_24/Algorithm/Solution2.java new file mode 100644 index 0000000..d463fe4 --- /dev/null +++ b/Project/src/main/java/Date10_24/Algorithm/Solution2.java @@ -0,0 +1,21 @@ +package Date10_24.Algorithm; + +import java.util.PriorityQueue; + +// 우선순위 큐 사용 +public class Solution2 { + public int[] solution2(int[] arr, int[][] commands) { + int[] answer = new int[commands.length]; + for (int i = 0; i < commands.length; i++) { + PriorityQueue pq = new PriorityQueue<>(); + + for (int j = commands[i][0] - 1; j < commands[i][1]; j++) { + pq.add(arr[j]); // 우선순위 큐에 from, to까지 넣기 + } + for (int j = 0; j < commands[i][2]; j++) { + answer[i] = pq.poll(); //stack의 pop과 + } + } + return answer; + } +} From efee518c0d871039a8b9f3afc3dbafa2e33ec4ba Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 25 Oct 2022 16:01:35 +0900 Subject: [PATCH 247/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20Hash=20Table=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_25/Algorithm/HashTableSolution.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Project/src/main/java/Date10_25/Algorithm/HashTableSolution.java b/Project/src/main/java/Date10_25/Algorithm/HashTableSolution.java index 459fb61..40f2e10 100644 --- a/Project/src/main/java/Date10_25/Algorithm/HashTableSolution.java +++ b/Project/src/main/java/Date10_25/Algorithm/HashTableSolution.java @@ -12,7 +12,7 @@ public HashTableSolution(int size) { this.table = new int[size]; } - public int hash(String key) { + public int hash(String key) { // Hash를 통해 임의의 값(index) 출력 int asciiSum = 0; for (int i = 0; i < key.length(); i++) { asciiSum += key.charAt(i); @@ -20,7 +20,7 @@ public int hash(String key) { return asciiSum % size; } - public void insert(String key, Integer value) { + public void insert(String key, Integer value) { // index 공간에 값 저장 int hashCode = hash(key); this.table[hashCode] = value; System.out.println(key + " " + hashCode + "방에 저장이 완료되었습니다."); @@ -36,12 +36,14 @@ public static void main(String[] args) { "HyeongsangOh", "SuinWoo", "JuwanWoo", "InkyuYoon", "GahyunLee", "DaonLee", "DohyunLee", "SanghunLee", "SujinLee", "AjinLee", "YeonJae", "HyeonjuLee", "HakjunYim", "SeoyunJang", "SeohyeonJang", "JinseonJang", "SujinJeon", "SeunghwanJeon", "DaehwanJung", "JaeHyunJeung", "HeejunJeong", "GukhyeonCho", "MunjuJo", "YejiJo", "ChanminJu", "MinjunChoi", "SujeongChoi", "SeunghoChoi", "AyeongChoi", "GeonjooHan", "JinhyuckHeo", "MinwooHwang", "SieunHwang", "JunhaHwang"}; + String[] al = new String[]{"aaa","bbb","ccc"}; + HashTableSolution ht = new HashTableSolution(200); - for (int i = 0; i < names.length; i++) { - ht.insert(names[i] , ht.hash(names[i])); + for (int i = 0; i < al.length; i++) { + ht.insert(al[i] , ht.hash(al[i])); } - System.out.println(ht.search("DongyeonKang")); - System.out.println(ht.search("JiyoungAhn")); + System.out.println(ht.search("aaa")); + System.out.println(ht.search("ccc")); } } From 54bb8fff8d463e1ea596bcf1f2083e5ba5608acc Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Wed, 26 Oct 2022 12:21:31 +0900 Subject: [PATCH 248/307] Hash Collistion --- .../src/main/java/Date10_26/HashSolution.java | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 Project/src/main/java/Date10_26/HashSolution.java diff --git a/Project/src/main/java/Date10_26/HashSolution.java b/Project/src/main/java/Date10_26/HashSolution.java new file mode 100644 index 0000000..3e76809 --- /dev/null +++ b/Project/src/main/java/Date10_26/HashSolution.java @@ -0,0 +1,111 @@ +package Algorithm; + +import java.util.ArrayList; +import java.util.List; + +// 해시 충돌 했을경우 해결법 +public class HashSolution { + + // 멤버변수 + private int size; + private List[] table; // 2차원 배열 리스트 + // ex) 2차원 배열 리스트에 Node형식으로 저장함 + // 1 2 3 + // ["aa",1] ["aaa",2] + // ["bb",2] + + // 내부 클래스 선언 + class Node { // Node DTO [(String)key,(Integer)value] 형식 + private String key; + private Integer value; + + public Node(String key, Integer value) { + this.key = key; + this.value = value; + } + + public String getKey() { + return key; + } + + public Integer getValue() { + return value; + } + } + + + // 디폴트 생성자 + public HashSolution() { // 생성자 + this.size = 10000; + this.table = new ArrayList[size]; + } + + // 생성자 오버로딩 + public HashSolution(int size) { // 생성자 + this.size = size; + this.table = new ArrayList[size]; // 2차원 배열 사이즈 선언 + } + + public int hash(String str) { // hash를 통해 임의의 숫자 구함 + int ascii = 0; + for (int i = 0; i < str.length(); i++) { + ascii += str.charAt(i); + } + return ascii % size; // 1000개 0~999까지의 값 출력 + } + + public Integer get(String key) { // 해시 값 찾기 + List nodes = this.table[hash(key)]; // 2차원 배열 리스트중 hash(key)에 해당하는 배열 가져옴 + // ex) 2차원 배열 리스트의 해당 값을 가져옴 만약 1번일때 + // 1 2 3 + // ["aa",1] ["aaa",2] + // ["bb",2] + + // nodes => ["aa",1],["bb',2] 가져옴 + for (Node node : nodes) { // 2번 반복 + if (key.equals(node.getKey())) { // 입력한 키와 찾아온 키를 비교함 + // ex) 입력된 키가 "bb"일때 + // 1번째 순서일때는 못찾고 2번째 순서일떄 찾는것으로 + // 2번째 node = {"bb",2} , node.getkey() = "bb" + // bb.equals(bb) true + return node.value; // 2번쨰 노드의 객체의 값인 2를 가져옴 + } + } + + return null; + } + + public void insert(String key, Integer value) { + int hashCode = hash(key); // 입력한 문자를 가지고 해시를 통해 임의의 key값 출력 + if (this.table[hashCode] == null) { // 만약 2차원 배열 리스트에 없는 값이라면 + this.table[hashCode] = new ArrayList<>(); // 2차원 배열 리스트 생성 + } + this.table[hashCode].add(new Node(key,value)); // 해당 해쉬 자리에 key,value 객체 저장 + } + + public static void main(String[] args) { + String[] names = new String[]{"DongyeonKang", + "SubinKang", "KwanwunKo", "HyunseokKo", "KyoungdukKoo", "YeonjiGu", "SoyeonKown", "OhsukKwon", "GunwooKim", "KiheonKim", "NayeongKim", "DohyeonKim", "MinkyoungKim", "MinjiKim", "SanghoKim", "SolbaeKim", "YejinKim", "EungjunKim", "JaegeunKim", "JeonghyeonKim", "JunhoKim", "JisuKim", "kimjinah", "HaneulKim", "HeejungKim", "KimoonPark", "EunbinPark", "JeongHoonPark", "JeminPark", "TaegeunPark", "JiwonBae", "SeunggeunBaek", "JihwanByeon", "HeungseopByeon", "JeongHeeSeo", "TaegeonSeo", "SeeYunSeok", "SuyeonSeong", "SeyoelSon", "MinjiSong", "JinwooSong", "hyunboSim", "SominAhn", "JiyoungAhn", "ChangbumAn", "SoonminEom", + "HyeongsangOh", "SuinWoo", "JuwanWoo", "InkyuYoon", "GahyunLee", "DaonLee", "DohyunLee", "SanghunLee", "SujinLee", "AjinLee", "YeonJae", "HyeonjuLee", "HakjunYim", "SeoyunJang", "SeohyeonJang", "JinseonJang", "SujinJeon", "SeunghwanJeon", "DaehwanJung", "JaeHyunJeung", "HeejunJeong", "GukhyeonCho", "MunjuJo", "YejiJo", "ChanminJu", "MinjunChoi", "SujeongChoi", "SeunghoChoi", "AyeongChoi", "GeonjooHan", "JinhyuckHeo", "MinwooHwang", "SieunHwang", + "JunhaHwang"}; + + + HashSolution hashSolution = new HashSolution(200); + hashSolution.insert("Yoonseo", 1); + hashSolution.insert("Seoyoon", 2); + + int result = hashSolution.get("Yoonseo"); + if (result == 1) { + System.out.println("테스트 성공"); + } else { + System.out.printf("테스트 실패 value:%d", result); + } + + result = hashSolution.get("Seoyoon"); + if (result == 2) { + System.out.println("테스트 성공"); + } else { + System.out.printf("테스트 실패 value:%d", result); + } + } +} \ No newline at end of file From 4508df273c647196b49c8144339e16519543bdc7 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Wed, 26 Oct 2022 12:26:56 +0900 Subject: [PATCH 249/307] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9928294..d176398 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,8 @@ https://github.com/Bae-Ji-Won/Spring-Study - 2022-10-24 : 알고리즘[배열 자르고, 정렬, 찾기] - 2022-10-25 : 알고리즘[Hash] + +- 2022-10-26 : 알고리즘[Hash Collistion]
# ⚙️ 기술 스택 From ce47bbd28dc8ad0eb5cf77beda01c5776578f3ca Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 27 Oct 2022 09:30:06 +0900 Subject: [PATCH 250/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20Hash(2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/Date10_27/Algorithm/UnfinishedPlayer.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Project/src/main/java/Date10_27/Algorithm/UnfinishedPlayer.java diff --git a/Project/src/main/java/Date10_27/Algorithm/UnfinishedPlayer.java b/Project/src/main/java/Date10_27/Algorithm/UnfinishedPlayer.java new file mode 100644 index 0000000..d67ff04 --- /dev/null +++ b/Project/src/main/java/Date10_27/Algorithm/UnfinishedPlayer.java @@ -0,0 +1,9 @@ +package Date10_27.Algorithm; + +/* 프로그래머스 완주하지 못한 선수 문제 + + + */ +public class UnfinishedPlayer { + +} From 5a685a71efba05f558883b617ef8d1197d79afdc Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Thu, 27 Oct 2022 09:32:49 +0900 Subject: [PATCH 251/307] Delete Project/src/main/java/Date10_26 directory --- .../src/main/java/Date10_26/HashSolution.java | 111 ------------------ 1 file changed, 111 deletions(-) delete mode 100644 Project/src/main/java/Date10_26/HashSolution.java diff --git a/Project/src/main/java/Date10_26/HashSolution.java b/Project/src/main/java/Date10_26/HashSolution.java deleted file mode 100644 index 3e76809..0000000 --- a/Project/src/main/java/Date10_26/HashSolution.java +++ /dev/null @@ -1,111 +0,0 @@ -package Algorithm; - -import java.util.ArrayList; -import java.util.List; - -// 해시 충돌 했을경우 해결법 -public class HashSolution { - - // 멤버변수 - private int size; - private List[] table; // 2차원 배열 리스트 - // ex) 2차원 배열 리스트에 Node형식으로 저장함 - // 1 2 3 - // ["aa",1] ["aaa",2] - // ["bb",2] - - // 내부 클래스 선언 - class Node { // Node DTO [(String)key,(Integer)value] 형식 - private String key; - private Integer value; - - public Node(String key, Integer value) { - this.key = key; - this.value = value; - } - - public String getKey() { - return key; - } - - public Integer getValue() { - return value; - } - } - - - // 디폴트 생성자 - public HashSolution() { // 생성자 - this.size = 10000; - this.table = new ArrayList[size]; - } - - // 생성자 오버로딩 - public HashSolution(int size) { // 생성자 - this.size = size; - this.table = new ArrayList[size]; // 2차원 배열 사이즈 선언 - } - - public int hash(String str) { // hash를 통해 임의의 숫자 구함 - int ascii = 0; - for (int i = 0; i < str.length(); i++) { - ascii += str.charAt(i); - } - return ascii % size; // 1000개 0~999까지의 값 출력 - } - - public Integer get(String key) { // 해시 값 찾기 - List nodes = this.table[hash(key)]; // 2차원 배열 리스트중 hash(key)에 해당하는 배열 가져옴 - // ex) 2차원 배열 리스트의 해당 값을 가져옴 만약 1번일때 - // 1 2 3 - // ["aa",1] ["aaa",2] - // ["bb",2] - - // nodes => ["aa",1],["bb',2] 가져옴 - for (Node node : nodes) { // 2번 반복 - if (key.equals(node.getKey())) { // 입력한 키와 찾아온 키를 비교함 - // ex) 입력된 키가 "bb"일때 - // 1번째 순서일때는 못찾고 2번째 순서일떄 찾는것으로 - // 2번째 node = {"bb",2} , node.getkey() = "bb" - // bb.equals(bb) true - return node.value; // 2번쨰 노드의 객체의 값인 2를 가져옴 - } - } - - return null; - } - - public void insert(String key, Integer value) { - int hashCode = hash(key); // 입력한 문자를 가지고 해시를 통해 임의의 key값 출력 - if (this.table[hashCode] == null) { // 만약 2차원 배열 리스트에 없는 값이라면 - this.table[hashCode] = new ArrayList<>(); // 2차원 배열 리스트 생성 - } - this.table[hashCode].add(new Node(key,value)); // 해당 해쉬 자리에 key,value 객체 저장 - } - - public static void main(String[] args) { - String[] names = new String[]{"DongyeonKang", - "SubinKang", "KwanwunKo", "HyunseokKo", "KyoungdukKoo", "YeonjiGu", "SoyeonKown", "OhsukKwon", "GunwooKim", "KiheonKim", "NayeongKim", "DohyeonKim", "MinkyoungKim", "MinjiKim", "SanghoKim", "SolbaeKim", "YejinKim", "EungjunKim", "JaegeunKim", "JeonghyeonKim", "JunhoKim", "JisuKim", "kimjinah", "HaneulKim", "HeejungKim", "KimoonPark", "EunbinPark", "JeongHoonPark", "JeminPark", "TaegeunPark", "JiwonBae", "SeunggeunBaek", "JihwanByeon", "HeungseopByeon", "JeongHeeSeo", "TaegeonSeo", "SeeYunSeok", "SuyeonSeong", "SeyoelSon", "MinjiSong", "JinwooSong", "hyunboSim", "SominAhn", "JiyoungAhn", "ChangbumAn", "SoonminEom", - "HyeongsangOh", "SuinWoo", "JuwanWoo", "InkyuYoon", "GahyunLee", "DaonLee", "DohyunLee", "SanghunLee", "SujinLee", "AjinLee", "YeonJae", "HyeonjuLee", "HakjunYim", "SeoyunJang", "SeohyeonJang", "JinseonJang", "SujinJeon", "SeunghwanJeon", "DaehwanJung", "JaeHyunJeung", "HeejunJeong", "GukhyeonCho", "MunjuJo", "YejiJo", "ChanminJu", "MinjunChoi", "SujeongChoi", "SeunghoChoi", "AyeongChoi", "GeonjooHan", "JinhyuckHeo", "MinwooHwang", "SieunHwang", - "JunhaHwang"}; - - - HashSolution hashSolution = new HashSolution(200); - hashSolution.insert("Yoonseo", 1); - hashSolution.insert("Seoyoon", 2); - - int result = hashSolution.get("Yoonseo"); - if (result == 1) { - System.out.println("테스트 성공"); - } else { - System.out.printf("테스트 실패 value:%d", result); - } - - result = hashSolution.get("Seoyoon"); - if (result == 2) { - System.out.println("테스트 성공"); - } else { - System.out.printf("테스트 실패 value:%d", result); - } - } -} \ No newline at end of file From d64e39753ad5ea5f3848f595d369f46d65ee2cfc Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 27 Oct 2022 09:38:41 +0900 Subject: [PATCH 252/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20Hash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_26/Algorithm/HashSolution.java | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 Project/src/main/java/Date10_26/Algorithm/HashSolution.java diff --git a/Project/src/main/java/Date10_26/Algorithm/HashSolution.java b/Project/src/main/java/Date10_26/Algorithm/HashSolution.java new file mode 100644 index 0000000..582960e --- /dev/null +++ b/Project/src/main/java/Date10_26/Algorithm/HashSolution.java @@ -0,0 +1,111 @@ +package Date10_26.Algorithm; + +import java.util.ArrayList; +import java.util.List; + +// 해시 충돌 했을경우 해결법 +public class HashSolution { + + // 멤버변수 + private int size; + private List[] table; // 2차원 배열 리스트 + // ex) 2차원 배열 리스트에 Node형식으로 저장함 + // 1 2 3 + // ["aa",1] ["aaa",2] + // ["bb",2] + + // 내부 클래스 선언 + class Node { // Node DTO [(String)key,(Integer)value] 형식 + private String key; + private Integer value; + + public Node(String key, Integer value) { + this.key = key; + this.value = value; + } + + public String getKey() { + return key; + } + + public Integer getValue() { + return value; + } + } + + + // 디폴트 생성자 + public HashSolution() { // 생성자 + this.size = 10000; + this.table = new ArrayList[size]; + } + + // 생성자 오버로딩 + public HashSolution(int size) { // 생성자 + this.size = size; + this.table = new ArrayList[size]; // 2차원 배열 사이즈 선언 + } + + public int hash(String str) { // hash를 통해 임의의 숫자 구함 + int ascii = 0; + for (int i = 0; i < str.length(); i++) { + ascii += str.charAt(i); + } + return ascii % size; // 1000개 0~999까지의 값 출력 + } + + public Integer get(String key) { // 해시 값 찾기 + List nodes = this.table[hash(key)]; // 2차원 배열 리스트중 hash(key)에 해당하는 배열 가져옴 + // ex) 2차원 배열 리스트의 해당 값을 가져옴 만약 1번일때 + // 1 2 3 + // ["aa",1] ["aaa",2] + // ["bb",2] + + // nodes => ["aa",1],["bb',2] 가져옴 + for (Node node : nodes) { // 2번 반복 + if (key.equals(node.getKey())) { // 입력한 키와 찾아온 키를 비교함 + // ex) 입력된 키가 "bb"일때 + // 1번째 순서일때는 못찾고 2번째 순서일떄 찾는것으로 + // 2번째 node = {"bb",2} , node.getkey() = "bb" + // bb.equals(bb) true + return node.value; // 2번쨰 노드의 객체의 값인 2를 가져옴 + } + } + + return null; + } + + public void insert(String key, Integer value) { + int hashCode = hash(key); // 입력한 문자를 가지고 해시를 통해 임의의 key값 출력 + if (this.table[hashCode] == null) { // 만약 2차원 배열 리스트에 없는 값이라면 + this.table[hashCode] = new ArrayList<>(); // 2차원 배열 리스트 생성 + } + this.table[hashCode].add(new Node(key,value)); // 해당 해쉬 자리에 key,value 객체 저장 + } + + public static void main(String[] args) { + String[] names = new String[]{"DongyeonKang", + "SubinKang", "KwanwunKo", "HyunseokKo", "KyoungdukKoo", "YeonjiGu", "SoyeonKown", "OhsukKwon", "GunwooKim", "KiheonKim", "NayeongKim", "DohyeonKim", "MinkyoungKim", "MinjiKim", "SanghoKim", "SolbaeKim", "YejinKim", "EungjunKim", "JaegeunKim", "JeonghyeonKim", "JunhoKim", "JisuKim", "kimjinah", "HaneulKim", "HeejungKim", "KimoonPark", "EunbinPark", "JeongHoonPark", "JeminPark", "TaegeunPark", "JiwonBae", "SeunggeunBaek", "JihwanByeon", "HeungseopByeon", "JeongHeeSeo", "TaegeonSeo", "SeeYunSeok", "SuyeonSeong", "SeyoelSon", "MinjiSong", "JinwooSong", "hyunboSim", "SominAhn", "JiyoungAhn", "ChangbumAn", "SoonminEom", + "HyeongsangOh", "SuinWoo", "JuwanWoo", "InkyuYoon", "GahyunLee", "DaonLee", "DohyunLee", "SanghunLee", "SujinLee", "AjinLee", "YeonJae", "HyeonjuLee", "HakjunYim", "SeoyunJang", "SeohyeonJang", "JinseonJang", "SujinJeon", "SeunghwanJeon", "DaehwanJung", "JaeHyunJeung", "HeejunJeong", "GukhyeonCho", "MunjuJo", "YejiJo", "ChanminJu", "MinjunChoi", "SujeongChoi", "SeunghoChoi", "AyeongChoi", "GeonjooHan", "JinhyuckHeo", "MinwooHwang", "SieunHwang", + "JunhaHwang"}; + + + HashSolution hashSolution = new HashSolution(200); + hashSolution.insert("Yoonseo", 1); + hashSolution.insert("Seoyoon", 2); + + int result = hashSolution.get("Yoonseo"); + if (result == 1) { + System.out.println("테스트 성공"); + } else { + System.out.printf("테스트 실패 value:%d", result); + } + + result = hashSolution.get("Seoyoon"); + if (result == 2) { + System.out.println("테스트 성공"); + } else { + System.out.printf("테스트 실패 value:%d", result); + } + } +} \ No newline at end of file From 57a653feba61dc0817f7e9faa4208e708ca39b32 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 27 Oct 2022 09:40:05 +0900 Subject: [PATCH 253/307] Factory --- .../java/Date10_24/Factory/AddStrategy.java | 26 ++++ .../Date10_24/Factory/DeleteAllStrategy.java | 17 ++ .../Date10_24/Factory/StatementStrategy.java | 11 ++ .../main/java/Date10_24/Factory/UserDao.java | 145 ++++++++++++++++++ .../Date10_24/Factory/UserDaoFactory.java | 54 +++++++ .../src/main/java/Date10_24/domain/User.java | 32 ++++ 6 files changed, 285 insertions(+) create mode 100644 Project/src/main/java/Date10_24/Factory/AddStrategy.java create mode 100644 Project/src/main/java/Date10_24/Factory/DeleteAllStrategy.java create mode 100644 Project/src/main/java/Date10_24/Factory/StatementStrategy.java create mode 100644 Project/src/main/java/Date10_24/Factory/UserDao.java create mode 100644 Project/src/main/java/Date10_24/Factory/UserDaoFactory.java create mode 100644 Project/src/main/java/Date10_24/domain/User.java diff --git a/Project/src/main/java/Date10_24/Factory/AddStrategy.java b/Project/src/main/java/Date10_24/Factory/AddStrategy.java new file mode 100644 index 0000000..b62baf6 --- /dev/null +++ b/Project/src/main/java/Date10_24/Factory/AddStrategy.java @@ -0,0 +1,26 @@ +package Date10_24.Factory; + +import Date10_24.domain.User; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; + +public class AddStrategy implements StatementStrategy { + + private User user; + + public AddStrategy(User user){ + this.user =user; + } + + @Override + public PreparedStatement makepreparedStatement(Connection connection) throws SQLException { + PreparedStatement ps = connection.prepareStatement("INSERT INTO users(id,name,password) VALUES(?,?,?)"); + ps.setString(1,user.getId()); // mysql 테이블로 값 insert + ps.setString(2,user.getName()); + ps.setString(3,user.getPassword()); + + return ps; + } +} diff --git a/Project/src/main/java/Date10_24/Factory/DeleteAllStrategy.java b/Project/src/main/java/Date10_24/Factory/DeleteAllStrategy.java new file mode 100644 index 0000000..1613e22 --- /dev/null +++ b/Project/src/main/java/Date10_24/Factory/DeleteAllStrategy.java @@ -0,0 +1,17 @@ +package Date10_24.Factory; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; + + +// Delete 쿼리문 클래스 +public class DeleteAllStrategy implements StatementStrategy { + + @Override + public PreparedStatement makepreparedStatement(Connection connection) throws SQLException { + return connection.prepareStatement("delete from users"); + } +} + + diff --git a/Project/src/main/java/Date10_24/Factory/StatementStrategy.java b/Project/src/main/java/Date10_24/Factory/StatementStrategy.java new file mode 100644 index 0000000..c5e4a0b --- /dev/null +++ b/Project/src/main/java/Date10_24/Factory/StatementStrategy.java @@ -0,0 +1,11 @@ +package Date10_24.Factory; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; + +// 쿼리문을 DAO 클래스에 작성하지 않고 따로 interface를 통해 각자 별도 클래스 생성함 +public interface StatementStrategy { + PreparedStatement makepreparedStatement(Connection connection) throws SQLException; + +} diff --git a/Project/src/main/java/Date10_24/Factory/UserDao.java b/Project/src/main/java/Date10_24/Factory/UserDao.java new file mode 100644 index 0000000..ad7b8be --- /dev/null +++ b/Project/src/main/java/Date10_24/Factory/UserDao.java @@ -0,0 +1,145 @@ +package Date10_24.Factory; + +import Date10_24.domain.User; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +// 중복코드만 따로 빼내서 작성한 코드 (3번째 방식) +public class UserDao { + + private DataSource dataSource; // connectionmaker -> datasource 변경 + + public UserDao(){ // 생성자를 통해 AWS DB의 makeConnection()을 오버라이딩하여 사용 + this.dataSource = new UserDaoFactory().awsDataSource(); + } + public UserDao(DataSource dataSource){ + this.dataSource = dataSource; + } + + // add,delete등 sql문을 사용하는 메서드들은 쿼리문(insert, delete,select 등)만 다르지 구조는 모두 같다 + // 따라서 이러한 중복되는 구조들을 하나의 메서드로 정의한 후 호출하여 사용함 + public void jdbcContextWithStatementStatementstrategy(StatementStrategy st){ + Connection conn = null; + PreparedStatement ps = null; + + try { // 예외처리 + conn = dataSource.getConnection(); // datasource를 사용하게 변경 + ps = new DeleteAllStrategy().makepreparedStatement(conn); + ps.executeUpdate(); + } catch (SQLException e) { + throw new RuntimeException(e); + }finally { // error 발생해도 실행함 + if(ps != null){ + try { + ps.close(); + } catch (SQLException e) { + } + } + + if(conn != null){ + try { + conn.close(); + } catch (SQLException e) { + } + } + } + } + +// public void deleteAll() throws SQLException, ClassNotFoundException { // DB 모든값 삭제 +// jdbcContextWithStatementStatementstrategy(new StatementStrategy() { +// @Override +// public PreparedStatement makepreparedStatement(Connection connection) throws SQLException { +// return connection.prepareStatement(); +// } +// }); +// } + + public int getCount() throws SQLException, ClassNotFoundException { // user테이블의 레코드 개수를 구하기 + Connection conn = null; + PreparedStatement ps = null; + ResultSet rs = null; + try { + conn = dataSource.getConnection(); + ps = conn.prepareStatement("select count(*) from users "); + rs = ps.executeQuery(); + rs.next(); + return rs.getInt(1); + + } catch (SQLException e) { + throw new RuntimeException(e); + } finally { + if(rs != null) { + try { + rs.close(); + } catch (SQLException e) { + } + } + if(ps != null){ + try { + ps.close(); + } catch (SQLException e) { + } + } + + if(conn != null){ + try { + conn.close(); + } catch (SQLException e) { + } + } + } + } + + public void add(User user) throws ClassNotFoundException, SQLException { + AddStrategy addStrategy = new AddStrategy(user); // User DTO에 저장되어 있는 값 가져옴 + jdbcContextWithStatementStatementstrategy(addStrategy); // add 쿼리문과 추가할 값 가져와서 대입 + + System.out.println("데이터가 insert 됬습니다"); + } + + public User select(String id) throws SQLException, ClassNotFoundException { + + Connection conn = null; + PreparedStatement ps = null; + ResultSet rs = null; // 쿼리문을 저장함 insert문과 달리 excuteQuery() 사용 + User user = null; + try { + conn = dataSource.getConnection(); + ps = conn.prepareStatement("SELECT id,name,password FROM users WHERE id = ?"); + ps.setString(1, id); // id는 get(String id)로 받은 id + rs = ps.executeQuery(); + // rs에는 쿼리 실행 결과가 담겨져 있다. (select * from users where id = 1;) + rs.next(); + // User 생성자를 통해 쿼리문에 id값을 넣어 찾은 id, name,password 값을 저장한다. + return new User(rs.getString("id"), rs.getString("name"), rs.getString("password")); + } + catch (SQLException e) { + throw new RuntimeException(e); + } + finally { + if(rs != null) { + try { + rs.close(); + } catch (SQLException e) { + } + } + if(ps != null){ + try { + ps.close(); + } catch (SQLException e) { + } + } + + if(conn != null){ + try { + conn.close(); + } catch (SQLException e) { + } + } + } + } +} \ No newline at end of file diff --git a/Project/src/main/java/Date10_24/Factory/UserDaoFactory.java b/Project/src/main/java/Date10_24/Factory/UserDaoFactory.java new file mode 100644 index 0000000..407fef5 --- /dev/null +++ b/Project/src/main/java/Date10_24/Factory/UserDaoFactory.java @@ -0,0 +1,54 @@ +package Date10_24.Factory; + + +// 인터페이스로 받은 것을 어떤것을 UserDaoInterface로 넘겨줄것인지 설정 +// 즉, 인터페이스로 DB별 연결 설정을 나눠놨는데 여기서 메서드별로 다시 DB별로 나누어 +// UserDaoInterface로 해당 DB 연결 설정 값을 보냄 + +// DB설정 파일을 따로 만들지 않고 Bean 파일에서 한번에 사용할수 있도록 리팩토링 + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.datasource.SimpleDriverDataSource; + +import javax.sql.DataSource; +import java.util.Map; + +@Configuration +public class UserDaoFactory { + + @Bean + public UserDao awsUserDao(){ + return new UserDao(awsDataSource()); + } + + @Bean + public UserDao localUserDao(){ + return new UserDao(localDataSource()); + } + + @Bean + DataSource awsDataSource(){ + Map env = System.getenv(); + SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); + dataSource.setDriverClass(com.mysql.cj.jdbc.Driver.class); + dataSource.setUrl(env.get("DB_HOST")); + dataSource.setUsername(env.get("DB_USER")); + dataSource.setPassword(env.get("DB_PASSWORD")); + return dataSource; + } + + @Bean + + DataSource localDataSource() { + Map env = System.getenv(); + SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); + dataSource.setDriverClass(com.mysql.cj.jdbc.Driver.class); + dataSource.setUrl("localhost"); + dataSource.setUsername("root"); + dataSource.setPassword("12345678"); + return dataSource; + } + + +} diff --git a/Project/src/main/java/Date10_24/domain/User.java b/Project/src/main/java/Date10_24/domain/User.java new file mode 100644 index 0000000..f83fb85 --- /dev/null +++ b/Project/src/main/java/Date10_24/domain/User.java @@ -0,0 +1,32 @@ +package Date10_24.domain; + +public class User { + private String id; + private String name; + private String password; + + public User() { + } + + public User(String id, String name, String password) { + this.id = id; + this.name = name; + this.password = password; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getPassword() { + return password; + } + + public String toString(){ + return "id = "+this.id + " name = "+this.name+" password = "+this.password; + } +} From 0e9a256c85a14d21e0666518e2557efaaaef4cc2 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 27 Oct 2022 10:00:52 +0900 Subject: [PATCH 254/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20Hash(2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_27/Algorithm/UnfinishedPlayer.java | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/Project/src/main/java/Date10_27/Algorithm/UnfinishedPlayer.java b/Project/src/main/java/Date10_27/Algorithm/UnfinishedPlayer.java index d67ff04..a2a510d 100644 --- a/Project/src/main/java/Date10_27/Algorithm/UnfinishedPlayer.java +++ b/Project/src/main/java/Date10_27/Algorithm/UnfinishedPlayer.java @@ -1,9 +1,39 @@ package Date10_27.Algorithm; -/* 프로그래머스 완주하지 못한 선수 문제 - +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +/* 프로그래머스 완주하지 못한 선수 문제 + 1. 배열로 참가인원 명단 받음 + 2. 완주자 명단 배열로 받음 + 3. 참가인원 명단에서 완주자명단을 제외한 명단을 리턴해줌 */ public class UnfinishedPlayer { - + public String solution(String[] participant, String[] completion) { + Map memo = new HashMap<>(); + + for(int i=0; i iterator = memo.keySet().iterator(); + String key = null; + + while(iterator.hasNext()){ + key = iterator.next(); + } + + return key; + } } From 85c19828d3b9a482bea29040faf8ecfe32d00adc Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 27 Oct 2022 10:01:04 +0900 Subject: [PATCH 255/307] TDD Hash(2) --- .../Algorithm/UnfinishedPlayerTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Project/src/test/java/Date10_27/Algorithm/UnfinishedPlayerTest.java diff --git a/Project/src/test/java/Date10_27/Algorithm/UnfinishedPlayerTest.java b/Project/src/test/java/Date10_27/Algorithm/UnfinishedPlayerTest.java new file mode 100644 index 0000000..0449adc --- /dev/null +++ b/Project/src/test/java/Date10_27/Algorithm/UnfinishedPlayerTest.java @@ -0,0 +1,22 @@ +package Date10_27.Algorithm; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class UnfinishedPlayerTest { + + @Test + @DisplayName("명단, 완주명단 입력") + void runner(){ + UnfinishedPlayer up = new UnfinishedPlayer(); + String[] participant = {"mislav", "stanko", "mislav", "ana"}; + String[] completion = {"stanko", "ana", "mislav"}; + + String result = up.solution(participant,completion); + + Assertions.assertEquals("mislav",result); + } +} \ No newline at end of file From a20ba26e0f9a2b1771702e0ea61cea30ad1a70ac Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Thu, 27 Oct 2022 10:54:36 +0900 Subject: [PATCH 256/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20Hash(2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_27/Algorithm/UnfinishedPlayer.java | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/Project/src/main/java/Date10_27/Algorithm/UnfinishedPlayer.java b/Project/src/main/java/Date10_27/Algorithm/UnfinishedPlayer.java index a2a510d..d63f1ad 100644 --- a/Project/src/main/java/Date10_27/Algorithm/UnfinishedPlayer.java +++ b/Project/src/main/java/Date10_27/Algorithm/UnfinishedPlayer.java @@ -1,7 +1,6 @@ package Date10_27.Algorithm; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; /* 프로그래머스 완주하지 못한 선수 문제 @@ -11,29 +10,35 @@ */ public class UnfinishedPlayer { public String solution(String[] participant, String[] completion) { - Map memo = new HashMap<>(); + Map memo = new HashMap<>(); - for(int i=0; i iterator = memo.keySet().iterator(); - String key = null; + String person = null; - while(iterator.hasNext()){ - key = iterator.next(); + for (String key : memo.keySet()) { + if (memo.get(key) == 1) + person = key; } - - return key; + return person; } } From 7ccdf3a62ef6b399989476f99bfe4671009c4782 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Thu, 27 Oct 2022 22:48:26 +0900 Subject: [PATCH 257/307] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d176398..7a6fe12 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ https://github.com/Bae-Ji-Won/Spring-Study - 2022-10-25 : 알고리즘[Hash] - 2022-10-26 : 알고리즘[Hash Collistion] + +- 2022-10-27 : 알고리즘[Hash(3)] - (프로그래머스) 완주하지 못한 선수 문제
# ⚙️ 기술 스택 From c36754667224a334ec21fc49c5db3bc5406fa8b0 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Fri, 28 Oct 2022 09:43:58 +0900 Subject: [PATCH 258/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20Hash(3)=20-=20=ED=8F=B0=EC=BC=93=EB=AA=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date10_28/Algorithm/Pokemon.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Project/src/main/java/Date10_28/Algorithm/Pokemon.java diff --git a/Project/src/main/java/Date10_28/Algorithm/Pokemon.java b/Project/src/main/java/Date10_28/Algorithm/Pokemon.java new file mode 100644 index 0000000..ebeab4c --- /dev/null +++ b/Project/src/main/java/Date10_28/Algorithm/Pokemon.java @@ -0,0 +1,22 @@ +package Date10_28.Algorithm; + +/* 프로그래머스 해쉬 - 폰켓몬 + 1. 폰켓몬의 종류가 담긴 배열이 주어짐 + 2. 다른종류의 폰켓몬을 고를 수 있는 횟수의 최댓값을 구함 + ex. {1,2,3,3} 1번 폰켓몬 = 1마리, 2번 폰켓몬 = 1마리,3번 폰켓몬 = 2마리 일떄 + 폰켓몬은 4/2 = 2마리를 선택할 수 있다. + 이때 서로 다른 폰켓몬을 가져가야 하는 상황은 + 1,2 + 1,3 + 2,3 이므로 + 최대 다른 종류의 2가지 폰켓몬을 가져갈 수 있다. + */ +public class Pokemon { + public int choosemax(String[] str){ + int count = (str.length)/2; // 선택할 수 있는 폰켓몬 수 + + Set + + return 0; + } +} From 57d30260a2ffec59b307f86d43b0b9b54c7d5b4a Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Fri, 28 Oct 2022 09:58:44 +0900 Subject: [PATCH 259/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20Hash(3)=20-=20=ED=8F=B0=EC=BC=93=EB=AA=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date10_28/Algorithm/Pokemon.java | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/Project/src/main/java/Date10_28/Algorithm/Pokemon.java b/Project/src/main/java/Date10_28/Algorithm/Pokemon.java index ebeab4c..d70f77d 100644 --- a/Project/src/main/java/Date10_28/Algorithm/Pokemon.java +++ b/Project/src/main/java/Date10_28/Algorithm/Pokemon.java @@ -1,5 +1,10 @@ package Date10_28.Algorithm; +import java.lang.reflect.Array; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + /* 프로그래머스 해쉬 - 폰켓몬 1. 폰켓몬의 종류가 담긴 배열이 주어짐 2. 다른종류의 폰켓몬을 고를 수 있는 횟수의 최댓값을 구함 @@ -12,11 +17,29 @@ 최대 다른 종류의 2가지 폰켓몬을 가져갈 수 있다. */ public class Pokemon { - public int choosemax(String[] str){ - int count = (str.length)/2; // 선택할 수 있는 폰켓몬 수 + public int choosemax(int[] nums){ + int count = (nums.length)/2; // 선택할 수 있는 폰켓몬 수 + + Set set = new HashSet<>(); - Set + for(int num:nums){ // nums의 배열을 1개씩 set에 넣어줌 + // set의 특성을 활용해 중복 제거 + set.add(num); + } + + int answer = (set.size()>count)? count:set.size(); + + return answer; + } + + public static void main(String[] args) { + Pokemon p = new Pokemon(); + int result1 = p.choosemax(new int[]{3,1,2,3}); + int result2 = p.choosemax(new int[]{3,3,3,2,2,4}); + int result3 = p.choosemax(new int[]{3,3,3,2,2,2}); - return 0; + System.out.println(result1); + System.out.println(result2); + System.out.println(result3); } } From a7ca849688ee2eee100cdc8f1dc5f0c79b3af019 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Fri, 28 Oct 2022 10:00:20 +0900 Subject: [PATCH 260/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20Hash(3)=20-=20=ED=8F=B0=EC=BC=93=EB=AA=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/src/main/java/Date10_28/Algorithm/Pokemon.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Project/src/main/java/Date10_28/Algorithm/Pokemon.java b/Project/src/main/java/Date10_28/Algorithm/Pokemon.java index d70f77d..3c52bf1 100644 --- a/Project/src/main/java/Date10_28/Algorithm/Pokemon.java +++ b/Project/src/main/java/Date10_28/Algorithm/Pokemon.java @@ -28,6 +28,7 @@ public int choosemax(int[] nums){ } int answer = (set.size()>count)? count:set.size(); + // set의 크기가 count보다 클경우 count 출력, 작을경우 set 원소개수 출력 return answer; } From bbb8c58a4dfbbd54a91270be517106bef9f6866b Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Fri, 28 Oct 2022 11:02:13 +0900 Subject: [PATCH 261/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20Hash(4)=20-=20=EC=A0=84=ED=99=94=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date10_28/Algorithm/CallBook.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Project/src/main/java/Date10_28/Algorithm/CallBook.java diff --git a/Project/src/main/java/Date10_28/Algorithm/CallBook.java b/Project/src/main/java/Date10_28/Algorithm/CallBook.java new file mode 100644 index 0000000..f379ea9 --- /dev/null +++ b/Project/src/main/java/Date10_28/Algorithm/CallBook.java @@ -0,0 +1,39 @@ +package Date10_28.Algorithm; + +import java.util.HashSet; +import java.util.Set; + +/* 프로그래머스 해시-전화번호 목록 + 1. 전화번호가 적인 값을 배열로 받음 + 2. 각 자리에 있는 전화번호가 다른 전화번호의 접두어인지 판별 + 3. 결과 출력 + */ +public class CallBook { + public Boolean solution(String[] phone_book){ + Set set= new HashSet<>(); + + for(String phone : phone_book) + set.add(phone); // HashSet에 저장 + + for(int i=0; i Date: Fri, 28 Oct 2022 11:05:38 +0900 Subject: [PATCH 262/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20Hash(4)=20-=20=EC=A0=84=ED=99=94=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/src/main/java/Date10_28/Algorithm/CallBook.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Project/src/main/java/Date10_28/Algorithm/CallBook.java b/Project/src/main/java/Date10_28/Algorithm/CallBook.java index f379ea9..ca048eb 100644 --- a/Project/src/main/java/Date10_28/Algorithm/CallBook.java +++ b/Project/src/main/java/Date10_28/Algorithm/CallBook.java @@ -15,9 +15,9 @@ public Boolean solution(String[] phone_book){ for(String phone : phone_book) set.add(phone); // HashSet에 저장 - for(int i=0; i Date: Sat, 29 Oct 2022 20:29:15 +0900 Subject: [PATCH 263/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20Hash(4)=20-=20=EC=A0=84=ED=99=94=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/src/main/java/Date10_28/Algorithm/CallBook.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Project/src/main/java/Date10_28/Algorithm/CallBook.java b/Project/src/main/java/Date10_28/Algorithm/CallBook.java index ca048eb..ff46d0d 100644 --- a/Project/src/main/java/Date10_28/Algorithm/CallBook.java +++ b/Project/src/main/java/Date10_28/Algorithm/CallBook.java @@ -16,9 +16,16 @@ public Boolean solution(String[] phone_book){ set.add(phone); // HashSet에 저장 for(int i=0; i Date: Mon, 31 Oct 2022 09:41:01 +0900 Subject: [PATCH 264/307] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]?= =?UTF-8?q?=20=EC=99=84=EC=A0=84=ED=83=90=EC=83=89(1)=20-=20=EC=B2=AB?= =?UTF-8?q?=EB=B2=88=EC=A7=B8=20=ED=95=99=EC=83=9D=20=EA=B0=92=20=EB=B9=84?= =?UTF-8?q?=EA=B5=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date10_31/Algorithm/SearchFull.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Project/src/main/java/Date10_31/Algorithm/SearchFull.java diff --git a/Project/src/main/java/Date10_31/Algorithm/SearchFull.java b/Project/src/main/java/Date10_31/Algorithm/SearchFull.java new file mode 100644 index 0000000..6cc8bb8 --- /dev/null +++ b/Project/src/main/java/Date10_31/Algorithm/SearchFull.java @@ -0,0 +1,34 @@ +package Date10_31.Algorithm; + +/* 프로그래머스 완전탐색-모의고사 + +1번 수포자가 찍는 방식: 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ... +2번 수포자가 찍는 방식: 2, 1, 2, 3, 2, 4, 2, 5, 2, 1, 2, 3, 2, 4, 2, 5, ... +3번 수포자가 찍는 방식: 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, ... + +위와 같이 서로 다른 방식으로 문제의 답을 찍어나갈때 3명의 학생중 누가 가장 많이 맞추는지 알아내라 + */ + +public class SearchFull { + public int solution(int[] answers) { + int[] user1 = {1,2,3,4,5}; + + int firststudent = 0; + + for(int i=0; i Date: Tue, 1 Nov 2022 10:02:33 +0900 Subject: [PATCH 265/307] =?UTF-8?q?TestCase(=EC=99=84=EC=A0=84=ED=83=90?= =?UTF-8?q?=EC=83=89)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date10_31/Algorithm/SearchFull2Test.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Project/src/test/java/Date10_31/Algorithm/SearchFull2Test.java diff --git a/Project/src/test/java/Date10_31/Algorithm/SearchFull2Test.java b/Project/src/test/java/Date10_31/Algorithm/SearchFull2Test.java new file mode 100644 index 0000000..19a6aa4 --- /dev/null +++ b/Project/src/test/java/Date10_31/Algorithm/SearchFull2Test.java @@ -0,0 +1,33 @@ +package Date10_31.Algorithm; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.*; + + + +class SearchFull2Test { + + @Test + @DisplayName("제일많이 맞춘사람 1명일때") + void onecheck(){ + SearchFull2 sf = new SearchFull2(); + + int[] answers = {1,2,3,4,5}; + + assertEquals("[1]",Arrays.toString(sf.solution(answers))); + } + + @Test + @DisplayName("제일많이 맞춘사람 1명 이상 일때") + void twocheck(){ + SearchFull2 sf = new SearchFull2(); + + int[] answers2 = {1,3,2,4,2}; + + assertEquals("[1, 2, 3]",Arrays.toString(sf.solution(answers2))); + } +} \ No newline at end of file From dec3c961df37322cbd48868c77e26a4b2500b80a Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 1 Nov 2022 10:03:37 +0900 Subject: [PATCH 266/307] Exhaustive Search - Array --- .../java/Date10_31/Algorithm/SearchFull.java | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/Project/src/main/java/Date10_31/Algorithm/SearchFull.java b/Project/src/main/java/Date10_31/Algorithm/SearchFull.java index 6cc8bb8..0a62063 100644 --- a/Project/src/main/java/Date10_31/Algorithm/SearchFull.java +++ b/Project/src/main/java/Date10_31/Algorithm/SearchFull.java @@ -9,26 +9,49 @@ 위와 같이 서로 다른 방식으로 문제의 답을 찍어나갈때 3명의 학생중 누가 가장 많이 맞추는지 알아내라 */ +import java.util.*; + public class SearchFull { - public int solution(int[] answers) { - int[] user1 = {1,2,3,4,5}; + public int[] solution(int[] answers) { - int firststudent = 0; + int[] user1 = {1,2,3,4,5}; + int[] user2 = {2,1,2,3,2,4,2,5}; + int[] user3 = {3,3,1,1,2,2,4,4,5,5}; + + int[] temp = {0,0,0}; + + for (int i = 0; i < answers.length; i++) { + if(answers[i] == user1[i%user1.length]) + temp[0]++; + if(answers[i] == user2[i%user2.length]) + temp[1]++; + if(answers[i] == user3[i%user3.length]) + temp[2]++; + } - for(int i=0; i maxScore = new ArrayList<>(); + // 최대값이 중복일 경우 리스트에 추가해줌 + for(int i=0; i Arrays + int[] result = new int[maxScore.size()]; + for(int i =0; i Date: Tue, 1 Nov 2022 10:03:49 +0900 Subject: [PATCH 267/307] Exhaustive Search - String --- .../java/Date10_31/Algorithm/SearchFull2.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Project/src/main/java/Date10_31/Algorithm/SearchFull2.java diff --git a/Project/src/main/java/Date10_31/Algorithm/SearchFull2.java b/Project/src/main/java/Date10_31/Algorithm/SearchFull2.java new file mode 100644 index 0000000..2d4cd22 --- /dev/null +++ b/Project/src/main/java/Date10_31/Algorithm/SearchFull2.java @@ -0,0 +1,40 @@ +package Date10_31.Algorithm; + +import java.util.ArrayList; +import java.util.List; + +public class SearchFull2 { + public int[] solution(int[] answers) { + String answerPattern1 = "12345".repeat(2000); + String answerPattern2 = "21232425".repeat(1250); + String answerPattern3 = "3311224455".repeat(1000); + + // 공간복잡도로 속도를 높이는 방법 + int[] count = {0,0,0}; + + // 각 사람마다 작성한 답안지를 채점함 + // 답이 맞으면 결과 배열의 값을 1씩 증가함 + for (int i = 0; i < answers.length; i++) { + if(Character.getNumericValue(answerPattern1.charAt(i)) == answers[i]) count[0] ++; + if(Character.getNumericValue(answerPattern2.charAt(i)) == answers[i]) count[1] ++; + if(Character.getNumericValue(answerPattern3.charAt(i)) == answers[i]) count[2] ++; + } + + // 중복 검사 + List maxscorelist = new ArrayList<>(); + int maxscore = Math.max(count[0],Math.max(count[1], count[2])); + + for(int i=0; i int[] + int[] result = maxscorelist.stream() + .mapToInt(Integer::intValue) + .toArray(); + + return result; + } +} From 042ccb54a563d7f78936a8252bcb5e86e8545bd2 Mon Sep 17 00:00:00 2001 From: Bae-Ji-Won Date: Tue, 1 Nov 2022 10:04:15 +0900 Subject: [PATCH 268/307] =?UTF-8?q?=EC=86=8C=EC=88=98=EC=B0=BE=EA=B8=B0=20?= =?UTF-8?q?-=2013=20=EC=86=8C=EC=88=98=20=EC=9D=BC=EC=B9=98=20=EC=97=AC?= =?UTF-8?q?=EB=B6=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date11_01/Algorithm/PrimeNumber.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Project/src/main/java/Date11_01/Algorithm/PrimeNumber.java diff --git a/Project/src/main/java/Date11_01/Algorithm/PrimeNumber.java b/Project/src/main/java/Date11_01/Algorithm/PrimeNumber.java new file mode 100644 index 0000000..b4bedaf --- /dev/null +++ b/Project/src/main/java/Date11_01/Algorithm/PrimeNumber.java @@ -0,0 +1,25 @@ +package Date11_01.Algorithm; + + +/* 프로그래머스 소수찾기 +1부터 입력받은 숫자 n 사이에 있는 소수의 개수를 반환하는 문제 +소수는 1과 자기 자신으로만 나누어지는 수를 의미 +(1은 소수가 아니다) +ex) 1~10일때 [2,3,5,7] = 4개가 존재 + + */ +public class PrimeNumber { + boolean isPrime(int num){ + for(int i = 2; i Date: Tue, 1 Nov 2022 10:40:14 +0900 Subject: [PATCH 269/307] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7a6fe12..f8c0775 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ https://github.com/Bae-Ji-Won/Spring-Study - 2022-10-26 : 알고리즘[Hash Collistion] - 2022-10-27 : 알고리즘[Hash(3)] - (프로그래머스) 완주하지 못한 선수 문제 + +- 2022-10-28 : 알고리즘[Hash(4)] - (프로그래머스) 폰켓몬, 전화번호 목록
# ⚙️ 기술 스택 From 24da4f1f3b0b437e05098b6b49de4d0956732a87 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Tue, 1 Nov 2022 10:40:48 +0900 Subject: [PATCH 270/307] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f8c0775..a788af6 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ https://github.com/Bae-Ji-Won/Spring-Study - 2022-10-27 : 알고리즘[Hash(3)] - (프로그래머스) 완주하지 못한 선수 문제 - 2022-10-28 : 알고리즘[Hash(4)] - (프로그래머스) 폰켓몬, 전화번호 목록 + +- 2022-10-31 : 알고리즘[완전탐색] - (프로그래머스) 모의고사
# ⚙️ 기술 스택 From aceadca7c7828f2f153d10b5bd99e6b6d1e165d9 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Thu, 3 Nov 2022 09:16:21 +0900 Subject: [PATCH 271/307] Update README.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index a788af6..59d5917 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,13 @@ https://github.com/Bae-Ji-Won/Spring-Study - 2022-10-28 : 알고리즘[Hash(4)] - (프로그래머스) 폰켓몬, 전화번호 목록 - 2022-10-31 : 알고리즘[완전탐색] - (프로그래머스) 모의고사 + +- 2022-11-01 : 알고리즘[연습문제] - (프로그래머스) 소수찾기 + +- 2022-11-02 : 알고리즘[연습문제(2)] - (프로그래머스) 에라토스테네스의 체를 통한 소수찾기 + +- 2022-11-03 : 알고리즘 +
# ⚙️ 기술 스택 From a580819deb9f5ede913ed1549edc7e583139054c Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Sun, 6 Nov 2022 20:34:55 +0900 Subject: [PATCH 272/307] Update PrimeNumber.java --- Project/src/main/java/Date11_01/Algorithm/PrimeNumber.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project/src/main/java/Date11_01/Algorithm/PrimeNumber.java b/Project/src/main/java/Date11_01/Algorithm/PrimeNumber.java index b4bedaf..db526e9 100644 --- a/Project/src/main/java/Date11_01/Algorithm/PrimeNumber.java +++ b/Project/src/main/java/Date11_01/Algorithm/PrimeNumber.java @@ -5,7 +5,7 @@ 1부터 입력받은 숫자 n 사이에 있는 소수의 개수를 반환하는 문제 소수는 1과 자기 자신으로만 나누어지는 수를 의미 (1은 소수가 아니다) -ex) 1~10일때 [2,3,5,7] = 4개가 존재 +ex) 1~10일때 [2,3,5,7] = 4개가 존재 */ public class PrimeNumber { From 835d927dcfc0b2b6f0534792a5ef4b85c48765ea Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Mon, 7 Nov 2022 11:31:22 +0900 Subject: [PATCH 273/307] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 59d5917..8276c0d 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ https://github.com/Bae-Ji-Won/Spring-Study - 2022-11-02 : 알고리즘[연습문제(2)] - (프로그래머스) 에라토스테네스의 체를 통한 소수찾기 -- 2022-11-03 : 알고리즘 +- 2022-11-03 : 알고리즘[연습문제(2)] - (프로그래머스) 에라토스테네스의 체를 통한 소수찾기 완성
From bbacda0ddbce51ca9416a524b6b99e1af2734ed1 Mon Sep 17 00:00:00 2001 From: Bae Ji Won Date: Wed, 9 Nov 2022 10:53:09 +0900 Subject: [PATCH 274/307] =?UTF-8?q?=EC=86=8C=EC=88=98=EC=B0=BE=EA=B8=B0=20?= =?UTF-8?q?-=201=EB=8B=A8=EA=B3=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/Date11_01/Algorithm/PrimeNumber.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Project/src/main/java/Date11_01/Algorithm/PrimeNumber.java b/Project/src/main/java/Date11_01/Algorithm/PrimeNumber.java index b4bedaf..0deed02 100644 --- a/Project/src/main/java/Date11_01/Algorithm/PrimeNumber.java +++ b/Project/src/main/java/Date11_01/Algorithm/PrimeNumber.java @@ -8,10 +8,14 @@ ex) 1~10일때 [2,3,5,7] = 4개가 존재 */ + + public class PrimeNumber { boolean isPrime(int num){ + // 1은 소수가 아니니 2부터 자기자신보다 1작은수까지 나누어 나머지값을 구한다 + // 만약 이때 나머지 값이 0이 나온다면 소수가 아니므로 false 출력 for(int i = 2; i Date: Wed, 9 Nov 2022 10:54:00 +0900 Subject: [PATCH 275/307] =?UTF-8?q?=EC=86=8C=EC=88=98=EC=B0=BE=EA=B8=B0=20?= =?UTF-8?q?-=202=EB=8B=A8=EA=B3=84(=EC=97=90=EB=9D=BC=ED=86=A0=EC=8A=A4?= =?UTF-8?q?=ED=85=8C=EB=84=A4=EC=8A=A4=20=EC=B2=B4=20=EC=82=AC=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date11_02/Algorithm/PrimeNumber.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Project/src/main/java/Date11_02/Algorithm/PrimeNumber.java diff --git a/Project/src/main/java/Date11_02/Algorithm/PrimeNumber.java b/Project/src/main/java/Date11_02/Algorithm/PrimeNumber.java new file mode 100644 index 0000000..3b3976c --- /dev/null +++ b/Project/src/main/java/Date11_02/Algorithm/PrimeNumber.java @@ -0,0 +1,44 @@ +package Date11_02.Algorithm; + +import java.util.ArrayList; +import java.util.List; + +/* 프로그래머스 소수찾기 (에라토스테네스의 체를 통한 풀이) + 소수가 아닌 값을 제외시켜 최종적으로 소수인 값만 남기는 방식 + + 이전에 했던 코드가 O(N)이라면 에라토스테네스의 체는 O(Log N)정도의 속도가 나온다. + */ +public class PrimeNumber { + + // 리스트를 통한 풀이 + public int solution(int num){ + List nums = new ArrayList<>(); + + // 1은 소수가 아니므로 2부터 시작 + for(int i =2; i<=num; i++){ + nums.add(i); + } + + // removeif( ) list의 메서드로 조건문을 통해 해당하는 값은 제거시킨다. + + // 2부터 num-1번값까지 + // 일반 for문으로 i<=num으로 돌리면 num값이 클경우 너무 많은 반복을 하게됨 + // 따라서 i의 제곱이 num보다 작거나 같을때까지 반복하게 되면 모든 소수를 찾을 수 있고 반복횟수도 적어짐 + // ex) num = 10일때, i는 2,3만 들어갈수 있음 + // + for(int i=2; i*i<=num; i++) { + for (int j = 0; j < nums.size(); j++) { + // 배수이면서 자기자신은 아니여야 함 + if (nums.get(j) % i == 0 && nums.get(j) != i) { + nums.remove(j); + } + } + } + return nums.size(); + } + + public static void main(String[] args) { + PrimeNumber p = new PrimeNumber(); + System.out.println(p.solution(10)); // 시간초과 발생 + } +} From 3e8dc8a9d815f4591df7e4108d1b1b7d334d334a Mon Sep 17 00:00:00 2001 From: Bae Ji Won Date: Wed, 9 Nov 2022 10:54:19 +0900 Subject: [PATCH 276/307] =?UTF-8?q?=EC=86=8C=EC=88=98=EC=B0=BE=EA=B8=B0=20?= =?UTF-8?q?-=203=EB=8B=A8=EA=B3=84(=EC=97=90=EB=9D=BC=ED=86=A0=EC=8A=A4?= =?UTF-8?q?=ED=85=8C=EB=84=A4=EC=8A=A4=20=EC=B2=B4=20=EC=82=AC=EC=9A=A9)?= =?UTF-8?q?=20=EC=B5=9C=EC=A2=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date11_03/Algorithm/PrimeNumber.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Project/src/main/java/Date11_03/Algorithm/PrimeNumber.java diff --git a/Project/src/main/java/Date11_03/Algorithm/PrimeNumber.java b/Project/src/main/java/Date11_03/Algorithm/PrimeNumber.java new file mode 100644 index 0000000..96c2b5b --- /dev/null +++ b/Project/src/main/java/Date11_03/Algorithm/PrimeNumber.java @@ -0,0 +1,47 @@ +package Date11_03.Algorithm; + + +import java.util.Arrays; + +/* 프로그래머스 소수찾기 (에라토스테네스의 체를 통한 풀이) + 이전에 했던 리스트를 통한 에라토스테네스의 체를 통한 풀이는 속도가 느려 통과가 안되는 문제가 발생했다 + 따라서 배열을 통해 속도를 좀 더 높힐 수 있도록 했다. + */ +public class PrimeNumber { + public int solution(int num) { + + int count = 0; + boolean[] result = new boolean[num+1]; // 0~n까지 크기 + Arrays.fill(result,true); // 배열 true로 채움(boolean 배열의 초기값은 false라 굳이 안채워줘도 되지만 라이브러리 사용을 위해 사용) + + + // 0과 1은 소수가 아니므로 false를 넣어준다. + result[0] = false; + result[1] = false; + + // n의 제곱근보다 작은 정수의 배수들만 지우면 n보다 작은 소수만 남게 됨 + for(int i= 2; i*i<=num; i++){ // 2~7까지의 배수값 구함 7*7 = 49 + + // j = i*i로 해줘야 자기 자신값은 제외가 됨. 2,3,5,7은 소수이므로 자기 자신의 값은 제외해야함 + // ex) i=2일때, 2는 소수이므로 4부터 시작하여 4,6,8,10... 값을 false로 대입 + // i=4일때, 어차피 4는 i=2일때 false를 대입했으므로 자기 자신의 값을 신경안써줘도 됨 + for(int j =i*i; j Date: Wed, 9 Nov 2022 10:55:26 +0900 Subject: [PATCH 277/307] =?UTF-8?q?=EC=86=8C=EC=88=98=EC=B0=BE=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AnonymousClassInPrimeNumber.java | 30 +++++++++++++ .../Algorithm/TemplateCallbackPrime.java | 42 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 Project/src/main/java/Date11_01/Algorithm/AnonymousClassInPrimeNumber.java create mode 100644 Project/src/main/java/Date11_01/Algorithm/TemplateCallbackPrime.java diff --git a/Project/src/main/java/Date11_01/Algorithm/AnonymousClassInPrimeNumber.java b/Project/src/main/java/Date11_01/Algorithm/AnonymousClassInPrimeNumber.java new file mode 100644 index 0000000..636d168 --- /dev/null +++ b/Project/src/main/java/Date11_01/Algorithm/AnonymousClassInPrimeNumber.java @@ -0,0 +1,30 @@ +package Date11_01.Algorithm; + +// inteface 포함 +interface Strategy{ + boolean compare(int a, int b); +} + +public class AnonymousClassInPrimeNumber { + boolean isPrime(int num, Strategy stmt) { + for (int i = 2; stmt.compare(i, num); i++) { + System.out.println(i); + if(num % i == 0) return false; + } + return true; + } + + public static void main(String[] args) { + AnonymousClassInPrimeNumber acip = new AnonymousClassInPrimeNumber(); + //람다 사용 + boolean r = acip.isPrime(17,(a,b)->a*a<=b); + +// boolean r = acip.isPrime(17, new Strategy() { +// @Override +// public boolean compare(int a, int b) { +// return a * a <= b; +// } +// }); + + } +} \ No newline at end of file diff --git a/Project/src/main/java/Date11_01/Algorithm/TemplateCallbackPrime.java b/Project/src/main/java/Date11_01/Algorithm/TemplateCallbackPrime.java new file mode 100644 index 0000000..f45ef5a --- /dev/null +++ b/Project/src/main/java/Date11_01/Algorithm/TemplateCallbackPrime.java @@ -0,0 +1,42 @@ +//package Date11_01.Algorithm; +// +//interface StatementStrategy{ +// //인터페이스 이용 +// boolean compare(int a , int b); +//} +// +//public class TemplateCallbackPrime { +// //Template Callback +// boolean someOperation(int a, int b) { +// return a < b; +// } +// +// boolean isPrime(int num){ +// boolean isPrime(int num,StatementStrategy stmt){ +// // i < num +// // i < num/2 +// // i*i < num i * i 쓰는이유 i*i a < b)); +// System.out.println(tcp.isPrime(17, (a, b)-> a < b/2)); +// System.out.println(tcp.isPrime(19, (a, b)-> a * a < b)); +// +//// @Override +//// boolean b = tcp.isPrime(17, new StatementStrategy() { +//// public boolean compare(int a, int b) { +//// return a * a <= b; +//// } +//// }); +// +// } +// } \ No newline at end of file From cf884e8c9fdd23d7d1834ef44069c17b3c212d55 Mon Sep 17 00:00:00 2001 From: Bae Ji Won Date: Wed, 9 Nov 2022 10:55:41 +0900 Subject: [PATCH 278/307] =?UTF-8?q?=ED=95=98=EC=83=A4=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=20=EC=B0=BE=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date11_07/Algorithm/Harshad.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Project/src/main/java/Date11_07/Algorithm/Harshad.java diff --git a/Project/src/main/java/Date11_07/Algorithm/Harshad.java b/Project/src/main/java/Date11_07/Algorithm/Harshad.java new file mode 100644 index 0000000..1828a3e --- /dev/null +++ b/Project/src/main/java/Date11_07/Algorithm/Harshad.java @@ -0,0 +1,49 @@ +package Date11_07.Algorithm; + +/* + 프로그래머스 하샤드문제 + 1. 입력받은 수의 자릿값들을 더함 + 2. 입력받은 수를 자릿값들의 합으로 나눔 + 3. 이때 값이 딱 떨어지게 나누어지면 하샤드 수임 + */ +public class Harshad { + // int로 값을 받아 계산하는 방식 + public boolean solution(int x){ + + int num = x; + // 자리수 합 + int sumOfDigit = 0; // 자릿수 합 + while(x>0){ + sumOfDigit += x%10; + x = x/10; + } + + if(num%sumOfDigit == 0){ + return true; + } + + return false; + } + + //String으로 값을 받아 계산하는 방식 + public boolean solution2(int x){ + String[] num = String.valueOf(x).split(""); // 입력받은 숫자를 문자열 배열 한자리씩 나눔 + + int sum = 0; + for(String s : num){ // 문자열 배열에 저장된 자릿수의 값들을 한개씩 뽑아 모두 더함 + sum += Integer.parseInt(s); + } + + if(x%sum == 0){ + return true; + } + + return false; + } + + public static void main(String[] args) { + Harshad hs = new Harshad(); + System.out.println(hs.solution2(10)); + System.out.println(hs.solution2(11)); + } +} From f4d05c5df12373e0de0dbbb168666d6d4389d176 Mon Sep 17 00:00:00 2001 From: Bae Ji Won Date: Wed, 9 Nov 2022 10:56:03 +0900 Subject: [PATCH 279/307] =?UTF-8?q?=ED=95=98=EC=83=A4=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=20=EC=B0=BE=EA=B8=B0=20(PriorityQueue=20=EC=82=AC=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date11_07/Algorithm/Harshad2.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Project/src/main/java/Date11_07/Algorithm/Harshad2.java diff --git a/Project/src/main/java/Date11_07/Algorithm/Harshad2.java b/Project/src/main/java/Date11_07/Algorithm/Harshad2.java new file mode 100644 index 0000000..dc18664 --- /dev/null +++ b/Project/src/main/java/Date11_07/Algorithm/Harshad2.java @@ -0,0 +1,71 @@ +package Date11_07.Algorithm; + +import java.util.*; + +/* PriorityQueue() 사용해서 푸는 법 + + 프로그래머스 나누어 떨어진느 숫자 배열 + 1. 배열을 통해 숫자 값들을 입력받음 + 2. 나누고 싶은 값을 설정함 + 3. 배열에 있는 값들을 나누고 싶은 값을 통해 나눔 + 4. 이때 나머지가 없이 딱 나누어지는 값을 배열에 넣어 리턴함 + 5. 만약 나머지가 없이 딱 나누어 떨어지는 값이 없을경우 -1 리턴 + */ +public class Harshad2 { + + // 기본 풀이 (리스트로 값 받은 후 배열에 저장하여 반환) + public int[] solution(int[] arr,int divisor){ + + List templist = new ArrayList<>(); + + for(int i=0; i list = new PriorityQueue<>(); + for (int i = 0; i < arr.length; i++) { + if (arr[i] % divisor == 0) list.add(arr[i]); + } + + if(list.size() == 0) return new int[]{-1}; + + // list를 Array로 바꾸기 + int[] answer = new int[list.size()]; // 배열의 크기를 list크기만큼 설정 + int idx = 0; + while(!list.isEmpty()){ // 리스트가 비어있지 않을경우 + answer[idx++] = list.poll(); // 배열에 리스트를 넣는다. + } + return answer; + } + + public static void main(String[] args) { + Harshad2 hs = new Harshad2(); + int[] arr ={5,9,7,10}; + int[] arr2 ={2,36,1,3}; + int[] arr3 = {3,2,6}; + System.out.println(Arrays.toString(hs.solution2(arr,5))); + System.out.println(Arrays.toString(hs.solution2(arr2,1))); + System.out.println(Arrays.toString(hs.solution2(arr3,10))); + } +} From 185d17f4abedb018c48d74d2a576f9c4a6d1b929 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Wed, 9 Nov 2022 10:57:41 +0900 Subject: [PATCH 280/307] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8276c0d..5080260 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,8 @@ https://github.com/Bae-Ji-Won/Spring-Study - 2022-11-03 : 알고리즘[연습문제(2)] - (프로그래머스) 에라토스테네스의 체를 통한 소수찾기 완성 +- 2022-11-07 : 알고리즘[PriorityQueue] - (프로그래머스) 하샤드 수 찾기, 나누어 떨어지는 숫자 배열 +
# ⚙️ 기술 스택 From cc44e7e91aeb49e90a48ac1506344a38096d6739 Mon Sep 17 00:00:00 2001 From: Bae Ji Won Date: Thu, 10 Nov 2022 13:11:01 +0900 Subject: [PATCH 281/307] =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=ED=83=90?= =?UTF-8?q?=EC=83=89(=EC=9B=90=ED=95=98=EB=8A=94=20=EC=88=AB=EC=9E=90=20?= =?UTF-8?q?=EC=9E=90=EB=A6=AC=20=EA=B5=AC=ED=95=98=EA=B8=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date11_08/Alogrithm/SimpleSearch.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Project/src/main/java/Date11_08/Alogrithm/SimpleSearch.java diff --git a/Project/src/main/java/Date11_08/Alogrithm/SimpleSearch.java b/Project/src/main/java/Date11_08/Alogrithm/SimpleSearch.java new file mode 100644 index 0000000..1e2a592 --- /dev/null +++ b/Project/src/main/java/Date11_08/Alogrithm/SimpleSearch.java @@ -0,0 +1,51 @@ +package Date11_08.Alogrithm; + +import com.fasterxml.jackson.core.util.BufferRecycler; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.Buffer; +import java.util.Arrays; + +/* + CodeUp 3001 데이터 탐색 + 1. 몇개의 데이터를 입력할 것인지 n 입력 + 2. n개의 갯수만큼 데이터 입력 + 3. 찾고 싶은 값을 입력 + 4. 찾고 싶은 값의 위치를 출력 만약 없는 값이라면 -1 반환 + */ +public class SimpleSearch { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + public int solution(int num) throws IOException { + int[] nums = new int[num]; // 입력한 값들 저장소의 크기 설정 + String[] temp = br.readLine().split(" "); + + for(int i=0; i Date: Thu, 10 Nov 2022 13:11:09 +0900 Subject: [PATCH 282/307] =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=ED=83=90?= =?UTF-8?q?=EC=83=89(=EC=9B=90=ED=95=98=EB=8A=94=20=EC=88=AB=EC=9E=90=20?= =?UTF-8?q?=EC=9E=90=EB=A6=AC=20=EA=B5=AC=ED=95=98=EA=B8=B0)=20-=20?= =?UTF-8?q?=EC=9D=B4=EC=A7=84=ED=83=90=EC=83=89=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date11_08/Alogrithm/SimpleSearch2.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Project/src/main/java/Date11_08/Alogrithm/SimpleSearch2.java diff --git a/Project/src/main/java/Date11_08/Alogrithm/SimpleSearch2.java b/Project/src/main/java/Date11_08/Alogrithm/SimpleSearch2.java new file mode 100644 index 0000000..1085c18 --- /dev/null +++ b/Project/src/main/java/Date11_08/Alogrithm/SimpleSearch2.java @@ -0,0 +1,62 @@ +package Date11_08.Alogrithm; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.Scanner; + +/* + CodeUp 3001 데이터 탐색 ( 바이너리 서치 - 이진탐색으로 구하기) + 1. 몇개의 데이터를 입력할 것인지 n 입력 + 2. n개의 갯수만큼 데이터 입력 + 3. 찾고 싶은 값을 입력 + 4. 찾고 싶은 값의 위치를 출력 만약 없는 값이라면 -1 반환 + 5. 이전에는 배열에 저장된 값들을 모두 비교해 하나하나 찾았다면 이진탐색으로는 오름차순으로 정렬하여 절반을 나눠 + 값보다 큰지 작은지 범위를 줄여나가면서 찾는방식이다. + ex) {1,2,3,4,5,6,7}일때 5를 찾아야 하는 경우 절반인 4의 값을 가져와 4보다 큰지 작은지 비교하고 크다면 + {5,6,7}을 중 6를 가져와 6보다 큰지 작은지 비교하여 작다면 5를 출력함 + */ +public class SimpleSearch2 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + public int solution(int num) throws IOException { + int[] nums = new int[num]; // 입력한 값들 저장소의 크기 설정 + String[] temp = br.readLine().split(" "); + + for(int i=0; i targetnum) // midnum이 targetnum 보다 클 경우 + endIdx = midIdx; // 인덱스 끝점을 midIdx로 바꿔줌 + + else if(midnum < targetIdx) // midnum이 targetnum 보다 작을 경우 + startIdx = midIdx; // 인덱스 시작점을 midIdx로 바꿔줌 + + else // midnum이 targetnum이랑 같을경우 + targetIdx += midIdx; // 찾을 index가 midIdx이므로 targetIdx에 midIdx 저장 + } + return targetIdx; + } + + public static void main(String[] args) throws IOException { + int num = Integer.parseInt(br.readLine()); + SimpleSearch s = new SimpleSearch(); + System.out.println(s.solution(num)); + } +} From d26648dcd1e32f12ab3bb15f3ee100c6f4b45eb2 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Thu, 10 Nov 2022 13:12:33 +0900 Subject: [PATCH 283/307] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5080260..aad7bdd 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ https://github.com/Bae-Ji-Won/Spring-Study - 2022-11-07 : 알고리즘[PriorityQueue] - (프로그래머스) 하샤드 수 찾기, 나누어 떨어지는 숫자 배열 +- 2022-11-08 : 알고리즘[이진탐색] - (코드업) 데이터탐색
# ⚙️ 기술 스택 From 431c7c855f382070eddcc0634dc9a4ffdeb7f7bd Mon Sep 17 00:00:00 2001 From: Bae Ji Won Date: Fri, 11 Nov 2022 14:36:37 +0900 Subject: [PATCH 284/307] =?UTF-8?q?=EC=84=A0=ED=83=9D=EC=A0=95=EB=A0=AC(?= =?UTF-8?q?=EA=B8=B0=EB=B3=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date11_09/Algorithm/SelectionSort.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Project/src/main/java/Date11_09/Algorithm/SelectionSort.java diff --git a/Project/src/main/java/Date11_09/Algorithm/SelectionSort.java b/Project/src/main/java/Date11_09/Algorithm/SelectionSort.java new file mode 100644 index 0000000..5a66587 --- /dev/null +++ b/Project/src/main/java/Date11_09/Algorithm/SelectionSort.java @@ -0,0 +1,47 @@ +package Date11_09.Algorithm; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +/* 선택정렬(1) + index = 0번부터 제일 작은 값으로 채워 나감 + ex) index = 0 1 2 3 4 + value = 5 7 3 1 2 일떄 + index 0번째 자리의 값을 다른 index 값과 모두 비교해서 제일 작은 값으로 바꿈 즉, 1과 자리를 바꿈 + */ + +public class SelectionSort { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + public int[] solution(int[] arr){ + int[] result = arr; + + for(int i=0; iresult[j]) // interface를 통해 값만 구현후 원하는 식에 넣어 사용 + minidx = j; + } + int temp = result[i]; + result[i] = result[minidx]; + result[minidx] = temp; + } + + return result; + } + + + public static void main(String[] args) throws IOException { + SelectionSort s = new SelectionSort(); + String[] temp = br.readLine().split(" "); + int[] arr = new int[temp.length]; + + for(int i=0; i Date: Fri, 11 Nov 2022 14:37:18 +0900 Subject: [PATCH 285/307] =?UTF-8?q?=EC=84=A0=ED=83=9D=EC=A0=95=EB=A0=AC(in?= =?UTF-8?q?terface=20Strategy=EC=82=AC=EC=9A=A9=ED=95=98=EC=97=AC=20?= =?UTF-8?q?=EC=98=A4=EB=A6=84,=EB=82=B4=EB=A6=BC=EC=B0=A8=EC=88=9C=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date11_09/Algorithm/SelectionSort2.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Project/src/main/java/Date11_09/Algorithm/SelectionSort2.java diff --git a/Project/src/main/java/Date11_09/Algorithm/SelectionSort2.java b/Project/src/main/java/Date11_09/Algorithm/SelectionSort2.java new file mode 100644 index 0000000..db79acd --- /dev/null +++ b/Project/src/main/java/Date11_09/Algorithm/SelectionSort2.java @@ -0,0 +1,59 @@ +package Date11_09.Algorithm; + +/* 선택정렬(2) - interface 사용하여 오름, 내림차순 정렬 + index = 0번부터 제일 작은 값으로 채워 나감 + ex) index = 0 1 2 3 4 + value = 5 7 3 1 2 일떄 + index 0번째 자리의 값을 다른 index 값과 모두 비교해서 제일 작은 값으로 바꿈 즉, 1과 자리를 바꿈 + */ + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +interface StatementStrategy{ + boolean compare(int a, int b); +} + +public class SelectionSort2 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + public int[] solution(int[] arr,StatementStrategy stmt){ + int[] result = arr; + + for(int i=0; i a>b))); + System.out.println(Arrays.toString(s.solution(arr,(a,b) -> ab; +// } +// }); + + } +} From 52f7dc0e2c067ded266d5a671e33a5de8d6d0657 Mon Sep 17 00:00:00 2001 From: Bae Ji Won Date: Fri, 11 Nov 2022 14:37:35 +0900 Subject: [PATCH 286/307] =?UTF-8?q?=EC=84=A0=ED=83=9D=EC=A0=95=EB=A0=AC(in?= =?UTF-8?q?terface=EB=A5=BC=20DiFunction=EC=9C=BC=EB=A1=9C=20=EB=8C=80?= =?UTF-8?q?=EC=B2=B4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date11_09/Algorithm/SelectionSort3.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Project/src/main/java/Date11_09/Algorithm/SelectionSort3.java diff --git a/Project/src/main/java/Date11_09/Algorithm/SelectionSort3.java b/Project/src/main/java/Date11_09/Algorithm/SelectionSort3.java new file mode 100644 index 0000000..53b9c2a --- /dev/null +++ b/Project/src/main/java/Date11_09/Algorithm/SelectionSort3.java @@ -0,0 +1,53 @@ +package Date11_09.Algorithm; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.function.BiFunction; + +/* /* 선택정렬(3) - ByFunction 사용해서 구현해보기 + index = 0번부터 제일 작은 값으로 채워 나감 + ex) index = 0 1 2 3 4 + value = 5 7 3 1 2 일떄 + index 0번째 자리의 값을 다른 index 값과 모두 비교해서 제일 작은 값으로 바꿈 즉, 1과 자리를 바꿈 + */ +public class SelectionSort3 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + public int[] solution(int[] arr, BiFunction stmt){ + int[] result = arr; + + for(int i=0; i biFunction = (a,b) -> a>b; + BiFunction biFunction2 = (a,b) -> a Date: Fri, 11 Nov 2022 14:39:05 +0900 Subject: [PATCH 287/307] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index aad7bdd..f167ee5 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,8 @@ https://github.com/Bae-Ji-Won/Spring-Study - 2022-11-07 : 알고리즘[PriorityQueue] - (프로그래머스) 하샤드 수 찾기, 나누어 떨어지는 숫자 배열 - 2022-11-08 : 알고리즘[이진탐색] - (코드업) 데이터탐색 + +- 2022-11-09 : 알고리즘[선택정렬] - 기본, interface(Strategy), DiFunction 사용
# ⚙️ 기술 스택 From 7a22b6b737e48c84eae671482f7de10e432c2eba Mon Sep 17 00:00:00 2001 From: Bae Ji Won Date: Fri, 11 Nov 2022 14:43:07 +0900 Subject: [PATCH 288/307] =?UTF-8?q?=EC=84=A0=ED=83=9D=EC=A0=95=EB=A0=AC(Di?= =?UTF-8?q?Function,=20DiPredicate=20=EC=82=AC=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date11_09/Algorithm/SelectionSort3.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Project/src/main/java/Date11_09/Algorithm/SelectionSort3.java b/Project/src/main/java/Date11_09/Algorithm/SelectionSort3.java index 53b9c2a..7505c92 100644 --- a/Project/src/main/java/Date11_09/Algorithm/SelectionSort3.java +++ b/Project/src/main/java/Date11_09/Algorithm/SelectionSort3.java @@ -5,6 +5,7 @@ import java.io.InputStreamReader; import java.util.Arrays; import java.util.function.BiFunction; +import java.util.function.BiPredicate; /* /* 선택정렬(3) - ByFunction 사용해서 구현해보기 index = 0번부터 제일 작은 값으로 채워 나감 @@ -15,6 +16,7 @@ public class SelectionSort3 { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + // BiFunction을 사용한 풀이 public int[] solution(int[] arr, BiFunction stmt){ int[] result = arr; @@ -32,6 +34,24 @@ public int[] solution(int[] arr, BiFunction stmt){ return result; } + // BiPredicate을 사용한 풀이 BiPredicate도 을 사용해야하지만 default값이 boolean이기 때문에 Boolean은 생략 가능 + public int[] solution2(int[] arr, BiPredicate stmt){ + int[] result = arr; + + for(int i=0; i biFunction = (a,b) -> a>b; - BiFunction biFunction2 = (a,b) -> a biPredicate = (a,b) -> a biFunction2 = (a,b) -> a Date: Fri, 11 Nov 2022 15:59:29 +0900 Subject: [PATCH 289/307] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index f167ee5..0bc8df3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ ### 🦁 멋쟁이사자처럼 백엔드 # 🗓 공부 일정 +
+ +정리 블로그 : https://velog.io/@qowl880/series/%EC%9E%90%EB%B0%94-%EC%8B%A4%EC%8A%B5 + - 2022-10-04 : Git + 알고리즘 - 2022-10-05 : Intellij Git 사용 + 자바란? + interface 의존성과 다형성을 통한 예제 문제 From 1165a2bb22971e97fa4445b875c4327e878b0f93 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Fri, 11 Nov 2022 16:00:07 +0900 Subject: [PATCH 290/307] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0bc8df3..99f0de0 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,9 @@ # 🗓 공부 일정
-정리 블로그 : https://velog.io/@qowl880/series/%EC%9E%90%EB%B0%94-%EC%8B%A4%EC%8A%B5 +실습 정리 블로그 : https://velog.io/@qowl880/series/%EC%9E%90%EB%B0%94-%EC%8B%A4%EC%8A%B5 + +알고리즘 정리 블로그 : https://velog.io/@qowl880/series/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98 - 2022-10-04 : Git + 알고리즘 From 172e74a1e8ee74977408cccee6944b43f06622f4 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Fri, 11 Nov 2022 16:01:19 +0900 Subject: [PATCH 291/307] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 99f0de0..99c6d8d 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ # 🗓 공부 일정
-실습 정리 블로그 : https://velog.io/@qowl880/series/%EC%9E%90%EB%B0%94-%EC%8B%A4%EC%8A%B5 +📄 실습 정리 블로그 : https://velog.io/@qowl880/series/%EC%9E%90%EB%B0%94-%EC%8B%A4%EC%8A%B5 -알고리즘 정리 블로그 : https://velog.io/@qowl880/series/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98 +📄 알고리즘 정리 블로그 : https://velog.io/@qowl880/series/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98 - 2022-10-04 : Git + 알고리즘 From 225667360d1c695d2d8d4350c748a8efb1d979bf Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Fri, 11 Nov 2022 16:04:09 +0900 Subject: [PATCH 292/307] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 99c6d8d..6776f22 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ https://github.com/Bae-Ji-Won/Spring-Study - 2022-11-08 : 알고리즘[이진탐색] - (코드업) 데이터탐색 -- 2022-11-09 : 알고리즘[선택정렬] - 기본, interface(Strategy), DiFunction 사용 +- 2022-11-09 : 알고리즘[선택정렬] - 기본, interface(Strategy), BiFunction, BiPredicate 사용
# ⚙️ 기술 스택 From 709f55372a8967a52976c1ffa7518b8d609a4619 Mon Sep 17 00:00:00 2001 From: Bae Ji Won Date: Fri, 11 Nov 2022 16:18:01 +0900 Subject: [PATCH 293/307] =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/test/java/Date10_20/UserDaoTest.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Project/src/test/java/Date10_20/UserDaoTest.java b/Project/src/test/java/Date10_20/UserDaoTest.java index f4d3907..d99ad11 100644 --- a/Project/src/test/java/Date10_20/UserDaoTest.java +++ b/Project/src/test/java/Date10_20/UserDaoTest.java @@ -1,22 +1,22 @@ -package Date10_20; - -import Date10_20.dao.Abstract.AWSUserDaoImpl; -import Date10_20.domain.User; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.sql.SQLException; - -class UserDaoTest { - - @Test - void addAndSelect() throws ClassNotFoundException, SQLException { - AWSUserDaoImpl userDao = new AWSUserDaoImpl(); - String id = "10"; - User user = new User(id,"test","1234"); // user 값을 DTO에 저장함 - userDao.add(user); - - User selectedUser = userDao.select(id); // DTO에 저장되어 있는 데이터를 가져와 비교함 - Assertions.assertEquals("test",selectedUser.getName()); - } -} \ No newline at end of file +//package Date10_20; +// +//import Date10_20.dao.Abstract.AWSUserDaoImpl; +//import Date10_20.domain.User; +//import org.junit.jupiter.api.Assertions; +//import org.junit.jupiter.api.Test; +// +//import java.sql.SQLException; +// +//class UserDaoTest { +// +// @Test +// void addAndSelect() throws ClassNotFoundException, SQLException { +// AWSUserDaoImpl userDao = new AWSUserDaoImpl(); +// String id = "10"; +// User user = new User(id,"test","1234"); // user 값을 DTO에 저장함 +// userDao.add(user); +// +// User selectedUser = userDao.select(id); // DTO에 저장되어 있는 데이터를 가져와 비교함 +// Assertions.assertEquals("test",selectedUser.getName()); +// } +//} \ No newline at end of file From 6abad46e288dd83af1747c5bd7b2d7f1c98e30bc Mon Sep 17 00:00:00 2001 From: Bae Ji Won Date: Fri, 11 Nov 2022 16:18:09 +0900 Subject: [PATCH 294/307] =?UTF-8?q?=EC=84=A0=ED=83=9D=EC=A0=95=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/src/main/java/Date11_09/Algorithm/SelectionSort.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project/src/main/java/Date11_09/Algorithm/SelectionSort.java b/Project/src/main/java/Date11_09/Algorithm/SelectionSort.java index 5a66587..9100080 100644 --- a/Project/src/main/java/Date11_09/Algorithm/SelectionSort.java +++ b/Project/src/main/java/Date11_09/Algorithm/SelectionSort.java @@ -21,7 +21,7 @@ public int[] solution(int[] arr){ for(int i=0; iresult[j]) // interface를 통해 값만 구현후 원하는 식에 넣어 사용 + if(result[minidx]>result[j]) minidx = j; } int temp = result[i]; From 7a945c3f0f6c83964c387d134a4d0cde2a3271d6 Mon Sep 17 00:00:00 2001 From: Bae Ji Won Date: Sun, 13 Nov 2022 16:22:51 +0900 Subject: [PATCH 295/307] =?UTF-8?q?=EC=A4=91=EB=B3=B5=EC=A0=9C=EA=B1=B0=20?= =?UTF-8?q?-=20list=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date11_10/Algorithm/NoOverlap.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Project/src/main/java/Date11_10/Algorithm/NoOverlap.java diff --git a/Project/src/main/java/Date11_10/Algorithm/NoOverlap.java b/Project/src/main/java/Date11_10/Algorithm/NoOverlap.java new file mode 100644 index 0000000..0cdd996 --- /dev/null +++ b/Project/src/main/java/Date11_10/Algorithm/NoOverlap.java @@ -0,0 +1,40 @@ +package Date11_10.Algorithm; + + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + + +/* 프로그래머스 (같은 숫자는 싫어) - list를 통한 풀이 + 1. 0~9까지의 값을 담은 배열이 주어짐 + 2. 연속되는 숫자중 중복되는 값은 제거함 + 3. 중복 제거한 값(배열)을 리턴하는데 원소들의 순서를 유지함 + ex) {4,4,4,3,3} 일때 {4,3}이 리턴되야함 또한 {1, 1, 3, 3, 0, 1, 1}이 입력되었을때 {1,3,0,1}이 리턴되야함 + */ +public class NoOverlap { + public Object[] solution(int[] nums){ + List numlist = new ArrayList<>(); + numlist.add(nums[0]); // 이전값과 다음값을 비교하기 위해 미리 처음 숫자를 넣어줌 + + // list 사이즈의 -1의 값이 새로들어오는 값과 같다면 추가안함 + // ex) {1,1,3,1}을 입력받을때 list에 처음값 1을 집어넣은 상태에서 반복문 실행 + // i = 1일때, listsize = 1이므로 numlist.get(1-1)의 값인 1을 가져와 nums[1]의 값인 1과 비교함 + // 이때 값이 중복되므로 list에 넣지 않음 + // i = 2일때, numlist.get(1-1)의 값인 1을 가져와 nums[2]의 값인 3과 비교 후 다르므로 list저장 + // i = 3일때, nulist.get(2-1)의 값인 3을 가져와 nums[3]의 값인 1과 비교 후 다르므로 list에 저장 + + for(int i=1; i Date: Sun, 13 Nov 2022 16:22:59 +0900 Subject: [PATCH 296/307] =?UTF-8?q?=EC=A4=91=EB=B3=B5=EC=A0=9C=EA=B1=B0=20?= =?UTF-8?q?-=20stack=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date11_10/Algorithm/NoOverlap2.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Project/src/main/java/Date11_10/Algorithm/NoOverlap2.java diff --git a/Project/src/main/java/Date11_10/Algorithm/NoOverlap2.java b/Project/src/main/java/Date11_10/Algorithm/NoOverlap2.java new file mode 100644 index 0000000..2513c90 --- /dev/null +++ b/Project/src/main/java/Date11_10/Algorithm/NoOverlap2.java @@ -0,0 +1,36 @@ +package Date11_10.Algorithm; + +/* 프로그래머스 (같은 숫자는 싫어) - stack을 통한 풀이 + 1. 0~9까지의 값을 담은 배열이 주어짐 + 2. 연속되는 숫자중 중복되는 값은 제거함 + 3. 중복 제거한 값(배열)을 리턴하는데 원소들의 순서를 유지함 + ex) {4,4,4,3,3} 일때 {4,3}이 리턴되야함 또한 {1, 1, 3, 3, 0, 1, 1}이 입력되었을때 {1,3,0,1}이 리턴되야함 + */ + +import java.util.Arrays; +import java.util.Stack; + +public class NoOverlap2 { + public int[] solution(int[] nums){ + Stack numlist = new Stack<>(); + numlist.push(nums[0]); + + for (int i = 1; i < nums.length; i++) { + if(numlist.peek() != nums[i]) // 스택에 있는 가장 높은 값을 가져와 비교함 + numlist.push(nums[i]); + } + + int[] result = new int[numlist.size()]; + for (int i = numlist.size()-1; i>=0; i--) { // 스택은 후입선출이기때문에 거꾸로 넣어줘야함 + result[i] = numlist.pop(); + } + + return result; + } + + public static void main(String[] args) { + NoOverlap2 no = new NoOverlap2(); + System.out.println(Arrays.toString(no.solution(new int[]{4,4,4,3,3}))); + System.out.println(Arrays.toString(no.solution(new int[]{1, 1, 3, 3, 0, 1, 1}))); + } +} From 0a2ac0f950136f45d04bd16c29b06fad400327b7 Mon Sep 17 00:00:00 2001 From: Bae Ji Won Date: Tue, 15 Nov 2022 22:28:09 +0900 Subject: [PATCH 297/307] =?UTF-8?q?=ED=80=B5=EC=A0=95=EB=A0=AC=20-=20?= =?UTF-8?q?=EC=9E=AC=EA=B7=80=ED=95=A8=EC=88=98=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date11_15/Algorithm/QuickSort.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Project/src/main/java/Date11_15/Algorithm/QuickSort.java diff --git a/Project/src/main/java/Date11_15/Algorithm/QuickSort.java b/Project/src/main/java/Date11_15/Algorithm/QuickSort.java new file mode 100644 index 0000000..7593a68 --- /dev/null +++ b/Project/src/main/java/Date11_15/Algorithm/QuickSort.java @@ -0,0 +1,56 @@ +package Date11_15.Algorithm; + +import java.util.ArrayList; +import java.util.List; + +// 재귀함수를 통한 퀵 정렬 +public class QuickSort { + + public List merge(List left,List mid,List right){ + List answer = new ArrayList<>(); + answer.addAll(left); + answer.addAll(mid); + answer.addAll(right); + + return answer; + } + + public List sort(List arr){ + + // 재귀 탈출 조건 + if(arr.size()<=1) return arr; // mid보다 값이 모두 작거나 커서 한쪽으로 쏠려 한쪽에는 아예 들어가지 않는 경우도 생기고 + // 1개의 값만 들어가는 경우도 생긴다. 1개만 들어가면 더이상 비교를 할 수 없기에 1이하로 하여 재귀를 빠져나오도록 한다. + + // 1. 기준값 뽑는 로직 구현 + int pivot = arr.get(arr.size()/2); // index = 4 , arr[4] = 5 + + // 2. 기준값 기준으로 왼쪽 오른쪽으로 나누어 담는 로직 구현 + List left = new ArrayList<>(); + List right = new ArrayList<>(); + List mid = new ArrayList<>(); + + for(int i=0; ipivot) + right.add(arr.get(i)); + else + mid.add(arr.get(i)); + } + + // list를 합치는 연산 + return merge(sort(left),mid,sort(right)); + } + + public static void main(String[] args) { + int[] arr = {20,18,5,19,5,25,40,50}; // 8 + List al = new ArrayList<>(); + for(int i =0; i Date: Wed, 16 Nov 2022 11:39:52 +0900 Subject: [PATCH 298/307] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6776f22..ed243ae 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,8 @@ https://github.com/Bae-Ji-Won/Spring-Study - 2022-11-08 : 알고리즘[이진탐색] - (코드업) 데이터탐색 - 2022-11-09 : 알고리즘[선택정렬] - 기본, interface(Strategy), BiFunction, BiPredicate 사용 + +- 2022-11-15 : 알고리즘[퀵정렬] - 재귀함수 사용
# ⚙️ 기술 스택 From 10e07f7dec3e61383c213581af8f477c8b26e66c Mon Sep 17 00:00:00 2001 From: Bae Ji Won Date: Thu, 17 Nov 2022 15:02:59 +0900 Subject: [PATCH 299/307] =?UTF-8?q?=ED=80=B5=EC=A0=95=EB=A0=AC=20-=20?= =?UTF-8?q?=EC=9E=AC=EA=B7=80=ED=95=A8=EC=88=98=20=EC=82=AC=EC=9A=A9(List?= =?UTF-8?q?=20=EC=82=AC=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/src/main/java/Date11_15/Algorithm/QuickSort.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project/src/main/java/Date11_15/Algorithm/QuickSort.java b/Project/src/main/java/Date11_15/Algorithm/QuickSort.java index 7593a68..c2c6bbc 100644 --- a/Project/src/main/java/Date11_15/Algorithm/QuickSort.java +++ b/Project/src/main/java/Date11_15/Algorithm/QuickSort.java @@ -3,7 +3,7 @@ import java.util.ArrayList; import java.util.List; -// 재귀함수를 통한 퀵 정렬 +// 재귀함수를 통한 퀵 정렬 - List로 풀기 public class QuickSort { public List merge(List left,List mid,List right){ From b3ee11a2b6853a80a0a51cb752de5c25db6ee888 Mon Sep 17 00:00:00 2001 From: Bae Ji Won Date: Thu, 17 Nov 2022 15:03:12 +0900 Subject: [PATCH 300/307] =?UTF-8?q?=ED=80=B5=EC=A0=95=EB=A0=AC(2)=20-=20?= =?UTF-8?q?=EC=9E=AC=EA=B7=80=ED=95=A8=EC=88=98=20=EC=82=AC=EC=9A=A9(Array?= =?UTF-8?q?=20=EC=82=AC=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/src/main/java/Date11_16/Algorithm/QuickSort2.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Project/src/main/java/Date11_16/Algorithm/QuickSort2.java diff --git a/Project/src/main/java/Date11_16/Algorithm/QuickSort2.java b/Project/src/main/java/Date11_16/Algorithm/QuickSort2.java new file mode 100644 index 0000000..5782649 --- /dev/null +++ b/Project/src/main/java/Date11_16/Algorithm/QuickSort2.java @@ -0,0 +1,6 @@ +package Date11_16.Algorithm; + +// 재귀함수를 통한 퀵 정렬 - 배열로 풀기 +public class QuickSort2 { + +} From 3d7ededaf6f788d7b1da1aa806166f2e9f349051 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Sun, 20 Nov 2022 20:35:50 +0900 Subject: [PATCH 301/307] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ed243ae..75f95b4 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ https://github.com/Bae-Ji-Won/Spring-Study - 2022-11-01 : 알고리즘[연습문제] - (프로그래머스) 소수찾기 - 2022-11-02 : 알고리즘[연습문제(2)] - (프로그래머스) 에라토스테네스의 체를 통한 소수찾기 - + - 2022-11-03 : 알고리즘[연습문제(2)] - (프로그래머스) 에라토스테네스의 체를 통한 소수찾기 완성 - 2022-11-07 : 알고리즘[PriorityQueue] - (프로그래머스) 하샤드 수 찾기, 나누어 떨어지는 숫자 배열 From cba1480ab3ae40d858d65755a90e9aa8945deb20 Mon Sep 17 00:00:00 2001 From: Bae Ji Won Date: Tue, 22 Nov 2022 13:24:27 +0900 Subject: [PATCH 302/307] =?UTF-8?q?=EC=8B=9C=EC=A0=80=EC=95=94=ED=98=B8(1)?= =?UTF-8?q?=20-=20=EB=82=B4=20=EB=B0=A9=EC=8B=9D=EB=8C=80=EB=A1=9C=20?= =?UTF-8?q?=ED=92=80=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date11_18/Algorithm/CaesarPassword.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Project/src/main/java/Date11_18/Algorithm/CaesarPassword.java diff --git a/Project/src/main/java/Date11_18/Algorithm/CaesarPassword.java b/Project/src/main/java/Date11_18/Algorithm/CaesarPassword.java new file mode 100644 index 0000000..25b39bf --- /dev/null +++ b/Project/src/main/java/Date11_18/Algorithm/CaesarPassword.java @@ -0,0 +1,62 @@ +package Date11_18.Algorithm; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +/* 프로그래머스 시저암호(내 방식대로 풀기) + 시저암호 : 어떤 문장의 각 알파벳을 일정한 거리만큼 밀어서 다른 알파벳으로 바꾸는 암호화 방식 + 예) "AB"는 1만큼 밀면 "BC가 되고, 3만큼 밀면 "DE"가 된다. "z'는 1만큼 밀면 "a"가 된다. + + 문자열 s와 거리 n을 입력받아 s를 n만큼 민 암호문을 만드는 함수를 작성하라. + +-------- 제한조건 -------- + 공백은 아무리 밀어도 공백입니다. + s는 알파벳 소문자, 대문자, 공백으로만 이루어져 있습니다. + s의 길이는 8000이하입니다. + n은 1 이상, 25이하인 자연수입니다. + */ +class CaesarPassword { + + public char solution(char c, int num){ + if((int)c >= 97 && (int)c <= 122) { // 소문자 일때 + int result = c+num; + if(result >122){ + result -= 122; + return (char)((96+result)); + } + return (char) ((c + num)); + } + else if((int)c>=65 && (int)c<=90) { // 대문자 일때 + int result = c+num; + if(result >90){ + result -= 90; + return (char)((64+result)); + } + return (char) ((c + num)); + } + else // 공백일 경우 + return c; + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String result = ""; + + System.out.print("문자열을 입력하세요 :"); + char[] str = br.readLine().toCharArray(); + for(int i=0; i Date: Tue, 22 Nov 2022 13:24:42 +0900 Subject: [PATCH 303/307] =?UTF-8?q?=EC=8B=9C=EC=A0=80=EC=95=94=ED=98=B8(1)?= =?UTF-8?q?=20-=20=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98=EB=A8=B8=EC=8A=A4?= =?UTF-8?q?=20=EC=96=91=EC=8B=9D=EB=8C=80=EB=A1=9C=20=ED=92=80=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Date11_18/Algorithm/CaesarPassword2.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Project/src/main/java/Date11_18/Algorithm/CaesarPassword2.java diff --git a/Project/src/main/java/Date11_18/Algorithm/CaesarPassword2.java b/Project/src/main/java/Date11_18/Algorithm/CaesarPassword2.java new file mode 100644 index 0000000..1bbb9bf --- /dev/null +++ b/Project/src/main/java/Date11_18/Algorithm/CaesarPassword2.java @@ -0,0 +1,45 @@ +package Date11_18.Algorithm; + +/* 프로그래머스 시저암호(프로그래머스에서 원하는 방식대로 풀기) +-------- 제한조건 -------- + 공백은 아무리 밀어도 공백입니다. + s는 알파벳 소문자, 대문자, 공백으로만 이루어져 있습니다. + s의 길이는 8000이하입니다. + n은 1 이상, 25이하인 자연수입니다. + */ +public class CaesarPassword2 { + public String solution(String s, int n){ + + String result = ""; // 최종 결과를 담을 문자열 + n = n%26; // n은 1~25사이인 자연수이므로 + + for(int i=0; i (26)%26 + 97 => 0+97 => 97 (a) + // 즉, 입력받은 문자열을 초기값인 a로 빼고 n만큼 더해 얼마나 증가가 되는지 계산한후 + // 소문자의 전체 갯수인 26개로 나머지값을 구함(소문자 아스키 코드는 97~122번 사이에 존재하므로 그 이상이 되면 다른 문자가 출력됨) + // 만약 26으로 나머지 값을 구하지 않으면 26+97 = 123으로 { 문자가 출력됨 따라서 이를 방지하고자 소문자 범위 내에서 계산되도록 설정 + // 마지막으로 초기값 97(a)를 더해 증가된 문자를 출력함 + } + else if(Character.isUpperCase(c)) { // 대문자 일때 + c = (char)((c-'A'+n)%26 + 'A'); + } + result += c; + } + + return result; + } + + + public static void main(String[] args) { + CaesarPassword2 cp = new CaesarPassword2(); + System.out.println(cp.solution("AB",1)); + System.out.println(cp.solution("z",1)); + System.out.println(cp.solution("a B z",4)); + } +} From cea9455316f0c1a8a518331fa44c2860cfc44222 Mon Sep 17 00:00:00 2001 From: Bae Ji Won Date: Tue, 22 Nov 2022 14:33:59 +0900 Subject: [PATCH 304/307] =?UTF-8?q?=ED=96=89=EB=A0=AC=EC=9D=98=20=EB=8D=A7?= =?UTF-8?q?=EC=85=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date11_17/Algorithm/ArrayPlus.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Project/src/main/java/Date11_17/Algorithm/ArrayPlus.java diff --git a/Project/src/main/java/Date11_17/Algorithm/ArrayPlus.java b/Project/src/main/java/Date11_17/Algorithm/ArrayPlus.java new file mode 100644 index 0000000..9ef9499 --- /dev/null +++ b/Project/src/main/java/Date11_17/Algorithm/ArrayPlus.java @@ -0,0 +1,32 @@ +package Date11_17.Algorithm; + +import java.util.Arrays; + +/* 프로그래머스 행렬의 덧셈 + 행과 열의 크기가 같은 두 행렬의 같은 행, 같은 열의 값을 서로 더한 결과가 된다. + 2개의 행렬 arr1과 arr2를 입력받아, 행렬 덧셈의 결과를 반환해라 + + ---- 제한 조건 ---- + 행렬 arr1, arr2의 행과 열의 길이는 500을 넘지 않는다. + */ +public class ArrayPlus { + public int[][] solution(int[][] arr1,int[][] arr2){ + int[][] result = new int[arr1.length][arr1[0].length]; + + // 행 반복 + for(int i=0; i Date: Thu, 24 Nov 2022 15:09:37 +0900 Subject: [PATCH 305/307] =?UTF-8?q?=EC=9E=AC=EA=B7=80=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=ED=92=80=EC=9D=B4=EB=B2=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Date11_23.Algorithm/Recursion.java | 29 +++++++++++++++++ .../java/Date11_23.Algorithm/Recursion2.java | 30 +++++++++++++++++ .../java/Date11_23.Algorithm/Recursion3.java | 32 +++++++++++++++++++ .../java/Date11_23.Algorithm/Recursion4.java | 22 +++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 Project/src/main/java/Date11_23.Algorithm/Recursion.java create mode 100644 Project/src/main/java/Date11_23.Algorithm/Recursion2.java create mode 100644 Project/src/main/java/Date11_23.Algorithm/Recursion3.java create mode 100644 Project/src/main/java/Date11_23.Algorithm/Recursion4.java diff --git a/Project/src/main/java/Date11_23.Algorithm/Recursion.java b/Project/src/main/java/Date11_23.Algorithm/Recursion.java new file mode 100644 index 0000000..83cdca5 --- /dev/null +++ b/Project/src/main/java/Date11_23.Algorithm/Recursion.java @@ -0,0 +1,29 @@ +package Date11_23.Algorithm; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +/* 재귀함수 문제 - 코드업 1851번 + n을 입력받아 n개의 별을 출력하기(재귀 사용) + */ +public class Recursion { + + public String solution(int num){ + + if(num == 0){ + return ""; + } + + return "*" + solution(num - 1); + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + System.out.print("n의 값을 입력하세요 : "); + int num = Integer.parseInt(br.readLine()); + Recursion r = new Recursion(); + System.out.println(r.solution(num)); + } +} diff --git a/Project/src/main/java/Date11_23.Algorithm/Recursion2.java b/Project/src/main/java/Date11_23.Algorithm/Recursion2.java new file mode 100644 index 0000000..0a9b1b3 --- /dev/null +++ b/Project/src/main/java/Date11_23.Algorithm/Recursion2.java @@ -0,0 +1,30 @@ +package Date11_23.Algorithm; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +/* 재귀함수(2) + 한 정수n을 입력받아 1부터 n까지의 정수 합을 출력하라 + */ +public class Recursion2 { + public int solution(int num){ + if(num == 0){ + return 0; + } + + return num + solution(num-1); + } + + + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + System.out.print("n의 값을 입력하세요 : "); + int num = Integer.parseInt(br.readLine()); + + Recursion2 r2 = new Recursion2(); + System.out.println(r2.solution(num)); + } +} diff --git a/Project/src/main/java/Date11_23.Algorithm/Recursion3.java b/Project/src/main/java/Date11_23.Algorithm/Recursion3.java new file mode 100644 index 0000000..d6759ef --- /dev/null +++ b/Project/src/main/java/Date11_23.Algorithm/Recursion3.java @@ -0,0 +1,32 @@ +package Date11_23.Algorithm; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +/* 재귀함수(3) 코드업 1854번 문제 + 재귀로 각 자리 수의 합 리턴하기 + */ +public class Recursion3 { + public int solution(int num){ + if(num == 0){ + return 0; + } + + int result = num % 10; + + return result + solution(num/10); + } + + + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + System.out.print("n의 값을 입력하세요 : "); + int num = Integer.parseInt(br.readLine()); + + Recursion3 r3 = new Recursion3(); + System.out.println(r3.solution(num)); + } +} diff --git a/Project/src/main/java/Date11_23.Algorithm/Recursion4.java b/Project/src/main/java/Date11_23.Algorithm/Recursion4.java new file mode 100644 index 0000000..16a3b7c --- /dev/null +++ b/Project/src/main/java/Date11_23.Algorithm/Recursion4.java @@ -0,0 +1,22 @@ +package Date11_23.Algorithm; + +/* 재귀(4) 코드업 1855번 + 재귀로 n번째 피보나치 수 리턴하기 + */ +public class Recursion4 { + public static void main(String[] args) { + // 0부터 8까지의 피보나치 수 모두 출력 + for (int i=0; i<9; i++) { + System.out.printf("%d\t", fibo(i)); + } + } + + public static int fibo(int n) { + // 전달받은 값과 동일한 값을 리턴한다면 계산할 필요가 없으므로 중단 + if (n <= 1) { + return n; + } else { + return fibo(n-2) + fibo(n-1); + } + } +} From cc0297a7c971fe22232287ec8445d7340538e79e Mon Sep 17 00:00:00 2001 From: Bae Ji Won Date: Mon, 28 Nov 2022 09:57:42 +0900 Subject: [PATCH 306/307] =?UTF-8?q?=EC=B5=9C=EB=8C=80=EA=B3=B5=EC=95=BD?= =?UTF-8?q?=EC=88=98=20=EA=B5=AC=ED=95=98=EA=B8=B0(=EC=9E=AC=EA=B7=80?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=82=AC=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/Date11_25/Algorithm/GCD.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Project/src/main/java/Date11_25/Algorithm/GCD.java diff --git a/Project/src/main/java/Date11_25/Algorithm/GCD.java b/Project/src/main/java/Date11_25/Algorithm/GCD.java new file mode 100644 index 0000000..0bf15ef --- /dev/null +++ b/Project/src/main/java/Date11_25/Algorithm/GCD.java @@ -0,0 +1,37 @@ +package Date11_25.Algorithm; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +/* 최대공약수 구하기(GCD: Greatest Common Divisor) - 코드업 2623번 문제 + 2개의 값을 입력받아 2개의 최대 공약수를 얻을 수 있다. + + 유클리드 호제법 공식 사용하여 최대공약수를 구한다. + 유클리드 호제법 : https://ko.wikipedia.org/wiki/%EC%9C%A0%ED%81%B4%EB%A6%AC%EB%93%9C_%ED%98%B8%EC%A0%9C%EB%B2%95 + */ +public class GCD { + public static int solution(int num, int num2){ + /* 만약 70,42를 입력받는다고 하면 + 70 % 42 = 28 -- num = 70, num2 = 42 + 42 % 28 = 14 -- num = 42, num2 = 28 + 28 % 14 = 0 -- num = 28, num2 = 14 + 14 % 0 -- num = 14, num2 = 0 이므로 재귀함수가 빠져나옴과 동시에 num값을 반환함 + */ + if(num2 == 0) return num; + + return solution(num2,num%num2); + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + System.out.print("첫번째 수를 입력하세요:"); + int num = Integer.parseInt(br.readLine()); + System.out.print("두번째 수를 입력하세요:"); + int num2 = Integer.parseInt(br.readLine()); + + System.out.println(solution(num>num2 ? num:num2,num>num2 ? num2:num)); // 큰값이 첫번째 매개변수로 갈 수 있도록 구성 + + } +} From a2c0637c89c661e336339c2677e9ad6e78247062 Mon Sep 17 00:00:00 2001 From: JIWON <82360230+Bae-Ji-Won@users.noreply.github.com> Date: Mon, 5 Dec 2022 16:46:48 +0900 Subject: [PATCH 307/307] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 75f95b4..228a64a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ ### 🦁 멋쟁이사자처럼 백엔드 +## 목적 : 자바 알고리즘 + # 🗓 공부 일정