-
Notifications
You must be signed in to change notification settings - Fork 5
3주차 미션 구현(정규호) #2
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
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| #Sun Mar 09 23:46:53 KST 2025 | ||
| distributionBase=GRADLE_USER_HOME | ||
| distributionPath=wrapper/dists | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip | ||
| networkTimeout=10000 | ||
| validateDistributionUrl=true | ||
| zipStoreBase=GRADLE_USER_HOME | ||
| zipStorePath=wrapper/dists |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,29 @@ | ||
| package mission; | ||
|
|
||
| import mission.Control.PrinterController; | ||
| import mission.Model.PrinterModel; | ||
| import mission.View.PrinterView; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| //Todo: 프로그램 구현 | ||
| PrinterModel model = new PrinterModel(); | ||
| PrinterView view = new PrinterView(); | ||
| PrinterController controller = new PrinterController(model, view); | ||
|
|
||
| Scanner scanner = new Scanner(System.in); | ||
|
|
||
| while (true) { | ||
| System.out.print("출력할 숫자를 입력하세요 (종료: -1): "); | ||
| int number = scanner.nextInt(); | ||
|
|
||
| if (number == -1) { | ||
| System.out.println("프로그램을 종료합니다."); | ||
| break; | ||
| } | ||
|
|
||
| controller.print(number); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package mission.Control; | ||
|
|
||
| import mission.Model.PrinterModel; | ||
| import mission.View.PrinterView; | ||
|
|
||
| public class PrinterController { | ||
| private PrinterModel model; | ||
| private PrinterView view; | ||
|
|
||
| public PrinterController(PrinterModel model, PrinterView view) { | ||
| this.model = model; | ||
| this.view = view; | ||
| } | ||
|
|
||
| public void print(int number) { | ||
| if (!model.getInk().hasEnoughInk()) { | ||
| view.printError("잉크가 부족합니다!"); | ||
| return; | ||
| } | ||
|
|
||
| if (!model.getPaper().hasEnoughPaper()) { | ||
| view.printError("종이가 부족합니다!"); | ||
| return; | ||
| } | ||
|
|
||
| String asciiArt = model.getAsciiArt(number); | ||
| view.printAscii(asciiArt); | ||
|
|
||
| model.getInk().useInk(); | ||
| model.getPaper().usePaper(); | ||
|
|
||
| view.printSuccess(); | ||
| showStatus(); | ||
| } | ||
|
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. 함수 볼륨이 좀 큰 것 같아요 |
||
|
|
||
| public void showStatus() { | ||
| view.printStatus(model.getInk().getInkAmount(), model.getPaper().getPaperAmount()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package mission.Model; | ||
|
|
||
| public class AsciiNumber { | ||
| public String getAsciiArt(int number) { | ||
| switch (number) { | ||
| case 1: | ||
| return " # \n ## \n # \n # \n ### \n"; | ||
|
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. 이렇게 구현해두면 문자를 한 줄로 잇는게 힘들지 않을까요? |
||
| case 2: | ||
| return " ### \n# #\n ## \n # \n#####\n"; | ||
| case 3: | ||
| return " ### \n #\n ## \n #\n ### \n"; | ||
| // 필요한 숫자 더 추가 가능 | ||
| default: | ||
| return "숫자를 다시 입력하세요."; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package mission.Model; | ||
|
|
||
| public class Ink { | ||
| private int inkAmount = 10; | ||
|
|
||
| public int getInkAmount() { | ||
| return inkAmount; | ||
| } | ||
|
|
||
| public boolean hasEnoughInk() { | ||
| return inkAmount > 0; | ||
| } | ||
|
|
||
| public void useInk() { | ||
| inkAmount--; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package mission.Model; | ||
|
|
||
| public class Paper { | ||
| private int paperAmount = 10; | ||
|
|
||
| public int getPaperAmount() { | ||
| return paperAmount; | ||
| } | ||
|
|
||
| public boolean hasEnoughPaper() { | ||
| return paperAmount > 0; | ||
| } | ||
|
|
||
| public void usePaper() { | ||
| paperAmount--; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package mission.Model; | ||
|
|
||
| public class PrinterModel { | ||
| private Ink ink; | ||
| private Paper paper; | ||
| private AsciiNumber asciiNumber; | ||
|
|
||
| public PrinterModel() { | ||
| this.ink = new Ink(); | ||
| this.paper = new Paper(); | ||
| this.asciiNumber = new AsciiNumber(); | ||
| } | ||
|
|
||
| public Ink getInk() { | ||
| return ink; | ||
| } | ||
|
|
||
| public Paper getPaper() { | ||
| return paper; | ||
| } | ||
|
|
||
| public String getAsciiArt(int number) { | ||
| return asciiNumber.getAsciiArt(number); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package mission.View; | ||
|
|
||
| public class PrinterView { | ||
| public void printAscii(String asciiArt) { | ||
| System.out.println(asciiArt); | ||
| } | ||
|
|
||
| public void printStatus(int inkAmount, int paperAmount) { | ||
| System.out.println("남은 잉크: " + inkAmount + " / 남은 종이: " + paperAmount); | ||
| } | ||
|
|
||
| public void printError(String message) { | ||
| System.out.println("오류: " + message); | ||
| } | ||
|
|
||
| public void printSuccess() { | ||
| System.out.println("출력이 성공적으로 완료되었습니다!"); | ||
| } | ||
| } |
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.
뷰를 분리했음에도 Application 단에서 sout을 하는게 관심사의 분리 측면에서 부적절할 수 있을 것 같아요