Skip to content

Commit cd66380

Browse files
committed
JAVA_basic lecture source code
0 parents  commit cd66380

File tree

234 files changed

+3760
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+3760
-0
lines changed

.gitignore

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
### IntelliJ IDEA ###
2+
out/
3+
!**/src/main/**/out/
4+
!**/src/test/**/out/
5+
6+
### Eclipse ###
7+
.apt_generated
8+
.classpath
9+
.factorypath
10+
.project
11+
.settings
12+
.springBeans
13+
.sts4-cache
14+
bin/
15+
!**/src/main/**/bin/
16+
!**/src/test/**/bin/
17+
18+
### NetBeans ###
19+
/nbproject/private/
20+
/nbbuild/
21+
/dist/
22+
/nbdist/
23+
/.nb-gradle/
24+
25+
### VS Code ###
26+
.vscode/
27+
28+
### Mac OS ###
29+
.DS_Store

.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/uiDesigner.xml

+124
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java-basic.iml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

src/Main.java

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
2+
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
3+
public class Main {
4+
public static void main(String[] args) {
5+
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
6+
// to see how IntelliJ IDEA suggests fixing it.
7+
System.out.printf("Hello and welcome!");
8+
9+
for (int i = 1; i <= 5; i++) {
10+
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
11+
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
12+
System.out.println("i = " + i);
13+
}
14+
}
15+
}

src/access/BankAccount.java

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package access;
2+
3+
public class BankAccount {
4+
5+
private int balance;
6+
7+
public BankAccount() {
8+
balance = 0;
9+
}
10+
11+
//public 메서드: deposit
12+
public void deposit(int amount) {
13+
if (isAmountValid(amount)) {
14+
balance += amount;
15+
} else {
16+
System.out.println("유효하지 않은 금액입니다.");
17+
}
18+
}
19+
20+
//public 메서드: withdraw
21+
public void withdraw(int amount) {
22+
if (isAmountValid(amount) && balance - amount >= 0) {
23+
balance -= amount;
24+
} else {
25+
System.out.println("유효하지 않은 금액이거나 잔액이 부족합니다.");
26+
}
27+
}
28+
29+
//public 메서드: getBalance
30+
public int getBalance() {
31+
return balance;
32+
}
33+
private boolean isAmountValid(int amount) {
34+
//금액이 0보다 커야함
35+
return amount > 0;
36+
}
37+
}

src/access/BankAccountMain.java

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package access;
2+
3+
public class BankAccountMain {
4+
5+
public static void main(String[] args) {
6+
BankAccount account = new BankAccount();
7+
account.deposit(10000);
8+
account.withdraw(3000);
9+
System.out.println("balance = " + account.getBalance());
10+
}
11+
}

src/access/Speaker.java

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package access;
2+
3+
public class Speaker {
4+
private int volume;
5+
6+
Speaker(int volume) {
7+
this.volume = volume;
8+
}
9+
10+
void volumeUp() {
11+
if (volume >= 100) {
12+
System.out.println("음량을 증가할 수 없습니다. 최대 음량입니다.");
13+
} else {
14+
volume += 10;
15+
System.out.println("음량을 10 증가합니다.");
16+
}
17+
}
18+
19+
void volumeDown() {
20+
volume -= 10;
21+
System.out.println("volumeDown 호출");
22+
}
23+
24+
void showVolume() {
25+
System.out.println("현재 음량: " + volume);
26+
}
27+
}

src/access/SpeakerMain.java

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package access;
2+
3+
public class SpeakerMain {
4+
public static void main(String[] args) {
5+
Speaker speaker = new Speaker(90);
6+
speaker.showVolume();
7+
8+
speaker.volumeUp();
9+
speaker.showVolume();
10+
11+
speaker.volumeUp();
12+
speaker.showVolume();
13+
14+
//필드에 직접 접근
15+
System.out.println("volume 필드 직접 접근 수정");
16+
//speaker.volume = 200;
17+
speaker.showVolume();
18+
}
19+
}

src/access/a/AccessData.java

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package access.a;
2+
3+
public class AccessData {
4+
5+
public int publicField;
6+
int defaultField;
7+
private int privateField;
8+
9+
public void publicMethod() {
10+
System.out.println("publicMethod 호출 " + publicField);
11+
}
12+
13+
void defaultMethod() {
14+
System.out.println("defaultMethod 호출 " + defaultField);
15+
}
16+
17+
private void privateMethod() {
18+
System.out.println("privateMethod 호출 " + privateField);
19+
}
20+
21+
public void innerAccess() {
22+
System.out.println("내부 호출");
23+
publicField = 100;
24+
defaultField = 200;
25+
privateField = 300;
26+
publicMethod();
27+
defaultMethod();
28+
privateMethod();
29+
}
30+
}

src/access/a/AccessInnerMain.java

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package access.a;
2+
3+
public class AccessInnerMain {
4+
public static void main(String[] args) {
5+
AccessData data = new AccessData();
6+
//public 호출 가능
7+
data.publicField = 1;
8+
data.publicMethod();
9+
10+
//같은 패키지 default호출 가능
11+
data.defaultField = 2;
12+
data.defaultMethod();
13+
14+
//private 호출 불가
15+
//data.privateField = 3;
16+
//data.privateMethod();
17+
18+
data.innerAccess();
19+
}
20+
}

src/access/a/PublicClass.java

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package access.a;
2+
3+
public class PublicClass {
4+
public static void main(String[] args) {
5+
PublicClass publicClass = new PublicClass();
6+
DefaultClass1 class1 = new DefaultClass1();
7+
DefaultClass2 class2 = new DefaultClass2();
8+
}
9+
}
10+
11+
class DefaultClass1 {
12+
13+
}
14+
15+
class DefaultClass2 {
16+
17+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package access.a;
2+
3+
public class PublicClassInnerMain {
4+
public static void main(String[] args) {
5+
PublicClass publicClass = new PublicClass();
6+
DefaultClass1 class1 = new DefaultClass1();
7+
DefaultClass2 class2 = new DefaultClass2();
8+
}
9+
}

0 commit comments

Comments
 (0)