-
Notifications
You must be signed in to change notification settings - Fork 11
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
[201800288 채다영] 1주차 미션을 제출합니다. #4
Open
CHAEGODA
wants to merge
22
commits into
CNU-Likelion:main
Choose a base branch
from
CHAEGODA:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
b73070a
add README
CHAEGODA 890d3f5
refactor : README
CHAEGODA b5bd8c3
refactor : README
CHAEGODA b7abdc8
refactor : README
CHAEGODA 122f690
feat : Application1
CHAEGODA 4d38f19
feat : Application1
CHAEGODA ba3256d
feat : Application2
CHAEGODA 27573ff
feat : Application3
CHAEGODA 524baca
feat : Application4
CHAEGODA 49a2dd5
feat : Application45
CHAEGODA df760c9
feat : Application6
CHAEGODA 99e27a4
feat : Application7
CHAEGODA eb1681e
feat : Application8
CHAEGODA 26f07f3
feat : Application9
CHAEGODA 7a4ca73
feat : Application10
CHAEGODA 02eb68e
feat : Application10
CHAEGODA 46e6c69
feat : Application10
CHAEGODA 91d1ccb
feat : Application10
CHAEGODA 8bd6a98
refactor : Application11
CHAEGODA 9b9c939
refactor : Application12
CHAEGODA a60ef3f
refactor : Application13
CHAEGODA 4601e7e
refactor : Application15
CHAEGODA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## 소감 | ||
기능목록을 작성하고 구현을 해보는 것을 처음해보았는데 생각보다 쉽지 않았습니다. | ||
기본적인 개념이 헷갈라는 것이 있었고 생각한 것을 코드로 작성하는 것이 어려웠습니다. | ||
제대로 작동이 되지 않고 고쳐야 할 부분이 있다는 것을 알지만 어떻게 수정해야하는지 잘 모르겠습니다. | ||
더 고민해 본 후 추가제출 기한에는 제대로 작동되도록 제출하도록 하겠습니다. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,140 @@ | ||
package baseball; | ||
import java.util.*; | ||
import mallang.missionutils.Randoms; | ||
import mallang.missionutils.Console; | ||
|
||
import static mallang.missionutils.Console.readLine; | ||
|
||
public class Application { | ||
public static void main(String[] args) { | ||
//TODO: 숫자 야구 게임 구현 | ||
startGame(); | ||
} | ||
// 게임 시작 | ||
public static void startGame() { | ||
List<Integer> answerNum = createNum(); | ||
|
||
while(true) { | ||
List<Integer> userNum = new ArrayList<>(); | ||
List<Integer> result = checkNum(answer, userNum); | ||
printResult(result); | ||
|
||
if (result[2] == 3) { | ||
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. result[2] == 3이 정확히 뭘 의미하는지 알기 어려워요! |
||
System.out.println("3개의 숫자를 모두 맞히셨습니다! 게임 종료 "); | ||
break; | ||
} | ||
if(!continueGame()) { | ||
break; | ||
} | ||
} | ||
} | ||
public static List<Integer> createNum() { // 변경 O | ||
ArrayList<Integer> answer = new List<>(); | ||
for(int i = 0; i < answer.size(); i++) { | ||
answer.set(i, Randoms.pickNumberInRange(1, 9)); | ||
} | ||
return answer; | ||
} | ||
|
||
public static List<Integer> userNum() { // 변경 O | ||
String input; | ||
System.out.println("숫자를 입력해주세요 : "); | ||
|
||
input = readLine(); | ||
if(input.length() > 3) { | ||
throw new IllegalArgumentException(); | ||
} | ||
alreadyNum(input); | ||
List<Integer> guess = parseInput(input); | ||
return guess; | ||
} | ||
public static void alreadyNum(String input) { // 변경 O | ||
boolean containNum; | ||
List<Integer> nums = new ArrayList<>(); | ||
for(int i = 0; i < 3; i++) { | ||
int idx = Integer.parseInt(String.valueOf(input.charAt(i))); | ||
|
||
containNum = !(nums.contains(idx)); | ||
if(containNum) { | ||
nums.add(idx); | ||
} | ||
else { | ||
throw new IllegalArgumentException(); | ||
} | ||
} | ||
} | ||
public static List<Integer> parseInput(String input) { // 변경 O | ||
List<Integer> guess = new List<>(); | ||
for(int i = 0; i < 3; i++) { | ||
char num = input.charAt(i); | ||
String strNum = String.valueOf(num); | ||
if(checkInput(strNum, 1, 9)) { | ||
guess.add(Integer.parseInt(strNum)); | ||
} | ||
} | ||
return guess; | ||
} | ||
public static boolean checkInput(String input, int start, int end) throws IllegalArgumentException { // 오류발생 | ||
try { | ||
int num = Integer.parseInt(input); | ||
if((start <= num) && (num <= end)) { | ||
return true; | ||
} | ||
else { | ||
throw new IllegalArgumentException(); | ||
} | ||
catch (IllegalArgumentException e) { | ||
throw e; | ||
} | ||
} | ||
|
||
// 정답 확인 함수 | ||
public static List<Integer> compareNum(List<Integer> answer, List<Integer> guess) { | ||
List<Integer> result = new ArrayList<>(); | ||
countBalls(answer, guess, result); | ||
countStrikes(answer, guess, result); | ||
result.set(2, 3 - result.get(0) - result.get(1)); // 낫싱 개수 | ||
return result; | ||
} | ||
// 볼 개수 | ||
public static void countBalls(List<Integer> answer, List<Integer> guess, List<Integer> result) { | ||
for(int i = 0; i < answer.size(); i++) { | ||
for(int j = 0; j < guess.size(); j++) { | ||
if(answer.get(i).equals(guess.get(j)) && i != j) { | ||
result.set(0, result.get(0) + 1); | ||
} | ||
} | ||
} | ||
} | ||
// 스트라이크 개수 | ||
public static void countStrikes(List<Integer> answer, List<Integer> guess, List<Integer> result) { | ||
for(int i = 0; i < answer.size(); i++) { | ||
if(answer.get(i).equals(guess.get(i))) { | ||
result.set(1, result.get(1) + 1); | ||
} | ||
} | ||
} | ||
// 결과 출력 (출력 수정 필요) | ||
public static void printResult(List<Integer> result) { | ||
System.out.println(result.get(0) + "볼 " + result.get(1) + "스트라이크 " + result.get(2) + "낫싱"); | ||
} | ||
// 게임 재시작 여부 | ||
public static boolean continueGame() { | ||
System.out.println("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요."); | ||
String restart = readLine(); | ||
|
||
if (restart.length() != 1) { | ||
throw new IllegalArgumentException(); | ||
} | ||
|
||
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. 공백 제거 부탁드려용! |
||
checkInput(restart,1,2); | ||
|
||
if (restart.equals("1")) { | ||
return true; | ||
} else if (restart.equals("2")) { | ||
return false; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
기능 목록 잘 작성해주셨네요 💯