-
Notifications
You must be signed in to change notification settings - Fork 0
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
[기본과제/심화과제] 1주차 자바 객체지향 개념/ 은행 구현하기 #1
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "1\uC8FC\uCC28"
Changes from all commits
a116954
26c9166
0d6f3cb
de5392c
7bdf33b
deae38e
c22f5d4
c27be64
96ac7e4
6d54701
b066d0b
1d2ae87
8d9f80e
9eefc8d
063871b
71339c2
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.
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,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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public class Animal { | ||
private String species; | ||
private String name; | ||
private int age; | ||
|
||
public void speak() { | ||
System.out.println("동물이 소리를 냅니다."); | ||
} | ||
|
||
public void drink() { | ||
System.out.println("동물이 물을 마십니다."); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
public class Calculator { | ||
Character operator; | ||
public int add(int a, int b) { | ||
return a + b; | ||
} | ||
public double add(double a, double b) { | ||
return a + b; | ||
} | ||
//여기서는 리턴 타입이 다르기때문에 오버로딩이다! | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public interface Car { | ||
public abstract void turnOn(); | ||
public abstract void turnOff(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
public class ConvenienceStore { | ||
|
||
String brand; | ||
String address; | ||
|
||
int staffCount; | ||
int visitorCount; | ||
|
||
public ConvenienceStore(String brand,String address,int staffCount,int visiotrCount){ | ||
this.brand=brand; | ||
this.address=address; | ||
this.staffCount=staffCount; | ||
this.visitorCount=visiotrCount; | ||
} | ||
public void addStaffCount() { | ||
staffCount++; | ||
} | ||
|
||
public int getStaffCount() { | ||
return staffCount; | ||
} | ||
|
||
public void addVisitorCount() { | ||
visitorCount++; | ||
} | ||
|
||
public void initVisitorCount() { | ||
visitorCount = 0; | ||
} | ||
|
||
public int getVisitorCount() { | ||
return visitorCount; | ||
} | ||
|
||
public void printConvenienceStoreInfo() { | ||
System.out.println("편의점 브랜드: " + brand); | ||
System.out.println("편의점 주소: " + address); | ||
System.out.println("편의점 직원 수: " + staffCount); | ||
System.out.println("편의점 방문자 수: " + visitorCount); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class Dog extends Animal { | ||
private String gender; | ||
public void walk() { | ||
System.out.println("강아지가 산책을 합니다."); | ||
} | ||
//오버라이딩은 부모 클래스의 동작을 재정의! | ||
@Override | ||
public void speak() { | ||
System.out.println("월월"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class GenericClass <T, E> { | ||
T type; | ||
E element; | ||
} | ||
class GenericMethod { | ||
public <T> T genericMethod(T type) { | ||
return type; | ||
} | ||
} | ||
public class GenericTest { | ||
public static void main(String[] args) { | ||
GenericClass<Integer, String> genericClass = new GenericClass<Integer, String>(); | ||
GenericMethod genericMethod = new GenericMethod(); | ||
|
||
String hello = genericMethod.genericMethod("Hello"); | ||
System.out.println(hello); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package HardMisson; | ||
|
||
public interface Bank { | ||
public abstract void deposit(int money); | ||
|
||
|
||
|
||
public abstract void withdraw(int money); | ||
public abstract void checkMoney(); | ||
|
||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package HardMisson; | ||
|
||
public class BankUser { | ||
public static void main(String[] args) { | ||
WooriBank wooriBank=new WooriBank(0,"010-1234-5678","www.wooribank.com"); | ||
//인스턴스 생성,힙에 할당되게 됩니당 | ||
wooriBank.deposit(1000); | ||
wooriBank.checkMoney(); | ||
wooriBank.withdraw(2000);// 에러 처리 발생~ | ||
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. 굿굿!! |
||
} | ||
|
||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package HardMisson; | ||
|
||
import HardMisson.Bank; | ||
|
||
public class WooriBank implements Bank { | ||
|
||
int currentMoney; | ||
String telephone; | ||
String webUrl; | ||
|
||
public WooriBank(int currentMoney,String telephone,String webUrl){ | ||
this.currentMoney=currentMoney; | ||
this.telephone=telephone; | ||
this.webUrl=webUrl; | ||
System.out.println("은행 생성완료!"); | ||
} | ||
@Override | ||
public void deposit(int money) { | ||
this.currentMoney=this.currentMoney+money; | ||
System.out.println(money+"만큼 입금되었습니다!"); | ||
} | ||
|
||
@Override | ||
public void withdraw(int money){ | ||
if(this.currentMoney-money<0){ | ||
System.out.println("잔고가 부족해 출금할 수 없습니다!"); | ||
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. ㅋ실생활에서 없으면 100억부자 가능ㅇ인데 |
||
} | ||
else{ | ||
this.currentMoney=this.currentMoney-money; | ||
System.out.println(money+"만큼 출금되었습니다!");} | ||
}; | ||
@Override | ||
public void checkMoney(){ | ||
System.out.println("현재 은행에 남은 잔고는 "+this.currentMoney+"입니다!"); | ||
}; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
public class Main { | ||
public static void main(String[] args) { | ||
|
||
Animal animal=new Animal(); | ||
animal.speak(); | ||
|
||
ConvenienceStore firstGS = new ConvenienceStore("GS 25", "지구 어딘가", 8, 0); | ||
|
||
firstGS.addStaffCount(); | ||
firstGS.addVisitorCount(); | ||
|
||
firstGS.printConvenienceStoreInfo(); | ||
|
||
Calculator calculator = new Calculator(); | ||
|
||
int intResult = calculator.add(1, 10); | ||
double doubleResult = calculator.add(1, 10); | ||
|
||
System.out.println(intResult); | ||
System.out.println(doubleResult); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public abstract class Person { | ||
private String gender; | ||
|
||
public abstract void walk(); | ||
} | ||
|
||
class Student extends Person { | ||
@Override | ||
public void walk() { | ||
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.
옹 은행을 인터페이스로 만들기 이렇게도 활용할 수 있군여👏
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.
ㅇㅈㅇㅈ그생각은못함