-
Notifications
You must be signed in to change notification settings - Fork 13
[BE] μΈμ§μπ μ λ€μ΄ #13
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 all commits
fb51848
f2fd864
209baaf
0de3f65
9f18091
f14191c
de1f44a
fe95b1a
5ea1424
0f2c1db
67a3f63
5ebbf49
8a22435
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 |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| ## κΈ°λ₯ μꡬμ¬ν | ||
|
|
||
| ### κ°μ²΄λ³ μν | ||
|
|
||
| **View** | ||
| - [x] κ²μ λ²μ (μμ΄/μ«μ)μ λ ₯ λ°κΈ° | ||
| - [x] μ«μ μ λ ₯λ°κΈ° | ||
| - [x] μμ΄ μ λ ₯λ°κΈ° | ||
|
|
||
| **Output** | ||
| - [x] κ²μ μμ 문ꡬ μΆλ ₯ | ||
| - [x] UP/DOWN κ²°κ³Ό μΆλ ₯ | ||
| - [x] μ λ΅μ΄λ©΄ μ λ΅λ¬Έκ΅¬ μΆλ ₯ | ||
| - [x] μλν νμ μΆλ ₯ | ||
|
|
||
| **Controller** | ||
| - [x] κ²μ μμ | ||
| - [ ] μ λ ₯κ° μ ν¨μ± κ²μ¬ | ||
|
|
||
| **Model** | ||
| - [x] λλ€μ μμ± | ||
| - [x] λλ€μλ³΄λ€ μ λ ₯κ°μ΄ ν¬λ©΄ UP νλ¨ | ||
| - [x] λλ€μλ³΄λ€ μ λ ₯κ°μ΄ μμΌλ©΄ DOWN νλ¨ | ||
| - [x] λλ€μκ° μ λ ₯κ°κ³Ό κ°μΌλ©΄ κ²μ μ’ λ£ | ||
| - [x] μλνμ νλ¨ | ||
|
|
||
| **μλ¬μ²λ¦¬** | ||
| - [x] λ²μ μ΄μΈμ κ° μ λ ₯ | ||
| :[ERROR] μ‘΄μ¬νμ§ μλ λ²μ μ λλ€. | ||
| - [ ] λ²μ λ°μ μ«μ μ λ ₯ | ||
| :[ERROR] λ²μ λ΄μ μ«μλ₯Ό μ λ ₯νμΈμ. | ||
| - [ ] λ²μ λ°μ μνλ²³ μ λ ₯ | ||
| :[ERROR] λ²μ λ΄μ μνλ²³μ μ λ ₯νμΈμ. | ||
| - [ ] λ€λ₯Έ νμ μ μ λ ₯κ° μ λ ₯ | ||
| :[ERROR] μ λ ₯ λ¬Έμμ νμ μ΄ λ§μ§ μμ΅λλ€. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| package leets.land; | ||
|
|
||
| import leets.land.controller.Controller; | ||
|
|
||
| public class UpdownApplication { | ||
|
|
||
| public static void main(String[] args) { | ||
| System.out.print("hihi :D"); | ||
| Controller controller = new Controller(); | ||
| controller.play(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package leets.land.constants; | ||
|
|
||
| public class Constants { | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package leets.land.controller; | ||
|
|
||
| import leets.land.model.AlphabetComputer; | ||
| import leets.land.model.NumberComputer; | ||
| import leets.land.view.InputView; | ||
| import leets.land.view.OutputView; | ||
|
|
||
| public class Controller { | ||
| private final static AlphabetComputer alphabetComputer = new AlphabetComputer(); | ||
| private final static NumberComputer numberComputer = new NumberComputer(); | ||
| private final static InputView inputView = new InputView(); | ||
| private final static OutputView outputView = new OutputView(); | ||
|
|
||
| public void play(){ | ||
| outputView.printStart(); | ||
| int version = inputView.getVersion(); | ||
|
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. λ²μ μ΄ λ€λ₯Ό λμ νμ μ΄ λ€λ₯Ό λμ λ²μ μ μ¨μ£Όμλ©΄ μ’μκ±°κ°μμ!! |
||
|
|
||
| if(version == 1){ | ||
| numberPlay(); | ||
| }else if( version == 2) { | ||
| alphabetPlay(); | ||
| }else{ | ||
| outputView.printErrorMessage("μ‘΄μ¬νμ§ μλ λ²μ μ λλ€."); | ||
| play(); | ||
|
Comment on lines
+18
to
+24
Member
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. μμΈ λ©μμ§λ₯Ό μΆλ ₯νκΈ°λ³΄λ€ μμΈλ₯Ό μ‘κ³ λ€μ ν¨μλ₯Ό μ€ννλ λ‘μ§μ ꡬμν΄λ³΄μλ건 μ΄λ¨κΉμ? |
||
| } | ||
| } | ||
| public void numberPlay(){ | ||
| while (true){ | ||
| int input = inputView.getNextNumberGuess(numberComputer.getMin(), numberComputer.getMax()); | ||
| if (!numberComputer.isValidInput(input)) { | ||
| outputView.printErrorMessage("λ²μ λ΄μ μ«μλ₯Ό μ λ ₯νμΈμ."); | ||
| continue; | ||
| } | ||
| if(numberComputer.up(input)){ | ||
| numberComputer.judgeUp(input); | ||
| outputView.printUpDownResult("UP"); | ||
| }else if(numberComputer.down(input)){ | ||
| numberComputer.judgeDown(input); | ||
| outputView.printUpDownResult("DOWN"); | ||
| }else if(numberComputer.correct(input)){ | ||
| outputView.printUpDownResult("μ λ΅ !"); | ||
| outputView.printCount(numberComputer.getCount()); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void alphabetPlay(){ | ||
| while (true){ | ||
| char input = inputView.getNextAlphabetGuess(alphabetComputer.getMin(), alphabetComputer.getMax()); | ||
| if (!alphabetComputer.isValidInput(input)) { | ||
| outputView.printErrorMessage("λ²μ λ΄μ μνλ²³μ μ λ ₯νμΈμ."); | ||
| continue; | ||
| } | ||
|
|
||
| if(alphabetComputer.up(input)){ | ||
| alphabetComputer.judgeUp(input); | ||
| outputView.printUpDownResult("UP"); | ||
| } else if(alphabetComputer.down(input)){ | ||
| alphabetComputer.judgeDown(input); | ||
| outputView.printUpDownResult("DOWN"); | ||
| } else if(alphabetComputer.correct(input)){ | ||
| outputView.printUpDownResult("μ λ΅ !"); | ||
| outputView.printCount(alphabetComputer.getCount()); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package leets.land.model; | ||
|
|
||
| import java.util.regex.Pattern; | ||
|
|
||
| public class AlphabetComputer { | ||
|
|
||
| private static char answer = (char) (Math.random() * ('z'-'A'+1) + 'A'); | ||
| private static int count = 1; | ||
| private static char min = 'A'; | ||
| private static char max = 'z'; | ||
|
|
||
|
|
||
| public int getCount() { | ||
| return count; | ||
| } | ||
|
|
||
| public char getMin(){ | ||
| return min; | ||
| } | ||
| public char getMax(){ | ||
| return max; | ||
| } | ||
| public void judgeUp(char input) { | ||
| count++; | ||
| if (input == 'z') { | ||
| max = 'z'; | ||
| min = 'A'; | ||
| } else { | ||
| min = (char) (input + 1); | ||
| max = 'z'; | ||
| } | ||
| } | ||
|
|
||
| public void judgeDown(char input) { | ||
| count++; | ||
| if (input == 'A') { | ||
| min = 'A'; | ||
| max = 'z'; | ||
| } else { | ||
| max = (char) (input - 1); | ||
| min = 'A'; | ||
| } | ||
| } | ||
|
|
||
| public boolean up(char input) { | ||
| return answer > input; | ||
| } | ||
|
|
||
| public boolean down(char input) { | ||
| return answer < input; | ||
| } | ||
|
|
||
| public boolean correct(char input) { | ||
| return answer == input; | ||
| } | ||
|
|
||
| public boolean isValidInput(char input) { | ||
| return input >= min && input <= max; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package leets.land.model; | ||
|
|
||
| public class NumberComputer { | ||
| private static int answer = (int) (Math.random() * 100) + 1; | ||
| private static int count = 1; | ||
| private static int min = 1; | ||
| private static int max = 100; | ||
|
|
||
|
|
||
| public int getCount() { | ||
| return count; | ||
| } | ||
|
|
||
| public int getMin() { | ||
| return min; | ||
| } | ||
|
|
||
| public int getMax() { | ||
| return max; | ||
| } | ||
|
|
||
| public void judgeUp(int input) { | ||
| count++; | ||
| min = input + 1; | ||
| } | ||
|
|
||
| public void judgeDown(int input) { | ||
| count++; | ||
| max = input - 1; | ||
| } | ||
|
|
||
| public boolean up(int input) { | ||
| return answer > input; | ||
| } | ||
|
|
||
| public boolean down(int input) { | ||
| return answer < input; | ||
| } | ||
|
|
||
| public boolean correct(int input) { | ||
| return answer == input; | ||
| } | ||
|
|
||
| public boolean isValidInput(int input){ | ||
| return input >= min && input <= max; | ||
|
|
||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package leets.land.view; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class InputView { | ||
| private final Scanner scanner; | ||
|
|
||
| public InputView(){ | ||
| scanner = new Scanner(System.in); | ||
| } | ||
| public int getVersion(){ | ||
| System.out.print("λ²μ μ μ λ ₯ν΄μ£ΌμΈμ (μ«μ λ²μ : 1, μμ΄ λ²μ : 2) :"); | ||
| return scanner.nextInt(); | ||
| } | ||
|
|
||
| public int getNextNumberGuess(int min, int max){ | ||
| System.out.printf("μ«μλ₯Ό μ λ ₯ν΄μ£ΌμΈμ(%d ~ %d) : ",min ,max); | ||
| return scanner.nextInt(); | ||
| } | ||
| public char getNextAlphabetGuess(char min, char max){ | ||
| System.out.printf("μμ΄λ₯Ό μ λ ₯ν΄μ£ΌμΈμ(%c ~ %c) : ",min ,max); | ||
| return scanner.next().charAt(0); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package leets.land.view; | ||
|
|
||
| public class OutputView { | ||
| public void printStart(){ | ||
| System.out.println("μ λ€μ΄ κ²μμ μμν©λλ€.\n"); | ||
| } | ||
|
|
||
| public void printUpDownResult(String result){ | ||
| System.out.println(result); | ||
| } | ||
|
|
||
| public void printCount(int count){ | ||
| System.out.println("\nμλν νμ : " + count); | ||
| } | ||
|
|
||
| public void printErrorMessage(String message) { | ||
| System.out.println("[ERROR] " + message); | ||
| } | ||
| } |
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.
μ΄λΆλΆμμ μ΄λ€ λ΄μ©μΌλ‘ μ½λλ₯Ό μμ νκ³ μΆμΌμ ¨λκ±΄μ§ κΆκΈν©λλ€ !!