Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions Chapter01/src/Calculator.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
public class Calculator {


public int sum = 0;
public int result;

public int add(int num1, int num2) {
int sum;
sum = num1 + num2;
return sum;
}

public int addAll(int num1, int num2, int num3) {
int sum=0;
// Insert code here.
sum = num1 + num2 + num3;
return sum;
}

public int subtract(int num1, int num2) {
int result=num1 - num2;
result = num1 - num2;
return result;
}
public int multiply(int num1, int num2) {
int result=num1 * num2;
result = num1 * num2;
return result;
}
public int divide(int num1, int num2) {
int result=num1 / num2;
result = num1 / num2;
return result;
}

Expand Down
30 changes: 30 additions & 0 deletions Chapter01/src/MyCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
public class MyCalculator {

public int add(int a, int b) {
System.out.printf("%d + %d = %d", a, b, a + b);
System.out.println();
return a + b;
}

public int subtract(int a, int b) {
System.out.printf("%d - %d = %d", a, b, a - b);
System.out.println();
return a - b;
}

public int multiply(int a, int b) {
System.out.printf("%d * %d = %d", a, b, a * b);
System.out.println();
return a * b;
}

public int divide(int a, int b) {
if (b == 0) {
System.out.println("Error: Divided By Zero");
return -1; // unexpected error
}
System.out.printf("%d / %d = %d", a, b, a / b);
System.out.println();
return a / b;
}
}
60 changes: 60 additions & 0 deletions Chapter01/src/MyCalculatorImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import java.util.Scanner;

public class MyCalculatorImpl {

public static void showMenu() {
System.out.println("======= Menu =======");
System.out.println("0. Exit");
System.out.println("1. Add");
System.out.println("2. Subtract");
System.out.println("3. Multiply");
System.out.println("4. Divide");
System.out.println("Please put the command number:");
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
MyCalculator myCalculator = new MyCalculator();
boolean flag = true;
int command = 0;
int a = 0;
int b = 0;
while (flag) {
showMenu();
command = sc.nextInt();
switch (command) {
case 0:
flag = false;
System.out.println("Thanks. See you later :)");
break;
case 1:
System.out.println("Put a, b that you want to add: ");
a = sc.nextInt();
b = sc.nextInt();
myCalculator.add(a, b);
break;
case 2:
System.out.println("Put a, b that you want to subtract: ");
a = sc.nextInt();
b = sc.nextInt();
myCalculator.subtract(a, b);
break;
case 3:
System.out.println("Put a, b that you want to multiply: ");
a = sc.nextInt();
b = sc.nextInt();
myCalculator.multiply(a, b);
break;
case 4:
System.out.println("Put a, b that you want to divide: ");
a = sc.nextInt();
b = sc.nextInt();
myCalculator.divide(a, b);
break;
default:
System.out.println("You got an wrong number. Please try again.");
break;
}
}
}
}
41 changes: 41 additions & 0 deletions Chapter02/src/MyProfile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
public class MyProfile {
private String name = "";
private int age = -1;

public MyProfile(String name) {
this.name = name;
}

public MyProfile(int age) {
this.age = age;
}

public MyProfile(String name, int age) {
this.name = name;
this.age = age;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

@Override
public String toString() {
return "MyProfile{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
6 changes: 6 additions & 0 deletions Chapter02/src/MyProfileImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class MyProfileImpl {
public static void main(String[] args) {
MyProfile profile = new MyProfile("choco-chanel", 25);
System.out.println(profile);
}
}
28 changes: 28 additions & 0 deletions Chapter03/src/MyProfile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public class MyProfile {
String name = "default";
int age = 0;

public static void main(String[] args) {
Profile profile = new Profile();
profile.setName("choco-chanel");
profile.setAge(25);
profile.printName();
profile.printAge();
}

public void setName(String str) {
name = str;
}

public void setAge(int value) {
age = value;
}

public void printName() {
System.out.println("My name is " + name);
}

public void printAge() {
System.out.println("My age is " + age);
}
}
16 changes: 16 additions & 0 deletions Chapter04/src/JavaVariables.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class JavaVariables {
private int instanceVariable;

private static int classVariable;

public void method(String[] parameters) {
int localVariable = this.instanceVariable;
}

public static void main(String[] args) {
System.out.println("Java의 변수는 총 4가지가 있다.");
System.out.println("1) 클래스 변수 vs 2) 인스턴스 변수");
System.out.println("3) Parameter vs 4) 지역 변수");
System.out.println("각 변수는 생명주기와 용도가 다르다");
}
}
64 changes: 54 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,58 @@
# GodOfJava 2nd Edition
자바의신 코드 저장소 입니다.
### CHOCO-CHANEL'S JAVA STUDY LOGS
##### Reference
```python
# Fork: GodOfJava 2nd Edition
# 자바의신 코드 저장소
```

# 예제 실행기 다운로드
상단의 메뉴에서 "Release" 를 클릭하면 파일을 다운로드 할 수 있습니다.
##### Logs
* 01 Programming
> Class & Method <br>
> - A class is the minimum unit of java consisting of state and behavior.
> - A method receives the parameter and returns the calculation result. <br>

# 연습문제 답
연습문제의 답은 각 챕터의 링크를 따라가면 확인할 수 있습니다.
예) Chapter01/src 디렉터리로 이동하면 Calculator.java 파일의 소스를 보실 수 있습니다.
* 02 Hello God Of Java
> Building a development Environment
> - Compilation of Java File <br>
> - Printing on the console <br>
> - Comment <br>
```java
public class Sample {
public static void main(String[] args){
System.out.println("Printing on the console.");
}
}
```

# 질문은 자바의 신 카페에~~~
질문은 자바의 신 카페에서 해 주시기 바랍니다.
* 03 Object Oriented Programming
> Concept of Object
> - An object is an instance of a class. <br>
> - A class consists of variables and methods. <br>
```java
public class Calculator {
public static void main(String[] args) {
System.out.println("Constructor");
Calculator myCalculator = new Calculator();
}
}
```

http://cafe.naver.com/godofjava.cafe
* 04 Data Type
> Variables of Java
> - Java has 4 types of variables and each of them has different range of scope and usability. <br>
```python
# === 4 Types of Variables ===
1. Local variables
2. Parameters
3. Instance Variables
4. Class Variables
```
> Data Types
> - Primitive Data Type vs Reference Data Type
```python
# === 4 Types of Variables ===
1. Local variables
2. Parameters
3. Instance Variables
4. Class Variables
```
Binary file added out/production/Chapter01/Calculator.class
Binary file not shown.
Binary file added out/production/Chapter01/MyCalculator.class
Binary file not shown.
Binary file added out/production/Chapter01/MyCalculatorImpl.class
Binary file not shown.
Binary file added out/production/Chapter02/MyProfile.class
Binary file not shown.
Binary file added out/production/Chapter02/MyProfileImpl.class
Binary file not shown.
Binary file added out/production/Chapter02/Profile.class
Binary file not shown.
Binary file added out/production/Chapter03/MyProfile.class
Binary file not shown.
Binary file added out/production/Chapter03/Profile.class
Binary file not shown.