-
Notifications
You must be signed in to change notification settings - Fork 2
feat :: 우주 탐사 관리 시스템 - 탐사대원의 정보, 탐사선 정보 입력 및 출력 #3
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 3 commits
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,29 @@ | ||
| ### IntelliJ IDEA ### | ||
| out/ | ||
| !**/src/main/**/out/ | ||
| !**/src/test/**/out/ | ||
|
|
||
| ### Eclipse ### | ||
| .apt_generated | ||
| .classpath | ||
| .factorypath | ||
| .project | ||
| .settings | ||
| .springBeans | ||
| .sts4-cache | ||
| bin/ | ||
| !**/src/main/**/bin/ | ||
| !**/src/test/**/bin/ | ||
|
|
||
| ### NetBeans ### | ||
| /nbproject/private/ | ||
| /nbbuild/ | ||
| /dist/ | ||
| /nbdist/ | ||
| /.nb-gradle/ | ||
|
|
||
| ### VS Code ### | ||
| .vscode/ | ||
|
|
||
| ### Mac OS ### | ||
| .DS_Store |
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.
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 |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| public class Astronaut { | ||
| private String astronautName; //탐사 대원 이름 | ||
|
|
||
| Astronaut (String astronautName){ | ||
| this.astronautName = astronautName; | ||
| } | ||
|
|
||
| Astronaut(){} | ||
|
|
||
| void setAstronautName(String astronautName){ | ||
| this.astronautName = astronautName; | ||
| } | ||
|
|
||
| void getAstronautName(){ | ||
| System.out.println(astronautName); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| public class Main { | ||
| public static void main(String[] args) { | ||
| Spaceship sp1 = new Spaceship("Apollo","manned"); | ||
| Spaceship sp2 = new Spaceship(); | ||
|
|
||
| sp2.setSpaceshipName("Odyssey"); | ||
| sp2.setSpaceshipHumanStatus("unmanned"); | ||
|
|
||
| Astronaut as1 = new Astronaut("Hello"); | ||
| Astronaut as2 = new Astronaut(); | ||
|
|
||
| as2.setAstronautName("Bye"); | ||
| //이름을 새로 입력하면 가장 최근에 입력된 이름으로 변경된다. | ||
| as2.setAstronautName("GoodBye"); | ||
|
|
||
| //유인 탐사선 sp1 에 탐사대원을 탑승시킨다. | ||
| sp1.addAstronaut(as1); | ||
| sp1.addAstronaut(as2); | ||
| sp1.spaceshipPrintInformation(); | ||
|
|
||
| //무인탐사선에는 탐사대원이 탑승 불가 | ||
| sp2.addAstronaut(as1); | ||
| sp2.spaceshipPrintInformation(); | ||
|
|
||
| //탐사대원이 탐사선에서 내린다. | ||
| sp1.removeAstronaut(as1); | ||
| //내린 탐사대원의 이름은 출력결과에서 사라진다. | ||
| sp1.spaceshipPrintInformation(); | ||
|
|
||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class Spaceship { | ||
| private String spaceshipName; //탐사선이름 | ||
| private String spaceshipHumanStatus; //탐사선이 무인인지 유인인지 | ||
|
||
| private List<Astronaut> astronauts = new ArrayList<>(); //탑승한 탐사 대원 리스트 | ||
|
|
||
| Spaceship(){} | ||
|
|
||
| Spaceship(String spaceshipName, String spaceshipHumanStatus){ | ||
| this.spaceshipName = spaceshipName; | ||
| this.spaceshipHumanStatus = spaceshipHumanStatus; | ||
| } | ||
|
||
|
|
||
| //탐사선 이름을 입력받는 메소드 | ||
| void setSpaceshipName(String spaceshipName){ | ||
| this.spaceshipName = spaceshipName; | ||
| } | ||
|
|
||
| //탐사선이 유인인지 무인인지 입력받는 메소드 | ||
| void setSpaceshipHumanStatus(String spaceshipHumanStatus){ | ||
| this.spaceshipHumanStatus = spaceshipHumanStatus; | ||
| } | ||
|
|
||
| //탐사대원을 추가하는 메소드 | ||
| //무인일 경우 탑승불가 | ||
| void addAstronaut(Astronaut astronaut){ | ||
| if (spaceshipHumanStatus.equals("manned")){ | ||
| this.astronauts.add(astronaut); | ||
| } | ||
| else{ | ||
| System.out.println("\n--------------------------------------\n"); | ||
| System.out.println("선택하신 탐사선 "+spaceshipName+"은 무인 탐사선 입니다."); | ||
| System.out.println("무인 탐사선에는 탐사 대원이 탑승할 수 없습니다."); | ||
| System.out.println("\n--------------------------------------\n"); | ||
| } | ||
| } | ||
|
|
||
| //탐사대원이 탐사선에서 내릴 수 있게 만드는 메소드 | ||
| void removeAstronaut(Astronaut astronaut){ | ||
| this.astronauts.remove(astronaut); | ||
| } | ||
|
|
||
| //탐사선의 정보를 출력하는 메소드 | ||
| //탐서선 이름, 유인인지 무인인지, 탑승한 탐사 대원들의 이름 출력 | ||
| void spaceshipPrintInformation(){ | ||
| System.out.println("\n--------------------------------------\n"); | ||
| System.out.println("탐사전 정보:"); | ||
| System.out.println("\t- 이름: "+spaceshipName); | ||
| if (spaceshipHumanStatus.equals("manned")){ | ||
| System.out.println("\t- 종류: 유인 탐사선"); | ||
| System.out.println("\t- 탐사 대원: "); | ||
| for (Astronaut astronaut : astronauts){ | ||
| System.out.print("\t\t- 탐사 대원: "); | ||
| astronaut.getAstronautName(); | ||
| } | ||
| } | ||
| else{ | ||
| System.out.println("\t- 종류: 무인 탐사선"); | ||
| System.out.println("\t- 탐사 대원: 없음"); | ||
| } | ||
| System.out.println("\n--------------------------------------\n"); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <module type="JAVA_MODULE" version="4"> | ||
| <component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
| <exclude-output /> | ||
| <content url="file://$MODULE_DIR$"> | ||
| <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
| </content> | ||
| <orderEntry type="inheritedJdk" /> | ||
| <orderEntry type="sourceFolder" forTests="false" /> | ||
| </component> | ||
| </module> |
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.
무인과 유인에 따라서 변수가 필요없을 때도 있고 메서드 추가 조건문이 붙을 때도 있으니 상속을 사용해서 우주선 클래스를 만들고 무인선, 유인선 클래스를 각각 만들어서 우주선 클래스를 상속 받으면 좋을 것 같습니다!