-
Notifications
You must be signed in to change notification settings - Fork 0
be/main/yeoshin_Java_Lv0 #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
220a827
de9a57d
c5cd3c9
f84fc49
741cf04
9323238
87b6160
6764cd1
cf75d9d
8053391
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,46 @@ | ||||||||||||||||||||||||||||||||||||||
| package com.example.maddaewoole; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import java.util.HashMap; | ||||||||||||||||||||||||||||||||||||||
| import java.util.Random; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| public class Daewoole { | ||||||||||||||||||||||||||||||||||||||
| private final int angryLimit; | ||||||||||||||||||||||||||||||||||||||
| private final HashMap<String, Integer> prevokePoints; | ||||||||||||||||||||||||||||||||||||||
| private int angryPoint; | ||||||||||||||||||||||||||||||||||||||
| private int prevokeCount; | ||||||||||||||||||||||||||||||||||||||
| private boolean punchFlag; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Daewoole() { | ||||||||||||||||||||||||||||||||||||||
| Random random = new Random(); | ||||||||||||||||||||||||||||||||||||||
| angryPoint = 0; | ||||||||||||||||||||||||||||||||||||||
| angryLimit = random.nextInt(41) + 80; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| prevokeCount = 0; | ||||||||||||||||||||||||||||||||||||||
| punchFlag = true; | ||||||||||||||||||||||||||||||||||||||
| prevokePoints = new HashMap<String, Integer>(); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| prevokePoints.put("당신의 지각비, 회식비로 대체되었다", random.nextInt(21)); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| prevokePoints.put("코딩 그렇게 하는거 아닌데", random.nextInt(21) + 10); | ||||||||||||||||||||||||||||||||||||||
| prevokePoints.put("오늘 저녁은 감탄계", random.nextInt(21) + 30); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| public int getAngryPoint() { | ||||||||||||||||||||||||||||||||||||||
| return (angryPoint); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| public boolean getPunchFlag() { | ||||||||||||||||||||||||||||||||||||||
| return (punchFlag); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| public int bePrevoked(String ment) { | ||||||||||||||||||||||||||||||||||||||
| angryPoint += prevokePoints.get(ment); | ||||||||||||||||||||||||||||||||||||||
| prevokeCount++; | ||||||||||||||||||||||||||||||||||||||
| if (angryPoint > angryLimit) | ||||||||||||||||||||||||||||||||||||||
| punchFlag = false; | ||||||||||||||||||||||||||||||||||||||
| return (prevokePoints.get(ment)); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| public boolean getPunchFlag() { | |
| return (punchFlag); | |
| } | |
| public int bePrevoked(String ment) { | |
| angryPoint += prevokePoints.get(ment); | |
| prevokeCount++; | |
| if (angryPoint > angryLimit) | |
| punchFlag = false; | |
| return (prevokePoints.get(ment)); | |
| public boolean isDaewooleAngered() { | |
| return angryPoint > angryLimit; | |
| } | |
| public int bePrevoked(String ment) { | |
| angryPoint += prevokePoints.get(ment); | |
| prevokeCount++; | |
| return prevokePoints.get(ment); |
punchFlag 대신 (angryPoint > angryLimit)로 임계점을 판단하는 게 더 좋을 것 같습니다
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,5 +1,26 @@ | ||||||
| package com.example.maddaewoole; | ||||||
|
|
||||||
| import java.util.ArrayList; | ||||||
| import java.util.Random; | ||||||
|
|
||||||
| public class Jpark2 { | ||||||
| private final ArrayList<String> ment; // final을 붙이면 arraylist 객체의 주소를 변경할 수 없는거지 ArrayList 클래스 내부 메서드를 이용한 값 변경은 가능하다 | ||||||
|
||||||
|
|
||||||
| Jpark2() { | ||||||
| ment = new ArrayList<String>(); | ||||||
| ment.add("당신의 지각비, 회식비로 대체되었다"); | ||||||
| ment.add("코딩 그렇게 하는거 아닌데"); | ||||||
| ment.add("오늘 저녁은 감탄계"); | ||||||
| } | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 구현체로 선언 하고, 생성자에서 초기화 후 값을 채워넣는 방식이군용
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ArrayList의 생성자 괄호 속에는 초기 용량 또는 Collection만 가능하다는 것을 알 수 있었습니다. 감사합니다 :) |
||||||
|
|
||||||
| public String prevoke() { | ||||||
|
||||||
| public String prevoke() { | |
| public String provoke() { |
오타 이슈
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,22 @@ | |||||||||||||||
| public class Main { | ||||||||||||||||
|
|
||||||||||||||||
| public static void main(String[] args) { | ||||||||||||||||
| Jpark2 jpark2 = new Jpark2(); | ||||||||||||||||
| Daewoole daewoole = new Daewoole(); | ||||||||||||||||
|
|
||||||||||||||||
| while (true) { | ||||||||||||||||
| String ment; | ||||||||||||||||
| int prevokePoint; | ||||||||||||||||
|
|
||||||||||||||||
| ment = jpark2.prevoke(); | ||||||||||||||||
| prevokePoint = daewoole.bePrevoked(ment); | ||||||||||||||||
|
||||||||||||||||
| String ment; | |
| int prevokePoint; | |
| ment = jpark2.prevoke(); | |
| prevokePoint = daewoole.bePrevoked(ment); | |
| String ment = jpark2.prevoke(); | |
| int prevokePoint = daewoole.bePrevoked(ment); |
선언과 동시에 할당을 하는 것이 권장돼요
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어디까지나 취향 차이지만, 무한루프보다는 탈줄조건을 while 안에 넣어주는건 어떠신가여?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네 가독성 측면에서 그게 더 좋을 것 같습니다!! 수정 완료했습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
접근제어자가 멀까요? 생성자는 어떤 역할을 하는걸까여??
하나의 클래스에 함께 존재하는 변수와 메서드는 어떤 의미를 가져야 하는가.. 객체지향은 어렵다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아무 생각 없이 cpp처럼 만들었는데 자바에는. default라는게 있었군요. 새로운 접근제어자를 배울 수 있었습니다 감사합니다!!
다른 패키지에서도 생성할 수 있도록 public으로 변경했습니다.