├── Chapter1
├── .classpath
├── .gitignore
├── .project
├── .settings
│ ├── org.eclipse.core.resources.prefs
│ └── org.eclipse.jdt.core.prefs
└── src
│ ├── ch01
│ └── HelloJava.java
│ ├── ch04
│ └── BinaryTest.java
│ ├── ch05
│ └── VariableTest.java
│ ├── ch06
│ └── IntegerTest.java
│ ├── ch07
│ ├── DoubleTest.java
│ └── DoubleTest2.java
│ ├── ch08
│ └── CharacterTest.java
│ ├── ch09
│ ├── BooleanTest.java
│ └── LocalVariableType.java
│ ├── ch10
│ ├── ConstantTest.java
│ └── TypeConversion.java
│ ├── ch11
│ └── OperatorTest.java
│ ├── ch12
│ ├── LogicalTest.java
│ ├── RealtionalTest.java
│ └── ShortCircuit.java
│ ├── ch13
│ ├── BitTest.java
│ └── ConditionTest.java
│ ├── ch15
│ ├── IfElseIfElseTest.java
│ └── IfIfTest.java
│ ├── ch16
│ ├── SwitchCaseTest.java
│ ├── SwitchCaseTest2.java
│ └── SwitchCaseUpTest.java
│ ├── ch17
│ └── WhileTest.java
│ ├── ch18
│ └── DowhileTest.java
│ ├── ch19
│ └── ForTest.java
│ ├── ch20
│ └── NestedLoopTest.java
│ └── ch21
│ ├── BreakTest.java
│ └── ContinueTest.java
├── Chapter2
├── .classpath
├── .gitignore
├── .project
├── .settings
│ ├── org.eclipse.core.resources.prefs
│ └── org.eclipse.jdt.core.prefs
└── src
│ ├── ch02
│ ├── Order.java
│ ├── Student.java
│ └── UserInfo.java
│ ├── ch03
│ └── FunctionTest.java
│ ├── ch04
│ ├── Student.java
│ └── StudentTest.java
│ ├── ch06
│ ├── Student.java
│ └── StudentTest.java
│ ├── ch07
│ ├── UserInfo.java
│ └── UserInfoTest.java
│ ├── ch08
│ ├── Order.java
│ ├── OrderTest.java
│ ├── Person.java
│ └── PersonTest.java
│ ├── ch09
│ ├── Student.java
│ ├── StudentTest.java
│ └── Subject.java
│ ├── ch10
│ ├── BirthDay.java
│ └── BirthDayTest.java
│ ├── ch11
│ ├── MakeReport.java
│ └── TestReprt.java
│ ├── ch12
│ └── Person.java
│ ├── ch14
│ ├── Bus.java
│ ├── Student.java
│ ├── Subway.java
│ └── TakeTransTest.java
│ ├── ch15
│ ├── Student.java
│ ├── TakeTransTest.java
│ └── Taxi.java
│ ├── ch16
│ ├── Employee.java
│ └── EmployeeTest.java
│ ├── ch17
│ ├── Employee.java
│ ├── EmployeeTest.java
│ └── EmployeeTest2.java
│ ├── ch18
│ ├── Company.java
│ └── CompanyTest.java
│ ├── ch19
│ ├── Car.java
│ ├── CarFactory.java
│ └── CarFactoryTest.java
│ ├── ch20
│ ├── ArrayTest.java
│ └── CharArrayTest.java
│ ├── ch21
│ ├── Book.java
│ ├── BookArrayTest.java
│ ├── ObjectCopy.java
│ └── ObjectCopy2.java
│ ├── ch22
│ └── TwoDimensionTest.java
│ ├── ch23
│ └── ArrayListTest.java
│ └── ch24
│ ├── Student.java
│ ├── StudentTest.java
│ └── Subject.java
├── Chapter3
├── .classpath
├── .gitignore
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── db.properties
├── db.properties~
└── src
│ ├── ch02
│ ├── Customer.java
│ ├── CustomerTest.java
│ └── VIPCustomer.java
│ ├── ch03
│ ├── Customer.java
│ ├── CustomerTest.java
│ └── VIPCustomer.java
│ ├── ch04
│ ├── Customer.java
│ ├── CustomerTest.java
│ └── VIPCustomer.java
│ ├── ch05
│ └── TestMethod.java
│ ├── ch06
│ ├── AnimalTest.java
│ ├── Customer.java
│ ├── CustomerTest.java
│ ├── GoldCustomer.java
│ └── VIPCustomer.java
│ ├── ch08
│ └── AnimalTest.java
│ ├── ch09
│ ├── Computer.java
│ ├── ComputerTest.java
│ ├── DeskTop.java
│ ├── MyNoteBook.java
│ └── NoteBook.java
│ ├── ch10
│ ├── AICar.java
│ ├── Car.java
│ ├── CarTest.java
│ ├── Define.java
│ ├── ManualCar.java
│ └── UsingDefine.java
│ ├── ch11
│ ├── Calc.java
│ ├── Calculator.java
│ ├── CalculatorTest.java
│ └── CompleteCalc.java
│ ├── ch13
│ ├── domain
│ │ └── userinfo
│ │ │ ├── UserInfo.java
│ │ │ └── dao
│ │ │ ├── UserInfoDao.java
│ │ │ ├── mysql
│ │ │ └── UserInfoMySqlDao.java
│ │ │ └── oracle
│ │ │ └── UserInfoOracleDao.java
│ └── userinfo
│ │ └── web
│ │ └── UserInfoClient.java
│ ├── ch14
│ ├── Calc.java
│ ├── Calculator.java
│ ├── CalculatorTest.java
│ └── CompleteCalc.java
│ ├── ch15
│ ├── BookShelf.java
│ ├── BookShelfTest.java
│ ├── Buy.java
│ ├── Customer.java
│ ├── CustomerTest.java
│ ├── MyClass.java
│ ├── MyClassTest.java
│ ├── MyInterface.java
│ ├── Queue.java
│ ├── Sell.java
│ ├── Shelf.java
│ ├── X.java
│ └── Y.java
│ └── ch16
│ ├── gamelevel
│ ├── AdvancedLevel.java
│ ├── BeginnerLevel.java
│ ├── MainBoardPlay.java
│ ├── Player.java
│ ├── PlayerLevel.java
│ ├── SuperLevel.java
│ └── UltraSuperLevel.java
│ └── scheduler
│ ├── LeastJob.java
│ ├── PriorityAllocation.java
│ ├── RoundRobin.java
│ ├── Scheduler.java
│ └── SchedulerTest.java
├── Chapter4
├── .classpath
├── .gitignore
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
└── src
│ ├── ch01
│ └── BookTest.java
│ ├── ch02
│ ├── EqualTest.java
│ └── Student.java
│ ├── ch03
│ ├── StringBuilderTest.java
│ ├── StringTest.java
│ ├── StringTest2.java
│ └── StringTextBlock.java
│ └── ch04
│ ├── ClassTest.java
│ ├── Person.java
│ └── StringTest.java
├── Chapter5
├── .classpath
├── .gitignore
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
└── src
│ ├── ch02
│ ├── MyArray.java
│ ├── MyArrayTest.java
│ └── MyObjectArray.java
│ ├── ch03
│ ├── MyLinkedList.java
│ ├── MyLinkedListTest.java
│ └── MyListNode.java
│ ├── ch04
│ ├── MyArrayStack.java
│ └── MyArrayStackTest.java
│ ├── ch05
│ ├── MyListQueue.java
│ └── MyListQueueTest.java
│ ├── ch06
│ ├── GeneriPrinterTest.java
│ ├── GenericPrinter.java
│ ├── Plastic.java
│ ├── Powder.java
│ └── Water.java
│ ├── ch07
│ ├── GenericPrinter.java
│ ├── GenericPrinterTest.java
│ ├── GenericPrinterTest2.java
│ ├── Material.java
│ ├── MyArrayTest.java
│ ├── MyArrayTest2.java
│ ├── Plastic.java
│ ├── Powder.java
│ ├── ThreeDPrinter.java
│ ├── ThreeDPrinterTest.java
│ └── Water.java
│ ├── ch08
│ ├── GenericMethod.java
│ └── Point.java
│ ├── ch10
│ ├── Member.java
│ ├── MemberArrayList.java
│ └── MemberArrayListTest.java
│ ├── ch12
│ ├── HashSetTest.java
│ ├── Member.java
│ ├── MemberHashSet.java
│ └── MemberHashSetTest.java
│ ├── ch13
│ ├── ComparatorTest.java
│ ├── Member.java
│ ├── MemberTreeSet.java
│ ├── MemberTreeSetTest.java
│ └── TreeSetTest.java
│ └── ch14
│ ├── Member.java
│ ├── MemberHashMap.java
│ └── MemberHashMapTest.java
├── Chapter6
├── .classpath
├── .gitignore
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── a.zip
├── copy.zip
├── data.txt
├── external.out
├── fine.txt
├── input.txt
├── input2.txt
├── log.txt
├── output.txt
├── output2.txt
├── output3.txt
├── outwriter.txt
├── random.txt
├── reader.txt
├── serial.out
├── src
│ ├── ch01
│ │ ├── AnonymousInnerTest.java
│ │ ├── InnerTest.java
│ │ └── LocalInnerTest.java
│ ├── ch03
│ │ ├── Add.java
│ │ ├── MyNumber.java
│ │ ├── TestAdd.java
│ │ └── TestMyNumber.java
│ ├── ch04
│ │ ├── StringConCatImpl.java
│ │ ├── StringConcat.java
│ │ ├── TestLambda.java
│ │ └── TestStringConcat.java
│ ├── ch05
│ │ ├── ArrayListStreamTest.java
│ │ ├── IntArrayStreamTest.java
│ │ └── IntArrayTest.java
│ ├── ch06
│ │ └── ReduceTest.java
│ ├── ch07
│ │ ├── TravelCustomer.java
│ │ └── TravelTest.java
│ ├── ch08
│ │ └── ArrayExceptionHandling.java
│ ├── ch09
│ │ ├── AutoCloseObj.java
│ │ ├── AutoCloseTest.java
│ │ ├── FileExceptionHandling.java
│ │ ├── ThrowsException.java
│ │ └── ThrowsException2.java
│ ├── ch10
│ │ ├── PasswordException.java
│ │ ├── PasswordTest.java
│ │ └── Test.java
│ ├── ch11
│ │ ├── LoggerTest.java
│ │ ├── MyLogger.java
│ │ ├── Student.java
│ │ ├── StudentNameFormatException.java
│ │ └── StudentTest.java
│ ├── ch13
│ │ ├── SystemInTest1.java
│ │ └── SystemInTest2.java
│ ├── ch14
│ │ ├── FileInputStreamTest1.java
│ │ ├── FileInputStreamTest2.java
│ │ ├── FileInputStreamTest3.java
│ │ ├── FileOutputStreamTest1.java
│ │ ├── FileOutputStreamTest2.java
│ │ └── FileOutputStreamTest3.java
│ ├── ch15
│ │ ├── FileInputStreamTest2.java
│ │ ├── FileReaderTest.java
│ │ └── FileWriterTest.java
│ ├── ch16
│ │ ├── BufferedStreamTest.java
│ │ ├── DataStreamTest.java
│ │ ├── FileCopyTest.java
│ │ └── InputStreamReaderTest.java
│ ├── ch17
│ │ └── SerializationTest.java
│ ├── ch18
│ │ ├── FileTest.java
│ │ └── RandomAccessFileTest.java
│ ├── ch19
│ │ ├── Coffee.java
│ │ ├── CoffeeTest.java
│ │ ├── Decorator.java
│ │ ├── EtiopiaAmericano.java
│ │ ├── KenyaAmericano.java
│ │ ├── Latte.java
│ │ ├── Mocha.java
│ │ └── WhippedCream.java
│ ├── ch20
│ │ ├── ThreadTest.java
│ │ └── ThreadTest2.java
│ ├── ch21
│ │ ├── JoinTest.java
│ │ ├── PriorityTest.java
│ │ └── TerminateThread.java
│ ├── ch22
│ │ └── SyncMain.java
│ └── ch23
│ │ └── LibraryMain.java
├── warning.txt
└── writer.txt
├── Chapter7-Up
├── .classpath
├── .gitignore
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
└── src
│ ├── grade
│ ├── BasicEvaluation.java
│ ├── GradeEvaluation.java
│ ├── MajorEvaluation.java
│ └── PassFailEvaluation.java
│ ├── school
│ ├── School.java
│ ├── Score.java
│ ├── Student.java
│ ├── Subject.java
│ └── report
│ │ └── GenerateGradeReport.java
│ ├── test
│ ├── GradeTest.java
│ └── TestMain.java
│ └── utils
│ └── Define.java
├── Chapter7
├── .classpath
├── .gitignore
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
└── src
│ ├── grade
│ ├── BasicEvaluation.java
│ ├── GradeEvaluation.java
│ └── MajorEvaluation.java
│ ├── school
│ ├── School.java
│ ├── Score.java
│ ├── Student.java
│ ├── Subject.java
│ └── report
│ │ └── GenerateGradeReport.java
│ ├── test
│ ├── GradeTest.java
│ └── TestMain.java
│ └── utils
│ └── Define.java
└── Chapter8
├── .classpath
├── .gitignore
├── .project
├── .settings
├── org.eclipse.core.resources.prefs
└── org.eclipse.jdt.core.prefs
└── src
├── ch01
└── MinMaxProblem.java
├── ch02
└── BinarySearchProblem.java
├── ch03
├── HeapSort.java
└── InsertionSort.java
├── ch04
├── bfs
│ └── BfsSearch.java
├── dfs
│ └── DfsSearch.java
└── graph
│ └── UndirectedGraph.java
├── ch05
└── ShortestPath.java
├── ch06
├── maze
│ ├── Maze.java
│ ├── Move.java
│ └── Robot.java
└── test
│ └── MazeTest.java
├── ch07
└── Fibonacci.java
├── ch08
└── GreedyTest.java
├── ch09
└── BruteForceSearch.java
└── ch10
└── CountingProblem.java
/Chapter1/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Chapter1/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 |
--------------------------------------------------------------------------------
/Chapter1/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Chapter1
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Chapter1/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=MS_949
3 |
--------------------------------------------------------------------------------
/Chapter1/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=14
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
13 | org.eclipse.jdt.core.compiler.release=enabled
14 | org.eclipse.jdt.core.compiler.source=14
15 |
--------------------------------------------------------------------------------
/Chapter1/src/ch01/HelloJava.java:
--------------------------------------------------------------------------------
1 | package ch01;
2 |
3 | public class HelloJava {
4 |
5 | public static void main(String[] args) {
6 | System.out.println("Hello, Java");
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/Chapter1/src/ch04/BinaryTest.java:
--------------------------------------------------------------------------------
1 | package ch04;
2 |
3 | public class BinaryTest {
4 |
5 | public static void main(String[] args) {
6 | int num = 10;
7 | int bNum = 0B1010;
8 | int oNum = 012;
9 | int xNum = 0XA;
10 |
11 |
12 | System.out.println(num);
13 | System.out.println(bNum);
14 | System.out.println(oNum);
15 | System.out.println(xNum);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Chapter1/src/ch05/VariableTest.java:
--------------------------------------------------------------------------------
1 | package ch05;
2 |
3 | public class VariableTest {
4 |
5 | public static void main(String[] args) {
6 | int age, count;
7 | age = 10;
8 |
9 | int level = 10000;
10 | System.out.println(age);
11 | System.out.println(level);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Chapter1/src/ch06/IntegerTest.java:
--------------------------------------------------------------------------------
1 | package ch06;
2 |
3 | public class IntegerTest {
4 |
5 | public static void main(String[] args) {
6 | byte bs = 127;
7 |
8 | System.out.println(bs);
9 |
10 | //int iVal = 12345678900;
11 | long lVal = 12345678900L;
12 |
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/Chapter1/src/ch07/DoubleTest.java:
--------------------------------------------------------------------------------
1 | package ch07;
2 |
3 | public class DoubleTest {
4 |
5 | public static void main(String[] args) {
6 | double dnum = 3.14;
7 | float fnum = 3.14F;
8 |
9 | System.out.println(dnum);
10 | System.out.println(fnum);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter1/src/ch07/DoubleTest2.java:
--------------------------------------------------------------------------------
1 | package ch07;
2 |
3 | public class DoubleTest2 {
4 |
5 | public static void main(String[] args) {
6 |
7 | double dnum = 1;
8 |
9 | for(int i = 0; i<10000; i++) {
10 | dnum = dnum + 0.1;
11 | }
12 | System.out.println(dnum);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter1/src/ch08/CharacterTest.java:
--------------------------------------------------------------------------------
1 | package ch08;
2 |
3 | public class CharacterTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | char ch1 = 'A';
8 | System.out.println(ch1);
9 | System.out.println((int)ch1);
10 |
11 | char ch2 = 66;
12 | System.out.println(ch2);
13 |
14 | int ch3 = 67;
15 | System.out.println(ch3);
16 | System.out.println((char)ch3);
17 |
18 | //char ch4 = -66; 음수는 대입 할 수 없음
19 |
20 |
21 | char ch5 = '한';
22 | char ch6 = '\uD55C';
23 |
24 | System.out.println(ch5);
25 | System.out.println(ch6);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Chapter1/src/ch09/BooleanTest.java:
--------------------------------------------------------------------------------
1 | package ch09;
2 |
3 | public class BooleanTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | boolean isMarried = true;
8 | System.out.println(isMarried);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Chapter1/src/ch09/LocalVariableType.java:
--------------------------------------------------------------------------------
1 | package ch09;
2 |
3 | public class LocalVariableType {
4 |
5 | public static void main(String[] args) {
6 |
7 | var i = 10;
8 | var j = 10.0;
9 | var str = "hello";
10 |
11 | System.out.println(i);
12 | System.out.println(j);
13 | System.out.println(str);
14 |
15 | str = "test";
16 | //str = 3;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter1/src/ch10/ConstantTest.java:
--------------------------------------------------------------------------------
1 | package ch10;
2 |
3 | public class ConstantTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | final int MAX_NUM = 100;
8 | final int MIN_NUM;
9 |
10 | MIN_NUM = 0;
11 |
12 | System.out.println(MAX_NUM);
13 | System.out.println(MIN_NUM);
14 |
15 | //MAX_NUM = 1000;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Chapter1/src/ch10/TypeConversion.java:
--------------------------------------------------------------------------------
1 | package ch10;
2 |
3 | public class TypeConversion {
4 |
5 | public static void main(String[] args) {
6 |
7 | double dNum = 1.2;
8 | float fNum = 0.9F;
9 |
10 | int iNum1 = (int)dNum + (int)fNum;
11 | int iNum2 = (int)(dNum + fNum);
12 |
13 | System.out.println(iNum1);
14 | System.out.println(iNum2);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/Chapter1/src/ch11/OperatorTest.java:
--------------------------------------------------------------------------------
1 | package ch11;
2 |
3 | public class OperatorTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | }
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter1/src/ch12/LogicalTest.java:
--------------------------------------------------------------------------------
1 | package ch12;
2 |
3 | public class LogicalTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | int num1 = 10;
8 | int num2 = 20;
9 |
10 | boolean flag = (num1 > 0) && (num2 > 0);
11 | System.out.println(flag);
12 |
13 | flag = (num1 < 0) && (num2 > 0);
14 | System.out.println(flag);
15 |
16 | flag = (num1 > 0) || (num2 > 0);
17 | System.out.println(flag);
18 |
19 | flag = (num1 < 0) || (num2 > 0);
20 | System.out.println(flag);
21 |
22 | flag = !(num1 > 0);
23 | System.out.println(flag);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Chapter1/src/ch12/RealtionalTest.java:
--------------------------------------------------------------------------------
1 | package ch12;
2 |
3 | public class RealtionalTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | int num1 = 5;
8 | int num2 = 3;
9 |
10 | boolean value = (num1 > num2);
11 | System.out.println(value);
12 |
13 | System.out.println(num1 < num2);
14 | System.out.println(num1 >= num2);
15 | System.out.println(num1 <= num2);
16 | System.out.println(num1 == num2);
17 | System.out.println(num1 != num2);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Chapter1/src/ch12/ShortCircuit.java:
--------------------------------------------------------------------------------
1 | package ch12;
2 |
3 | public class ShortCircuit {
4 |
5 | public static void main(String[] args) {
6 |
7 | int num1 = 10;
8 | int i = 2;
9 |
10 | boolean value = ((num1 = num1 + 10 ) < 10) && ( ( i = i + 2 ) < 10);
11 | System.out.println(value);
12 | System.out.println(num1);
13 | System.out.println(i);
14 |
15 | value = ((num1 = num1 + 10 ) < 10) || ( ( i = i + 2 ) < 10);
16 | System.out.println(value);
17 | System.out.println(num1);
18 | System.out.println(i);
19 |
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter1/src/ch13/BitTest.java:
--------------------------------------------------------------------------------
1 | package ch13;
2 |
3 | public class BitTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | int num1 = 5; // 00000101
8 | int num2 = 10; // 00001010
9 |
10 | System.out.println(num1 | num2);
11 | System.out.println(num1 & num2);
12 | System.out.println(num1 ^ num2);
13 | System.out.println(~num1);
14 |
15 | System.out.println(num1 << 2);
16 | System.out.println(num1);
17 | System.out.println(num1 <<= 2);
18 | System.out.println(num1);
19 |
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter1/src/ch13/ConditionTest.java:
--------------------------------------------------------------------------------
1 | package ch13;
2 |
3 | import java.util.Scanner;
4 |
5 | public class ConditionTest {
6 |
7 | public static void main(String[] args) {
8 |
9 | int max;
10 | System.out.println("입력 받은 두 수중 큰 수를 출력하세요\n ");
11 |
12 | Scanner scanner = new Scanner(System.in);
13 | System.out.println("입력1:");
14 | int x = scanner.nextInt();
15 | System.out.println("입력2:");
16 | int y = scanner.nextInt();
17 |
18 | max = (x > y)? x : y;
19 | System.out.println(max);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter1/src/ch15/IfElseIfElseTest.java:
--------------------------------------------------------------------------------
1 | package ch15;
2 |
3 | public class IfElseIfElseTest {
4 |
5 | public static void main(String[] args) {
6 | int age = 12;
7 | int charge;
8 |
9 | if(age < 8){
10 | charge = 1000;
11 | System.out.println("미 취학 아동입니다.");
12 | }
13 | else if(age < 14){
14 | charge = 2000;
15 | System.out.println("초등학생 입니다.");
16 | }
17 | else if(age < 20){
18 | charge = 2500;
19 | System.out.println("중, 고등학생 입니다.");
20 | }
21 | else{
22 | charge = 3000;
23 | System.out.println("일반인 입니다.");
24 | }
25 |
26 | System.out.println("입장료는 " + charge + "원입니다.");
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Chapter1/src/ch15/IfIfTest.java:
--------------------------------------------------------------------------------
1 | package ch15;
2 |
3 | public class IfIfTest {
4 |
5 | public static void main(String[] args) {
6 | int age = 12;
7 | int charge;
8 |
9 | if(age < 8){
10 | charge = 1000;
11 | System.out.println("미 취학 아동입니다.");
12 | }
13 | if(age < 14){
14 | charge = 2000;
15 | System.out.println("초등학생 입니다.");
16 | }
17 | if(age < 20){
18 | charge = 2500;
19 | System.out.println("중, 고등학생 입니다.");
20 | }
21 | else{
22 | charge = 3000;
23 | System.out.println("일반인 입니다.");
24 | }
25 |
26 | System.out.println("입장료는 " + charge + "원입니다.");
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Chapter1/src/ch16/SwitchCaseTest.java:
--------------------------------------------------------------------------------
1 | package ch16;
2 |
3 | public class SwitchCaseTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | int month = 10;
8 | int day;
9 |
10 | switch(month){
11 |
12 | case 1: case 3: case 5: case 7: case 8: case 10: case 12:
13 | day = 31;
14 | break;
15 |
16 | case 4: case 6: case 9: case 11:
17 | day = 30;
18 | break;
19 | case 2:
20 | day = 28;
21 | break;
22 | default:
23 | day = 0;
24 | System.out.println("존재하지 않는 달 입니다.");
25 |
26 | }
27 |
28 | System.out.println(month + "월은 " + day + "일입니다.");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Chapter1/src/ch16/SwitchCaseTest2.java:
--------------------------------------------------------------------------------
1 | package ch16;
2 |
3 | public class SwitchCaseTest2 {
4 |
5 | public static void main(String[] args) {
6 | String medal = "Gold";
7 |
8 | switch(medal) {
9 |
10 | case "Gold":
11 | System.out.println("금메달 입니다.");
12 | break;
13 | case "Silver":
14 | System.out.println("은메달 입니다.");
15 | break;
16 | case "Bronze":
17 | System.out.println("동메달 입니다.");
18 | break;
19 | default:
20 | System.out.println("메달이 없습니다.");
21 | break;
22 | }
23 |
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Chapter1/src/ch16/SwitchCaseUpTest.java:
--------------------------------------------------------------------------------
1 | package ch16;
2 |
3 | public class SwitchCaseUpTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | int month = 10;
8 |
9 | int day = switch (month) {
10 | case 1, 3, 5, 7, 8, 10,12 -> {
11 | System.out.println("한 달은 31일입니다.");
12 | yield 31;
13 | }
14 | case 4,6,9,11 -> {
15 | System.out.println("한 달은 30일입니다.");
16 | yield 30;
17 | }
18 | case 2 ->{
19 | System.out.println("한 달은 28일입니다.");
20 | yield 28;
21 | }
22 | default->{
23 | System.out.println("존재하지 않는 달 입니다.");
24 | yield 0;
25 | }
26 | };
27 |
28 | System.out.println(month + "월은 " + day + "일입니다.");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Chapter1/src/ch17/WhileTest.java:
--------------------------------------------------------------------------------
1 | package ch17;
2 |
3 | public class WhileTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | int num = 1;
8 | int sum = 0;
9 |
10 | while( num <= 10) {
11 |
12 | sum += num;
13 | num++;
14 | }
15 |
16 | System.out.println(sum);
17 | System.out.println(num);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter1/src/ch18/DowhileTest.java:
--------------------------------------------------------------------------------
1 | package ch18;
2 |
3 | import java.util.Scanner;
4 |
5 | public class DowhileTest {
6 |
7 | public static void main(String[] args) {
8 | Scanner scanner = new Scanner(System.in);
9 | int input;
10 | int sum = 0;
11 |
12 | do {
13 | input = scanner.nextInt();
14 | sum += input;
15 |
16 | }while(input != 0);
17 |
18 | System.out.println(sum);
19 | }
20 | }
--------------------------------------------------------------------------------
/Chapter1/src/ch19/ForTest.java:
--------------------------------------------------------------------------------
1 | package ch19;
2 |
3 | public class ForTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | int count =1;
8 | int sum = 0;
9 |
10 | for( int i = 0 ; i<10; i++, count++) { //10번
11 | sum += count;
12 | count++;
13 | }
14 | System.out.println(sum);
15 |
16 |
17 | int num = 1;
18 | int total = 0;
19 |
20 | while( num <= 10) {
21 | total += num;
22 | num++;
23 | }
24 | System.out.println(total);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Chapter1/src/ch20/NestedLoopTest.java:
--------------------------------------------------------------------------------
1 | package ch20;
2 |
3 | public class NestedLoopTest {
4 |
5 | public static void main(String[] args) {
6 | int dan = 2;
7 | int count = 1;
8 |
9 | for( dan = 2; dan <= 9; dan++) {
10 |
11 | for(count = 1; count <=9; count++) {
12 |
13 | System.out.println( dan + "X" + count + "=" + dan * count);
14 | }
15 | System.out.println();
16 | }
17 |
18 | dan = 2;
19 | while( dan <= 9 ) {
20 | count = 1;
21 | while (count <= 9) {
22 |
23 | System.out.println( dan + "X" + count + "=" + dan * count);
24 | count++;
25 |
26 | }
27 | dan++;
28 | System.out.println();
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Chapter1/src/ch21/BreakTest.java:
--------------------------------------------------------------------------------
1 | package ch21;
2 |
3 | public class BreakTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | int sum = 0;
8 | int num;
9 | for( num = 1; ; num++) {
10 |
11 | sum += num;
12 | if( sum >= 100) break;
13 | }
14 |
15 | System.out.println(sum);
16 | System.out.println(num);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter1/src/ch21/ContinueTest.java:
--------------------------------------------------------------------------------
1 | package ch21;
2 |
3 | public class ContinueTest {
4 |
5 | public static void main(String[] args) {
6 | int num;
7 | for( num = 1; num <= 100; num++) {
8 |
9 | if( (num % 3) != 0) continue;
10 |
11 | System.out.println(num);
12 |
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Chapter2/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Chapter2/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 |
--------------------------------------------------------------------------------
/Chapter2/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Chapter2
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Chapter2/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=MS_949
3 |
--------------------------------------------------------------------------------
/Chapter2/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=14
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
13 | org.eclipse.jdt.core.compiler.release=enabled
14 | org.eclipse.jdt.core.compiler.source=14
15 |
--------------------------------------------------------------------------------
/Chapter2/src/ch02/Order.java:
--------------------------------------------------------------------------------
1 | package ch02;
2 |
3 | public class Order {
4 |
5 | int orderId;
6 | String buyerId;
7 | String sellerId;
8 | int productId;
9 | String orderDate;
10 |
11 | int add(int num1, int num2) {
12 |
13 | int result;
14 | result = num1 + num2;
15 | return result;
16 | }
17 | }
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Chapter2/src/ch02/Student.java:
--------------------------------------------------------------------------------
1 | package ch02;
2 |
3 | public class Student {
4 |
5 | int studentNumber;
6 | String studentName;
7 | int majorCode;
8 | String majorName;
9 | int grade;
10 | }
11 |
--------------------------------------------------------------------------------
/Chapter2/src/ch02/UserInfo.java:
--------------------------------------------------------------------------------
1 | package ch02;
2 |
3 | public class UserInfo {
4 |
5 | String userId;
6 | String userPassWord;
7 | String userName;
8 | String userAddress;
9 | int phoneNumber;
10 | }
11 |
--------------------------------------------------------------------------------
/Chapter2/src/ch03/FunctionTest.java:
--------------------------------------------------------------------------------
1 | package ch03;
2 |
3 | public class FunctionTest {
4 |
5 | public static int addNum(int num1, int num2) {
6 | int result;
7 | result = num1 + num2;
8 | return result;
9 | }
10 |
11 | public static void sayHello(String greeting) {
12 | System.out.println(greeting);
13 | }
14 |
15 | public static int calcSum() {
16 |
17 | int sum = 0;
18 | int i;
19 |
20 | for(i = 0; i<=100; i++) {
21 | sum += i;
22 | }
23 |
24 | return sum;
25 | }
26 |
27 | public static void main(String[] args) {
28 |
29 | int n1 = 10;
30 | int n2 = 20;
31 |
32 | int total = addNum(n1, n2);
33 |
34 | sayHello("안녕하세요");
35 | int num = calcSum();
36 |
37 | System.out.println(total);
38 | System.out.println(num);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Chapter2/src/ch04/Student.java:
--------------------------------------------------------------------------------
1 | package ch04;
2 |
3 | public class Student {
4 |
5 | public int studentID;
6 | public String studentName;
7 | public String address;
8 |
9 | public void showStudentInfo() {
10 | System.out.println(studentName + "," + address);
11 | }
12 |
13 | public String getStudentName() {
14 | return studentName;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Chapter2/src/ch04/StudentTest.java:
--------------------------------------------------------------------------------
1 | package ch04;
2 |
3 | public class StudentTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | Student studentLee = new Student();
8 | studentLee.studentName = "이순신";
9 | studentLee.address = "서울";
10 |
11 |
12 | studentLee.showStudentInfo();
13 |
14 | Student studentKim = new Student();
15 | studentKim.studentName = "김유신";
16 | studentKim.address = "경주";
17 |
18 | studentKim.showStudentInfo();
19 |
20 | System.out.println(studentLee);
21 | System.out.println(studentKim);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/Chapter2/src/ch06/Student.java:
--------------------------------------------------------------------------------
1 | package ch06;
2 |
3 | public class Student {
4 |
5 | public int studentNumber;
6 | public String studentName;
7 | public int grade;
8 |
9 | public Student(int studentNumber, String studentName, int grade) {
10 | this.studentNumber = studentNumber;
11 | this.studentName = studentName;
12 | this.grade = grade;
13 | }
14 |
15 | public String showStudentInfo() {
16 | return studentName + "학생의 학번은 " + studentNumber + "이고, " + grade + "학년 입니다.";
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter2/src/ch06/StudentTest.java:
--------------------------------------------------------------------------------
1 | package ch06;
2 |
3 | public class StudentTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | //Student studentLee = new Student();
8 |
9 | Student studentLee = new Student(12345, "Lee", 3);
10 |
11 | String data = studentLee.showStudentInfo();
12 | System.out.println(data);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/Chapter2/src/ch07/UserInfo.java:
--------------------------------------------------------------------------------
1 | package ch07;
2 |
3 | public class UserInfo {
4 |
5 | public String userId;
6 | public String userPassWord;
7 | public String userName;
8 | public String userAddress;
9 | public String phoneNumber;
10 |
11 | public UserInfo(){}
12 |
13 | public UserInfo(String userId, String userPassWord, String userName) {
14 | this.userId = userId;
15 | this.userPassWord = userPassWord;
16 | this.userName = userName;
17 | }
18 |
19 | public String showUserInfo() {
20 | return "고객님의 아이디는 " + userId + "이고, 등록된 이름은 " + userName + "입니다.";
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Chapter2/src/ch07/UserInfoTest.java:
--------------------------------------------------------------------------------
1 | package ch07;
2 |
3 | public class UserInfoTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | UserInfo userLee = new UserInfo();
8 | userLee.userId = "a12345";
9 | userLee.userPassWord = "zxcvbn12345";
10 | userLee.userName = "Lee";
11 | userLee.phoneNumber = "01034556699";
12 | userLee.userAddress = "Seoul, Korea";
13 |
14 | System.out.println(userLee.showUserInfo());
15 |
16 | UserInfo userKim = new UserInfo("b12345", "09876mnbvc", "Kim");
17 | System.out.println(userKim.showUserInfo());
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Chapter2/src/ch08/Order.java:
--------------------------------------------------------------------------------
1 | package ch08;
2 |
3 | public class Order {
4 |
5 | // Date 나 Calendar 객체를 사용할 줄 알면 시간이나 날짜 대한 값은 해당 객체를 사용하면 됩니다.
6 | // 여기서 숫자에 해당되는 자료형을 String으로 표현한건 0으로 시작될 가능성이 있는 숫자에 해당합니다.
7 |
8 | public String orderNumber;
9 | public String customerPhone;
10 | public String customerAddress;
11 | public String orderDate;
12 | public String orderTime;
13 | public int price;
14 | public String menuId;
15 |
16 | public void showOrderDetail() {
17 |
18 | System.out.println("주문 접수 번호: " + orderNumber);
19 | System.out.println("주문 핸드폰 번호: " + customerPhone);
20 | System.out.println("주문 집 주소: " + customerAddress);
21 | System.out.println("주문 날짜: " + orderDate);
22 | System.out.println("주문 시간: " + orderTime);
23 | System.out.println("주문 가격: " + price);
24 | System.out.println("메뉴 번호: " + menuId);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Chapter2/src/ch08/OrderTest.java:
--------------------------------------------------------------------------------
1 | package ch08;
2 |
3 | public class OrderTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | Order myOrder = new Order();
8 | myOrder.orderNumber = "202011020003";
9 | myOrder.customerPhone = "01023450001";
10 | myOrder.customerAddress = "서울시 강남구 역삼동 111-333";
11 | myOrder.orderDate = "20201102";
12 | myOrder.orderTime = "130258";
13 | myOrder.price = 35000;
14 | myOrder.menuId = "0003";
15 |
16 | myOrder.showOrderDetail();
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/Chapter2/src/ch08/Person.java:
--------------------------------------------------------------------------------
1 | package ch08;
2 |
3 | public class Person {
4 |
5 | public String name;
6 | public int age;
7 | public int height;
8 | public int weight;
9 | public String gender;
10 |
11 | public void showPersonInfo() {
12 | System.out.println("키가 " + height + "이고, 몸무게가 " + weight + "킬로인 "+ gender + "이 있습니다.");
13 | System.out.println("이름은 " + name + "이고, 나이는 " + age + "세입니다" );
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/Chapter2/src/ch08/PersonTest.java:
--------------------------------------------------------------------------------
1 | package ch08;
2 |
3 | public class PersonTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | Person personT = new Person();
8 | personT.name = "Tomas";
9 | personT.age = 37;
10 | personT.height = 180;
11 | personT.weight = 78;
12 | personT.gender = "남성";
13 |
14 | personT.showPersonInfo();
15 |
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter2/src/ch09/Student.java:
--------------------------------------------------------------------------------
1 | package ch09;
2 |
3 | public class Student {
4 |
5 | int studentID;
6 | String studentName;
7 |
8 | Subject korea;
9 | Subject math;
10 |
11 | public Student(int id, String name) {
12 | studentID = id;
13 | studentName = name;
14 |
15 | korea = new Subject();
16 | math = new Subject();
17 | }
18 |
19 |
20 | public void setKoreaSubject(String name, int score) {
21 | korea.subjectName = name;
22 | korea.score = score;
23 | }
24 |
25 | public void setMathSubject(String name, int score) {
26 | math.subjectName = name;
27 | math.score = score;
28 | }
29 |
30 | public void showStudentSocre() {
31 | int total = korea.score + math.score;
32 | System.out.println(studentName + " 학생의 총점은 " + total + "점 입니다." );
33 |
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Chapter2/src/ch09/StudentTest.java:
--------------------------------------------------------------------------------
1 | package ch09;
2 |
3 | public class StudentTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | Student studentLee = new Student(100, "Lee");
8 | studentLee.setKoreaSubject("국어", 100);
9 | studentLee.setMathSubject("수학", 95);
10 |
11 |
12 | Student studentKim = new Student(101, "Kim");
13 | studentKim.setKoreaSubject("국어", 80);
14 | studentKim.setMathSubject("수학", 99);
15 |
16 | studentLee.showStudentSocre();
17 | studentKim.showStudentSocre();
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter2/src/ch09/Subject.java:
--------------------------------------------------------------------------------
1 | package ch09;
2 |
3 | public class Subject {
4 | String subjectName;
5 | int score;
6 | int subjectID;
7 | }
8 |
--------------------------------------------------------------------------------
/Chapter2/src/ch10/BirthDay.java:
--------------------------------------------------------------------------------
1 | package ch10;
2 |
3 | public class BirthDay {
4 | private int day;
5 | private int month;
6 | private int year;
7 |
8 | private boolean isValid;
9 |
10 | public void setDay(int day) {
11 | this.day = day;
12 | }
13 |
14 | public int getDay() {
15 | return day;
16 | }
17 |
18 | public int getMonth() {
19 | return month;
20 | }
21 |
22 | public void setMonth(int month) {
23 |
24 | if ( month < 1 || month > 12) {
25 | isValid = false;
26 | }
27 | else {
28 | this.month = month;
29 | }
30 | }
31 |
32 | public int getYear() {
33 | return year;
34 | }
35 |
36 | public void setYear(int year) {
37 | this.year = year;
38 | }
39 |
40 | public void showDate() {
41 |
42 | if ( isValid) {
43 | System.out.println( year + "년 " + month + "월 " + day + "일 입니다." );
44 | }
45 | else {
46 | System.out.println("유효하지 않은 날짜 입니다");
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Chapter2/src/ch10/BirthDayTest.java:
--------------------------------------------------------------------------------
1 | package ch10;
2 |
3 | public class BirthDayTest {
4 |
5 | public static void main(String[] args) {
6 | BirthDay date = new BirthDay();
7 |
8 | date.setYear(2019);
9 | date.setMonth(77);
10 | date.setDay(100);
11 |
12 | date.showDate();
13 |
14 |
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/Chapter2/src/ch11/MakeReport.java:
--------------------------------------------------------------------------------
1 | package ch11;
2 |
3 | public class MakeReport {
4 |
5 | StringBuffer buffer = new StringBuffer();
6 |
7 | private String line = "===========================================\n";
8 | private String title = " 이름\t 주소 \t\t 전화번호 \n";
9 | private void makeHeader()
10 | {
11 | buffer.append(line);
12 | buffer.append(title);
13 | buffer.append(line);
14 | }
15 |
16 | private void generateBody()
17 | {
18 | buffer.append("James \t");
19 | buffer.append("Seoul Korea \t");
20 | buffer.append("010-2222-3333\n");
21 |
22 | buffer.append("Tomas \t");
23 | buffer.append("NewYork US \t");
24 | buffer.append("010-7777-0987\n");
25 | }
26 |
27 | private void makeFooter()
28 | {
29 |
30 | buffer.append(line);
31 | }
32 |
33 | public String getReport()
34 | {
35 | makeHeader();
36 | generateBody();
37 | makeFooter();
38 | return buffer.toString();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Chapter2/src/ch11/TestReprt.java:
--------------------------------------------------------------------------------
1 | package ch11;
2 |
3 | public class TestReprt {
4 |
5 | public static void main(String[] args) {
6 |
7 | MakeReport report = new MakeReport();
8 | String builder = report.getReport();
9 |
10 | System.out.println(builder);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/Chapter2/src/ch12/Person.java:
--------------------------------------------------------------------------------
1 | package ch12;
2 |
3 | public class Person {
4 |
5 | String name;
6 | int age;
7 |
8 | public Person() {
9 | this("이름없음", 1);
10 | }
11 |
12 | public Person(String name, int age) {
13 | this.name = name;
14 | this.age = age;
15 | }
16 |
17 | public Person getPerson() {
18 | return this;
19 | }
20 |
21 |
22 | public static void main(String[] args)
23 | {
24 | Person p = new Person();
25 | p.name = "James";
26 | p.age = 37;
27 |
28 | Person p2 = p.getPerson();
29 | System.out.println(p);
30 | System.out.println(p2);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Chapter2/src/ch14/Bus.java:
--------------------------------------------------------------------------------
1 | package ch14;
2 |
3 | public class Bus {
4 |
5 | int busNumber;
6 | int passengerCount;
7 | int money;
8 |
9 | public Bus(int busNumber) {
10 | this.busNumber = busNumber;
11 | }
12 |
13 | public void take(int money) { //승차
14 | this.money += money;
15 | passengerCount++;
16 | }
17 |
18 | public void showBusInfo() {
19 | System.out.println(busNumber + "번 버스의 승객은 " + passengerCount + "명 이고, 수입은 " + money + "원 입니다");
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter2/src/ch14/Student.java:
--------------------------------------------------------------------------------
1 | package ch14;
2 |
3 | public class Student {
4 |
5 | String studentName;
6 | int grade;
7 | int money;
8 |
9 | public Student(String studentName, int money) {
10 | this.studentName = studentName;
11 | this.money = money;
12 | }
13 |
14 | public void takeBus(Bus bus) {
15 | bus.take(1000);
16 | this.money -= 1000;
17 | }
18 |
19 | public void takeSubway(Subway subway) {
20 | subway.take(1200);
21 | this.money -= 1200;
22 | }
23 |
24 | public void showInfo() {
25 | System.out.println(studentName +"님의 남은 돈은 " + money + "원 입니다");
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Chapter2/src/ch14/Subway.java:
--------------------------------------------------------------------------------
1 | package ch14;
2 |
3 | public class Subway {
4 |
5 | int lineNumber;
6 | int passengerCount;
7 | int money;
8 |
9 | public Subway(int lineNumber) {
10 | this.lineNumber = lineNumber;
11 | }
12 |
13 | public void take(int money) {
14 | this.money += money;
15 | passengerCount++;
16 | }
17 |
18 | public void showSubwayInfo() {
19 | System.out.println(lineNumber + "번 지하철의 승객은 " + passengerCount + "명 이고, 수입은 " + money + "원 입니다");
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter2/src/ch14/TakeTransTest.java:
--------------------------------------------------------------------------------
1 | package ch14;
2 |
3 | public class TakeTransTest {
4 |
5 | public static void main(String[] args) {
6 | Student studentJ = new Student("James", 5000);
7 | Student studentT = new Student("Tomas", 10000);
8 |
9 | Bus bus100 = new Bus(100);
10 |
11 | Subway subwayGreen = new Subway(2);
12 |
13 |
14 | studentJ.takeBus(bus100);
15 | studentT.takeSubway(subwayGreen);
16 |
17 | studentJ.showInfo();
18 | studentT.showInfo();
19 |
20 | bus100.showBusInfo();
21 |
22 | subwayGreen.showSubwayInfo();
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/Chapter2/src/ch15/Student.java:
--------------------------------------------------------------------------------
1 | package ch15;
2 |
3 | public class Student {
4 |
5 | String studentName;
6 | int grade;
7 | int money;
8 |
9 | public Student(String studentName, int money) {
10 | this.studentName = studentName;
11 | this.money = money;
12 | }
13 |
14 | public void takeTaxi(Taxi taxi) {
15 | taxi.take(10000);
16 | this.money -= 10000;
17 | }
18 |
19 | public void showInfo() {
20 | System.out.println(studentName +"님의 남은 돈은 " + money + "원 입니다");
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Chapter2/src/ch15/TakeTransTest.java:
--------------------------------------------------------------------------------
1 | package ch15;
2 |
3 | public class TakeTransTest {
4 |
5 | public static void main(String[] args) {
6 | Student studentE = new Student("Edward", 20000);
7 | Taxi wellTaxi = new Taxi("잘 간다 운수");
8 | studentE.takeTaxi(wellTaxi);
9 |
10 | studentE.showInfo();
11 | wellTaxi.showTaxInfo();
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter2/src/ch15/Taxi.java:
--------------------------------------------------------------------------------
1 | package ch15;
2 |
3 | public class Taxi {
4 | String companyName;
5 | int money;
6 |
7 | public Taxi(String companyName) {
8 | this.companyName = companyName;
9 | }
10 |
11 | public void take(int money) {
12 | this.money += money;
13 | }
14 |
15 | public void showTaxInfo() {
16 | System.out.println(companyName + "택시 수입은 " + money + "원 입니다.");
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter2/src/ch16/Employee.java:
--------------------------------------------------------------------------------
1 | package ch16;
2 |
3 | public class Employee {
4 |
5 | public static int serialNum = 1000;
6 |
7 | private int employeeId;
8 | private String employeeName;
9 | private String department;
10 |
11 | public Employee()
12 | {
13 | serialNum++;
14 | employeeId = serialNum;
15 | }
16 |
17 | public int getEmployeeId() {
18 | return employeeId;
19 | }
20 | public void setEmployeeId(int employeeId) {
21 | this.employeeId = employeeId;
22 | }
23 | public String getEmployeeName() {
24 | return employeeName;
25 | }
26 | public void setEmployeeName(String employeeName) {
27 | this.employeeName = employeeName;
28 | }
29 | public String getDepartment() {
30 | return department;
31 | }
32 | public void setDepartment(String department) {
33 | this.department = department;
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/Chapter2/src/ch16/EmployeeTest.java:
--------------------------------------------------------------------------------
1 | package ch16;
2 |
3 | public class EmployeeTest {
4 |
5 | public static void main(String[] args) {
6 | Employee employeeLee = new Employee();
7 | employeeLee.setEmployeeName("이순신");
8 |
9 | Employee employeeKim = new Employee();
10 | employeeKim.setEmployeeName("김유신");
11 |
12 | System.out.println(employeeLee.getEmployeeName() + "," + employeeLee.getEmployeeId());
13 | System.out.println(employeeKim.getEmployeeName() + "," + employeeKim.getEmployeeId());
14 |
15 | System.out.println(Employee.serialNum);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Chapter2/src/ch17/Employee.java:
--------------------------------------------------------------------------------
1 | package ch17;
2 |
3 | public class Employee {
4 |
5 | private static int serialNum = 1000;
6 |
7 | private int employeeId;
8 | private String employeeName;
9 | private String department;
10 |
11 | public Employee()
12 | {
13 | serialNum++;
14 | employeeId = serialNum;
15 | }
16 |
17 | public static int getSerialNum() {
18 | return serialNum;
19 | }
20 |
21 | public static void setSerialNum(int serialNum) {
22 | int i = 0;
23 |
24 | // employeeName = "Lee"; //오류발생
25 | Employee.serialNum = serialNum;
26 | }
27 |
28 | public int getEmployeeId() {
29 | return employeeId;
30 | }
31 | public void setEmployeeId(int employeeId) {
32 | this.employeeId = employeeId;
33 | }
34 | public String getEmployeeName() {
35 | return employeeName;
36 | }
37 | public void setEmployeeName(String employeeName) {
38 | this.employeeName = employeeName;
39 | }
40 | public String getDepartment() {
41 | return department;
42 | }
43 | public void setDepartment(String department) {
44 | this.department = department;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/Chapter2/src/ch17/EmployeeTest.java:
--------------------------------------------------------------------------------
1 | package ch17;
2 |
3 | public class EmployeeTest {
4 |
5 | public static void main(String[] args) {
6 | Employee employeeLee = new Employee();
7 | employeeLee.setEmployeeName("이순신");
8 |
9 | Employee employeeKim = new Employee();
10 | employeeKim.setEmployeeName("김유신");
11 |
12 | System.out.println(employeeLee.getEmployeeName() + "," + employeeLee.getEmployeeId());
13 | System.out.println(employeeKim.getEmployeeName() + "," + employeeKim.getEmployeeId());
14 |
15 | System.out.println(Employee.getSerialNum());
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Chapter2/src/ch17/EmployeeTest2.java:
--------------------------------------------------------------------------------
1 | package ch17;
2 |
3 | public class EmployeeTest2 {
4 |
5 | public static void main(String[] args) {
6 |
7 | System.out.println(Employee.getSerialNum());
8 | Employee.setSerialNum(1003);
9 | System.out.println(Employee.getSerialNum());
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Chapter2/src/ch18/Company.java:
--------------------------------------------------------------------------------
1 | package ch18;
2 |
3 | public class Company {
4 |
5 | private static Company instance = new Company();
6 |
7 | private Company() {}
8 |
9 | public static Company getInstance() {
10 |
11 | if( instance == null) {
12 | instance = new Company();
13 | }
14 | return instance;
15 |
16 | }
17 | }
--------------------------------------------------------------------------------
/Chapter2/src/ch18/CompanyTest.java:
--------------------------------------------------------------------------------
1 | package ch18;
2 |
3 | public class CompanyTest {
4 |
5 | public static void main(String[] args) {
6 | Company company1 = Company.getInstance();
7 |
8 | Company company2 = Company.getInstance();
9 |
10 | System.out.println(company1);
11 | System.out.println(company2);
12 |
13 | //Calendar calendar = Calendar.getInstance();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Chapter2/src/ch19/Car.java:
--------------------------------------------------------------------------------
1 | package ch19;
2 |
3 | public class Car {
4 |
5 | private static int serialNum = 10000;
6 | private int carNum;
7 |
8 | public Car() {
9 | serialNum++;
10 | carNum = serialNum;
11 | }
12 |
13 | public int getCarNum() {
14 | return carNum;
15 | }
16 |
17 | public void setCarNum(int carNum) {
18 | this.carNum = carNum;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter2/src/ch19/CarFactory.java:
--------------------------------------------------------------------------------
1 | package ch19;
2 |
3 | public class CarFactory {
4 |
5 | private static CarFactory instance = new CarFactory();
6 |
7 | private CarFactory() {}
8 |
9 | public static CarFactory getInstance() {
10 | if(instance == null) {
11 | instance = new CarFactory();
12 | }
13 | return instance;
14 | }
15 |
16 | public Car createCar() {
17 |
18 | Car car = new Car();
19 | return car;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter2/src/ch19/CarFactoryTest.java:
--------------------------------------------------------------------------------
1 | package ch19;
2 |
3 | public class CarFactoryTest {
4 |
5 | public static void main(String[] args) {
6 | CarFactory factory = CarFactory.getInstance();
7 | Car mySonata = factory.createCar();
8 | Car yourSonata = factory.createCar();
9 |
10 | System.out.println(mySonata.getCarNum());
11 | System.out.println(yourSonata.getCarNum());
12 |
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/Chapter2/src/ch20/ArrayTest.java:
--------------------------------------------------------------------------------
1 | package ch20;
2 |
3 | public class ArrayTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | int[] arr1 = new int[10];
8 | int arr2[] = new int[10];
9 |
10 | int[] numbers = {10, 20, 30};
11 |
12 | for(int i : numbers) {
13 | System.out.println(i);
14 | }
15 |
16 | int[] ids;
17 | ids = new int[] {10, 20, 30};
18 |
19 | for(int i : ids) {
20 | System.out.println(i);
21 | }
22 |
23 | int[] arr = new int[10];
24 | int total = 0;
25 |
26 |
27 | for(int i=0, num=1; i< arr.length; i++, num++) {
28 | arr[i] = num;
29 | }
30 |
31 | for( int i =0; i library = new ArrayList();
11 |
12 | library.add(new Book("태백산맥1", "조정래"));
13 | library.add(new Book("태백산맥2", "조정래"));
14 | library.add(new Book("태백산맥3", "조정래"));
15 | library.add(new Book("태백산맥4", "조정래"));
16 | library.add(new Book("태백산맥5", "조정래"));
17 |
18 | for(int i =0; i subjectList;
10 |
11 | public Student(int studentID, String studentName){
12 | this.studentID = studentID;
13 | this.studentName = studentName;
14 |
15 | subjectList = new ArrayList();
16 | }
17 |
18 | public void addSubject(String name, int score){
19 | Subject subject = new Subject();
20 |
21 | subject.setName(name);
22 | subject.setScorePoint(score);
23 | subjectList.add(subject);
24 | }
25 |
26 | public void showStudentInfo()
27 | {
28 | int total = 0;
29 |
30 | for(Subject s : subjectList){
31 |
32 | total += s.getScorePoint();
33 | System.out.println("학생 " + studentName + "의 " + s.getName() + " 과목 성적은 " +
34 | s.getScorePoint() + "입니다.");
35 | }
36 |
37 | System.out.println("학생 " + studentName + "의 총점은 " + total + " 입니다.");
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Chapter2/src/ch24/StudentTest.java:
--------------------------------------------------------------------------------
1 | package ch24;
2 |
3 | public class StudentTest {
4 |
5 | public static void main(String[] args) {
6 | Student studentLee = new Student(1001, "Lee");
7 |
8 | studentLee.addSubject("국어", 100);
9 | studentLee.addSubject("수학", 50);
10 |
11 | Student studentKim = new Student(1002, "Kim");
12 |
13 | studentKim.addSubject("국어", 70);
14 | studentKim.addSubject("수학", 85);
15 | studentKim.addSubject("영어", 100);
16 |
17 | studentLee.showStudentInfo();
18 | System.out.println("======================================");
19 | studentKim.showStudentInfo();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter2/src/ch24/Subject.java:
--------------------------------------------------------------------------------
1 | package ch24;
2 |
3 | public class Subject {
4 |
5 | private String name;
6 | private int scorePoint;
7 |
8 | public String getName() {
9 | return name;
10 | }
11 | public void setName(String name) {
12 | this.name = name;
13 | }
14 | public int getScorePoint() {
15 | return scorePoint;
16 | }
17 | public void setScorePoint(int scorePoint) {
18 | this.scorePoint = scorePoint;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter3/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Chapter3/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 |
--------------------------------------------------------------------------------
/Chapter3/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Chapter3
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Chapter3/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6 | org.eclipse.jdt.core.compiler.compliance=14
7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=enabled
12 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
13 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
14 | org.eclipse.jdt.core.compiler.release=enabled
15 | org.eclipse.jdt.core.compiler.source=14
16 |
--------------------------------------------------------------------------------
/Chapter3/db.properties:
--------------------------------------------------------------------------------
1 | DBTYPE=MYSQL
2 |
--------------------------------------------------------------------------------
/Chapter3/db.properties~:
--------------------------------------------------------------------------------
1 | DBTYPE=ORACLE
2 |
--------------------------------------------------------------------------------
/Chapter3/src/ch02/Customer.java:
--------------------------------------------------------------------------------
1 | package ch02;
2 |
3 | public class Customer {
4 |
5 | protected int customerID;
6 | protected String customerName;
7 | protected String customerGrade;
8 | int bonusPoint;
9 | double bonusRatio;
10 |
11 | public Customer() {
12 | customerGrade = "SILVER";
13 | bonusRatio = 0.01;
14 | }
15 |
16 | public int calcPrice(int price) {
17 | bonusPoint += price * bonusRatio;
18 | return price;
19 | }
20 |
21 |
22 | public int getCustomerID() {
23 | return customerID;
24 | }
25 |
26 | public void setCustomerID(int customerID) {
27 | this.customerID = customerID;
28 | }
29 |
30 | public String getCustomerName() {
31 | return customerName;
32 | }
33 |
34 | public void setCustomerName(String customerName) {
35 | this.customerName = customerName;
36 | }
37 |
38 | public String getCustomerGrade() {
39 | return customerGrade;
40 | }
41 |
42 | public void setCustomerGrade(String customerGrade) {
43 | this.customerGrade = customerGrade;
44 | }
45 |
46 | public String showCustomerInfo() {
47 | return customerName + "님의 등급은 " + customerGrade +
48 | "이며, 보너스 포인트는 " + bonusPoint + "입니다";
49 |
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Chapter3/src/ch02/CustomerTest.java:
--------------------------------------------------------------------------------
1 | package ch02;
2 |
3 | public class CustomerTest {
4 |
5 | public static void main(String[] args) {
6 | Customer customerLee = new Customer();
7 | customerLee.setCustomerName("이순신");
8 | customerLee.setCustomerID(10010);
9 | customerLee.bonusPoint = 1000;
10 | System.out.println(customerLee.showCustomerInfo());
11 |
12 |
13 | VIPCustomer customerKim = new VIPCustomer();
14 | customerKim.setCustomerName("김유신");
15 | customerKim.setCustomerID(10020);
16 | customerKim.bonusPoint = 10000;
17 | System.out.println(customerKim.showCustomerInfo());
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Chapter3/src/ch02/VIPCustomer.java:
--------------------------------------------------------------------------------
1 | package ch02;
2 |
3 | public class VIPCustomer extends Customer{
4 |
5 | private int agentID;
6 | double salesRatio;
7 |
8 | public VIPCustomer() {
9 | customerGrade = "VIP"; //오류 발생
10 | bonusRatio = 0.05;
11 | salesRatio = 0.1;
12 | }
13 |
14 | public int getAgentID() {
15 | return agentID;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Chapter3/src/ch03/Customer.java:
--------------------------------------------------------------------------------
1 | package ch03;
2 |
3 | public class Customer {
4 |
5 | protected int customerID;
6 | protected String customerName;
7 | protected String customerGrade;
8 | int bonusPoint;
9 | double bonusRatio;
10 |
11 | /*public Customer() {
12 | customerGrade = "SILVER";
13 | bonusRatio = 0.01;
14 |
15 | System.out.println("Customer() 생성자 호출");
16 | }*/
17 |
18 | public Customer(int customerID, String customerName) {
19 | this.customerID = customerID;
20 | this.customerName = customerName;
21 |
22 | customerGrade = "SILVER";
23 | bonusRatio = 0.01;
24 | System.out.println("Customer(int, String) 생성자 호출");
25 | }
26 |
27 | public int calcPrice(int price) {
28 | bonusPoint += price * bonusRatio;
29 | return price;
30 | }
31 |
32 |
33 | public int getCustomerID() {
34 | return customerID;
35 | }
36 |
37 | public void setCustomerID(int customerID) {
38 | this.customerID = customerID;
39 | }
40 |
41 | public String getCustomerName() {
42 | return customerName;
43 | }
44 |
45 | public void setCustomerName(String customerName) {
46 | this.customerName = customerName;
47 | }
48 |
49 | public String getCustomerGrade() {
50 | return customerGrade;
51 | }
52 |
53 | public void setCustomerGrade(String customerGrade) {
54 | this.customerGrade = customerGrade;
55 | }
56 |
57 | public String showCustomerInfo() {
58 | return customerName + "님의 등급은 " + customerGrade +
59 | "이며, 보너스 포인트는 " + bonusPoint + "입니다";
60 |
61 | }
62 |
63 |
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/Chapter3/src/ch03/CustomerTest.java:
--------------------------------------------------------------------------------
1 | package ch03;
2 |
3 | public class CustomerTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | Customer customerLee = new Customer(10010, "이순신");
8 | customerLee.bonusPoint = 1000;
9 | System.out.println(customerLee.showCustomerInfo());
10 |
11 | VIPCustomer customerKim = new VIPCustomer(10020, "김유신");
12 | customerKim.bonusPoint = 10000;
13 | System.out.println(customerKim.showCustomerInfo());
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Chapter3/src/ch03/VIPCustomer.java:
--------------------------------------------------------------------------------
1 | package ch03;
2 |
3 | public class VIPCustomer extends Customer{
4 |
5 | private int agentID;
6 | double salesRatio;
7 |
8 | /*public VIPCustomer() {
9 | customerGrade = "VIP"; //오류 발생
10 | bonusRatio = 0.05;
11 | salesRatio = 0.1;
12 |
13 | System.out.println("VIPCustomer() 생성자 호출");
14 | }
15 | */
16 |
17 | public VIPCustomer(int customerID, String customerName) {
18 | super(customerID, customerName);
19 |
20 | customerGrade = "VIP";
21 | bonusRatio = 0.05;
22 | salesRatio = 0.1;
23 |
24 | System.out.println("VIPCustomer(int, String) 생성자 호출");
25 | }
26 | public int getAgentID() {
27 | return agentID;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Chapter3/src/ch04/Customer.java:
--------------------------------------------------------------------------------
1 | package ch04;
2 |
3 | public class Customer {
4 |
5 | protected int customerID;
6 | protected String customerName;
7 | protected String customerGrade;
8 | int bonusPoint;
9 | double bonusRatio;
10 |
11 | /*public Customer() {
12 | customerGrade = "SILVER";
13 | bonusRatio = 0.01;
14 |
15 | System.out.println("Customer() 생성자 호출");
16 | }*/
17 |
18 | public Customer(int customerID, String customerName) {
19 | this.customerID = customerID;
20 | this.customerName = customerName;
21 |
22 | customerGrade = "SILVER";
23 | bonusRatio = 0.01;
24 | //System.out.println("Customer(int, String) 생성자 호출");
25 | }
26 |
27 | public int calcPrice(int price) {
28 | bonusPoint += price * bonusRatio;
29 | return price;
30 | }
31 |
32 |
33 | public int getCustomerID() {
34 | return customerID;
35 | }
36 |
37 | public void setCustomerID(int customerID) {
38 | this.customerID = customerID;
39 | }
40 |
41 | public String getCustomerName() {
42 | return customerName;
43 | }
44 |
45 | public void setCustomerName(String customerName) {
46 | this.customerName = customerName;
47 | }
48 |
49 | public String getCustomerGrade() {
50 | return customerGrade;
51 | }
52 |
53 | public void setCustomerGrade(String customerGrade) {
54 | this.customerGrade = customerGrade;
55 | }
56 |
57 | public String showCustomerInfo() {
58 | return customerName + "님의 등급은 " + customerGrade +
59 | "이며, 보너스 포인트는 " + bonusPoint + "입니다";
60 |
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/Chapter3/src/ch04/CustomerTest.java:
--------------------------------------------------------------------------------
1 | package ch04;
2 |
3 | public class CustomerTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | Customer customerLee = new Customer(10010, "이순신");
8 | customerLee.bonusPoint = 1000;
9 | System.out.println(customerLee.showCustomerInfo());
10 |
11 | VIPCustomer customerKim = new VIPCustomer(10020, "김유신");
12 | customerKim.bonusPoint = 10000;
13 | System.out.println(customerKim.showCustomerInfo());
14 |
15 | int priceLee = customerLee.calcPrice(10000);
16 | int priceKim = customerKim.calcPrice(10000);
17 |
18 | System.out.println(customerLee.showCustomerInfo() + " 지불금액은 " + priceLee + "원 입니다.");
19 | System.out.println(customerKim.showCustomerInfo() + " 지불금액은 " + priceKim + "원 입니다.");
20 |
21 | Customer customerNo = new VIPCustomer(10030, "나몰라");
22 | customerNo.bonusPoint = 10000;
23 | int priceNo = customerNo.calcPrice(10000);
24 | System.out.println(customerNo.showCustomerInfo() + " 지불금액은 " + priceNo + "원 입니다.");
25 |
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Chapter3/src/ch04/VIPCustomer.java:
--------------------------------------------------------------------------------
1 | package ch04;
2 |
3 | public class VIPCustomer extends Customer{
4 |
5 | private int agentID;
6 | double salesRatio;
7 |
8 | /*public VIPCustomer() {
9 | customerGrade = "VIP"; //오류 발생
10 | bonusRatio = 0.05;
11 | salesRatio = 0.1;
12 |
13 | System.out.println("VIPCustomer() 생성자 호출");
14 | }
15 | */
16 |
17 | public VIPCustomer(int customerID, String customerName) {
18 | super(customerID, customerName);
19 |
20 | customerGrade = "VIP";
21 | bonusRatio = 0.05;
22 | salesRatio = 0.1;
23 |
24 | //System.out.println("VIPCustomer(int, String) 생성자 호출");
25 | }
26 |
27 |
28 |
29 | @Override
30 | public int calcPrice(int price) {
31 | bonusPoint += price * bonusRatio;
32 | return price - (int)(price * salesRatio);
33 | }
34 |
35 |
36 |
37 | public int getAgentID() {
38 | return agentID;
39 | }
40 |
41 | @Override
42 | public String showCustomerInfo() {
43 | return customerName + "님의 등급은 " + customerGrade +
44 | "이며, 보너스 포인트는 " + bonusPoint + "입니다";
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Chapter3/src/ch05/TestMethod.java:
--------------------------------------------------------------------------------
1 | package ch05;
2 |
3 | public class TestMethod {
4 |
5 | int num;
6 |
7 | void aaa() {
8 | System.out.println("aaa() 호출");
9 | }
10 |
11 | public static void main(String[] args) {
12 |
13 | TestMethod a1 = new TestMethod();
14 | a1.aaa();
15 |
16 | TestMethod a2 = new TestMethod();
17 | a2.aaa();
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter3/src/ch06/Customer.java:
--------------------------------------------------------------------------------
1 | package ch06;
2 |
3 | public class Customer {
4 |
5 | protected int customerID;
6 | protected String customerName;
7 | protected String customerGrade;
8 | int bonusPoint;
9 | double bonusRatio;
10 |
11 | public Customer()
12 | {
13 | initCustomer();
14 | }
15 |
16 | public Customer(int customerID, String customerName){
17 | this.customerID = customerID;
18 | this.customerName = customerName;
19 |
20 | initCustomer();
21 | }
22 |
23 | private void initCustomer()
24 | {
25 | customerGrade = "SILVER";
26 | bonusRatio = 0.01;
27 | }
28 |
29 | public int calcPrice(int price){
30 | bonusPoint += price * bonusRatio;
31 | return price;
32 | }
33 |
34 | public String showCustomerInfo(){
35 | return customerName + " 님의 등급은 " + customerGrade + "이며, 보너스 포인트는 " + bonusPoint + "입니다.";
36 | }
37 |
38 | public int getCustomerID() {
39 | return customerID;
40 | }
41 |
42 | public void setCustomerID(int customerID) {
43 | this.customerID = customerID;
44 | }
45 |
46 | public String getCustomerName() {
47 | return customerName;
48 | }
49 |
50 | public void setCustomerName(String customerName) {
51 | this.customerName = customerName;
52 | }
53 |
54 | public String getCustomerGrade() {
55 | return customerGrade;
56 | }
57 |
58 | public void setCustomerGrade(String customerGrade) {
59 | this.customerGrade = customerGrade;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Chapter3/src/ch06/CustomerTest.java:
--------------------------------------------------------------------------------
1 | package ch06;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class CustomerTest {
6 |
7 | public static void main(String[] args) {
8 |
9 | ArrayList customerList = new ArrayList();
10 |
11 | Customer customerLee = new Customer(10010, "이순신");
12 | Customer customerShin = new Customer(10020, "신사임당");
13 | Customer customerHong = new GoldCustomer(10030, "홍길동");
14 | Customer customerYul = new GoldCustomer(10040, "이율곡");
15 | Customer customerKim = new VIPCustomer(10050, "김유신", 12345);
16 |
17 | customerList.add(customerLee);
18 | customerList.add(customerShin);
19 | customerList.add(customerHong);
20 | customerList.add(customerYul);
21 | customerList.add(customerKim);
22 |
23 | System.out.println("====== 고객 정보 출력 =======");
24 |
25 | for( Customer customer : customerList){
26 | System.out.println(customer.showCustomerInfo());
27 | }
28 |
29 | System.out.println("====== 할인율과 보너스 포인트 계산 =======");
30 |
31 | int price = 10000;
32 | for( Customer customer : customerList){
33 | int cost = customer.calcPrice(price);
34 | System.out.println(customer.getCustomerName() +" 님이 " + + cost + "원 지불하셨습니다.");
35 | System.out.println(customer.getCustomerName() +" 님의 현재 보너스 포인트는 " + customer.bonusPoint + "점입니다.");
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Chapter3/src/ch06/GoldCustomer.java:
--------------------------------------------------------------------------------
1 | package ch06;
2 |
3 | public class GoldCustomer extends Customer{
4 |
5 | double saleRatio;
6 |
7 | public GoldCustomer(int customerID, String customerName){
8 | super(customerID, customerName);
9 |
10 | customerGrade = "GOLD";
11 | bonusRatio = 0.02;
12 | saleRatio = 0.1;
13 |
14 | }
15 |
16 | public int calcPrice(int price){
17 | bonusPoint += price * bonusRatio;
18 | return price - (int)(price * saleRatio);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter3/src/ch06/VIPCustomer.java:
--------------------------------------------------------------------------------
1 | package ch06;
2 |
3 | public class VIPCustomer extends Customer{
4 |
5 | private int agentID;
6 | double saleRatio;
7 |
8 | public VIPCustomer(int customerID, String customerName, int agentID){
9 | super(customerID, customerName);
10 |
11 | customerGrade = "VIP";
12 | bonusRatio = 0.05;
13 | saleRatio = 0.1;
14 | this.agentID = agentID;
15 | }
16 |
17 | public int calcPrice(int price){
18 | bonusPoint += price * bonusRatio;
19 | return price - (int)(price * saleRatio);
20 | }
21 |
22 | public String showCustomerInfo(){
23 | return super.showCustomerInfo() + " 담당 상담원 번호는 " + agentID + "입니다";
24 | }
25 |
26 | public int getAgentID(){
27 | return agentID;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Chapter3/src/ch09/Computer.java:
--------------------------------------------------------------------------------
1 | package ch09;
2 |
3 | public abstract class Computer {
4 |
5 | abstract void display();
6 | abstract void typing();
7 |
8 | public void turnOn() {
9 | System.out.println("전원을 켭니다.");
10 | }
11 |
12 | public void turnOff() {
13 | System.out.println("전원을 끕니다.");
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Chapter3/src/ch09/ComputerTest.java:
--------------------------------------------------------------------------------
1 | package ch09;
2 |
3 | public class ComputerTest {
4 |
5 | public static void main(String[] args) {
6 | Computer computer = new DeskTop();
7 | computer.display();
8 | computer.turnOff();
9 |
10 | NoteBook myNote = new MyNoteBook();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter3/src/ch09/DeskTop.java:
--------------------------------------------------------------------------------
1 | package ch09;
2 |
3 | public class DeskTop extends Computer{
4 |
5 | @Override
6 | void display() {
7 | System.out.println("DeskTop display");
8 | }
9 |
10 | @Override
11 | void typing() {
12 | System.out.println("DeskTop typing");
13 | }
14 |
15 | @Override
16 | public void turnOff() {
17 | System.out.println("Desktop turnoff");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Chapter3/src/ch09/MyNoteBook.java:
--------------------------------------------------------------------------------
1 | package ch09;
2 |
3 | public class MyNoteBook extends NoteBook{
4 |
5 | @Override
6 | void display() {
7 | System.out.println("MyNoteBook display");
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter3/src/ch09/NoteBook.java:
--------------------------------------------------------------------------------
1 | package ch09;
2 |
3 | public abstract class NoteBook extends Computer{
4 | @Override
5 | public void typing() {
6 | System.out.println("NoteBook typing");
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/Chapter3/src/ch10/AICar.java:
--------------------------------------------------------------------------------
1 | package ch10;
2 |
3 | public class AICar extends Car{
4 |
5 | @Override
6 | public void drive() {
7 | System.out.println("자율 주행합니다.");
8 | System.out.println("자동차가 스스로 방향을 바꿉니다.");
9 | }
10 |
11 | @Override
12 | public void stop() {
13 | System.out.println("스스로 멈춥니다.");
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Chapter3/src/ch10/Car.java:
--------------------------------------------------------------------------------
1 | package ch10;
2 |
3 | public abstract class Car {
4 |
5 | public abstract void drive();
6 | public abstract void stop();
7 |
8 | public void startCar() {
9 | System.out.println("시동을 켭니다.");
10 | }
11 |
12 | public void turnOff() {
13 | System.out.println("시동을 끕니다.");
14 | }
15 |
16 | final public void run() {
17 | startCar();
18 | drive();
19 | stop();
20 | turnOff();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Chapter3/src/ch10/CarTest.java:
--------------------------------------------------------------------------------
1 | package ch10;
2 |
3 | public class CarTest {
4 |
5 | public static void main(String[] args) {
6 | Car aiCar = new AICar();
7 | aiCar.run();
8 | System.out.println("=================");
9 | Car manualCar = new ManualCar();
10 | manualCar.run();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter3/src/ch10/Define.java:
--------------------------------------------------------------------------------
1 | package ch10;
2 |
3 | public class Define {
4 |
5 | public static final int MIN = 1;
6 | public static final int MAX = 999999;
7 | public static final double PI = 3.14;
8 | public static final String GREETING = "Good Morning!";
9 | public static final int MATH_CODE = 1001;
10 | public static final int CHEMISTRY_CODE = 1002;
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter3/src/ch10/ManualCar.java:
--------------------------------------------------------------------------------
1 | package ch10;
2 |
3 | public class ManualCar extends Car{
4 |
5 | @Override
6 | public void drive() {
7 | System.out.println("사람이 운전합니다.");
8 | System.out.println("사람이 핸들을 조작합니다.");
9 | }
10 |
11 | @Override
12 | public void stop() {
13 | System.out.println("브레이크를 밟아서 정지합니다.");
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/Chapter3/src/ch10/UsingDefine.java:
--------------------------------------------------------------------------------
1 | package ch10;
2 |
3 | public class UsingDefine {
4 |
5 | public static void main(String[] args) {
6 |
7 | System.out.println(Define.GREETING);
8 | System.out.println(Define.MIN);
9 | System.out.println(Define.MAX);
10 | System.out.println(Define.MATH_CODE);
11 | System.out.println(Define.CHEMISTRY_CODE);
12 | System.out.println("원주률은" + Define.PI + "입니다.");
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/Chapter3/src/ch11/Calc.java:
--------------------------------------------------------------------------------
1 | package ch11;
2 |
3 | public interface Calc {
4 |
5 | double PI = 3.14;
6 | int ERROR = -99999999;
7 |
8 | int add(int num1, int num2);
9 | int substract(int num1, int num2);
10 | int times(int num1, int num2);
11 | int divide(int num1, int num2);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/Chapter3/src/ch11/Calculator.java:
--------------------------------------------------------------------------------
1 | package ch11;
2 |
3 | public abstract class Calculator implements Calc{
4 |
5 | @Override
6 | public int add(int num1, int num2) {
7 | return num1 + num2;
8 | }
9 |
10 | @Override
11 | public int substract(int num1, int num2) {
12 | return num1 - num2;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter3/src/ch11/CalculatorTest.java:
--------------------------------------------------------------------------------
1 | package ch11;
2 |
3 | public class CalculatorTest {
4 |
5 | public static void main(String[] args) {
6 | Calc calc = new CompleteCalc();
7 | int num1 = 10;
8 | int num2 = 2;
9 |
10 | System.out.println(num1 + "+" + num2 + "=" + calc.add(num1, num2));
11 | System.out.println(num1 + "-" + num2 + "=" +calc.substract(num1, num2));
12 | System.out.println(num1 + "*" + num2 + "=" +calc.times(num1, num2));
13 | System.out.println(num1 + "/" + num2 + "=" +calc.divide(num1, num2));
14 | }
15 | }
--------------------------------------------------------------------------------
/Chapter3/src/ch11/CompleteCalc.java:
--------------------------------------------------------------------------------
1 | package ch11;
2 |
3 | public class CompleteCalc extends Calculator{
4 |
5 | @Override
6 | public int times(int num1, int num2) {
7 | return num1 * num2;
8 | }
9 |
10 | @Override
11 | public int divide(int num1, int num2) {
12 | if( num2 == 0 )
13 | return ERROR;
14 | else
15 | return num1 / num2;
16 | }
17 |
18 | public void showInfo() {
19 | System.out.println("모두 구현하였습니다.");
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter3/src/ch13/domain/userinfo/UserInfo.java:
--------------------------------------------------------------------------------
1 | package ch13.domain.userinfo;
2 |
3 | public class UserInfo {
4 |
5 | private String userId;
6 | private String passwd;
7 | private String userName;
8 |
9 | public String getUserId() {
10 | return userId;
11 | }
12 |
13 | public void setUserId(String userId) {
14 | this.userId = userId;
15 | }
16 |
17 | public String getPasswd() {
18 | return passwd;
19 | }
20 |
21 | public void setPasswd(String passwd) {
22 | this.passwd = passwd;
23 | }
24 |
25 | public String getUserName() {
26 | return userName;
27 | }
28 |
29 | public void setUserName(String userName) {
30 | this.userName = userName;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Chapter3/src/ch13/domain/userinfo/dao/UserInfoDao.java:
--------------------------------------------------------------------------------
1 | package ch13.domain.userinfo.dao;
2 |
3 | import ch13.domain.userinfo.UserInfo;
4 |
5 | public interface UserInfoDao {
6 |
7 | void insertUserInfo(UserInfo userInfo);
8 | void updateUserInfo(UserInfo userInfo);
9 | void deleteUserInf(UserInfo userInfo);
10 | }
11 |
--------------------------------------------------------------------------------
/Chapter3/src/ch13/domain/userinfo/dao/mysql/UserInfoMySqlDao.java:
--------------------------------------------------------------------------------
1 | package ch13.domain.userinfo.dao.mysql;
2 |
3 | import ch13.domain.userinfo.UserInfo;
4 | import ch13.domain.userinfo.dao.UserInfoDao;
5 |
6 | public class UserInfoMySqlDao implements UserInfoDao{
7 |
8 | @Override
9 | public void insertUserInfo(UserInfo userInfo) {
10 | System.out.println("insert into MYSQL DB userId =" + userInfo.getUserId() );
11 | }
12 |
13 | @Override
14 | public void updateUserInfo(UserInfo userInfo) {
15 | System.out.println("update into MYSQL DB userId = " + userInfo.getUserId());
16 | }
17 |
18 | @Override
19 | public void deleteUserInf(UserInfo userInfo) {
20 | System.out.println("delete from MYSQL DB userId = " + userInfo.getUserId());
21 |
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/Chapter3/src/ch13/domain/userinfo/dao/oracle/UserInfoOracleDao.java:
--------------------------------------------------------------------------------
1 | package ch13.domain.userinfo.dao.oracle;
2 |
3 | import ch13.domain.userinfo.UserInfo;
4 | import ch13.domain.userinfo.dao.UserInfoDao;
5 |
6 | public class UserInfoOracleDao implements UserInfoDao{
7 |
8 | public void insertUserInfo(UserInfo userInfo){
9 | System.out.println("insert into ORACLE DB userId =" + userInfo.getUserId() );
10 | }
11 |
12 | public void updateUserInfo(UserInfo userInfo){
13 | System.out.println("update into ORACLE DB userId = " + userInfo.getUserId());
14 | }
15 |
16 | public void deleteUserInf(UserInfo userInfo){
17 | System.out.println("delete from ORACLE DB userId = " + userInfo.getUserId());
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Chapter3/src/ch13/userinfo/web/UserInfoClient.java:
--------------------------------------------------------------------------------
1 | package ch13.userinfo.web;
2 |
3 | import java.io.FileInputStream;
4 | import java.io.IOException;
5 | import java.util.Properties;
6 |
7 | import ch13.domain.userinfo.UserInfo;
8 | import ch13.domain.userinfo.dao.UserInfoDao;
9 | import ch13.domain.userinfo.dao.mysql.UserInfoMySqlDao;
10 | import ch13.domain.userinfo.dao.oracle.UserInfoOracleDao;
11 |
12 | public class UserInfoClient {
13 |
14 | public static void main(String[] args) throws IOException {
15 |
16 | FileInputStream fis = new FileInputStream("db.properties");
17 |
18 | Properties prop = new Properties();
19 | prop.load(fis);
20 |
21 | String dbType = prop.getProperty("DBTYPE");
22 |
23 | UserInfo userInfo = new UserInfo();
24 | userInfo.setUserId("12345");
25 | userInfo.setPasswd("!@#$%");
26 | userInfo.setUserName("이순신");
27 |
28 |
29 | UserInfoDao userInfoDao = null;
30 |
31 | if(dbType.equals("ORACLE")){
32 | userInfoDao = new UserInfoOracleDao();
33 | }
34 | else if(dbType.endsWith("MYSQL")){
35 | userInfoDao = new UserInfoMySqlDao();
36 | }
37 | else{
38 | System.out.println("db support error");
39 | return;
40 | }
41 |
42 | userInfoDao.insertUserInfo(userInfo);
43 | userInfoDao.updateUserInfo(userInfo);
44 | userInfoDao.deleteUserInf(userInfo);
45 | }
46 | }
--------------------------------------------------------------------------------
/Chapter3/src/ch14/Calc.java:
--------------------------------------------------------------------------------
1 | package ch14;
2 |
3 | public interface Calc {
4 |
5 | double PI = 3.14;
6 | int ERROR = -99999999;
7 |
8 | int add(int num1, int num2);
9 | int substract(int num1, int num2);
10 | int times(int num1, int num2);
11 | int divide(int num1, int num2);
12 |
13 | default void description() {
14 | System.out.println("정수 계산기를 구현합니다.");
15 | myMethod();
16 | }
17 |
18 | static int total(int[] arr) {
19 | int total = 0;
20 |
21 | for(int i: arr) {
22 | total += i;
23 | }
24 | mystaticMethod();
25 | return total;
26 | }
27 |
28 | private void myMethod() {
29 | System.out.println("private method");
30 | }
31 |
32 | private static void mystaticMethod() {
33 | System.out.println("private static method");
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Chapter3/src/ch14/Calculator.java:
--------------------------------------------------------------------------------
1 | package ch14;
2 |
3 | public abstract class Calculator implements Calc{
4 |
5 | @Override
6 | public int add(int num1, int num2) {
7 | return num1 + num2;
8 | }
9 |
10 | @Override
11 | public int substract(int num1, int num2) {
12 | return num1 - num2;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter3/src/ch14/CalculatorTest.java:
--------------------------------------------------------------------------------
1 | package ch14;
2 |
3 | public class CalculatorTest {
4 |
5 | public static void main(String[] args) {
6 | Calc calc = new CompleteCalc();
7 | int num1 = 10;
8 | int num2 = 2;
9 |
10 | System.out.println(num1 + "+" + num2 + "=" + calc.add(num1, num2));
11 | System.out.println(num1 + "-" + num2 + "=" +calc.substract(num1, num2));
12 | System.out.println(num1 + "*" + num2 + "=" +calc.times(num1, num2));
13 | System.out.println(num1 + "/" + num2 + "=" +calc.divide(num1, num2));
14 |
15 | calc.description();
16 |
17 | int[] arr = {1,2,3,4,5};
18 | int sum = Calc.total(arr);
19 | System.out.println(sum);
20 | }
21 | }
--------------------------------------------------------------------------------
/Chapter3/src/ch14/CompleteCalc.java:
--------------------------------------------------------------------------------
1 | package ch14;
2 |
3 | public class CompleteCalc extends Calculator{
4 |
5 | @Override
6 | public int times(int num1, int num2) {
7 | return num1 * num2;
8 | }
9 |
10 | @Override
11 | public int divide(int num1, int num2) {
12 | if( num2 == 0 )
13 | return ERROR;
14 | else
15 | return num1 / num2;
16 | }
17 |
18 | public void showInfo() {
19 | System.out.println("모두 구현하였습니다.");
20 | }
21 |
22 | @Override
23 | public void description() {
24 | System.out.println("CompleteCalc에서 재정의한 default 메서드");
25 | //super.description();
26 | }
27 |
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/Chapter3/src/ch15/BookShelf.java:
--------------------------------------------------------------------------------
1 | package ch15;
2 |
3 | public class BookShelf extends Shelf implements Queue{
4 |
5 | @Override
6 | public void enQueue(String title) {
7 | shelf.add(title);
8 | }
9 |
10 | @Override
11 | public String deQueue() {
12 | return shelf.remove(0);
13 | }
14 |
15 | @Override
16 | public int getSize() {
17 | return getCount();
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter3/src/ch15/BookShelfTest.java:
--------------------------------------------------------------------------------
1 | package ch15;
2 |
3 | public class BookShelfTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | Queue bookQueue = new BookShelf();
8 | bookQueue.enQueue("태백산맥1");
9 | bookQueue.enQueue("태백산맥2");
10 | bookQueue.enQueue("태백산맥3");
11 |
12 | System.out.println(bookQueue.deQueue());
13 | System.out.println(bookQueue.deQueue());
14 | System.out.println(bookQueue.deQueue());
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/Chapter3/src/ch15/Buy.java:
--------------------------------------------------------------------------------
1 | package ch15;
2 |
3 | public interface Buy {
4 |
5 | void buy();
6 |
7 | default void order() {
8 | System.out.println("구매 주문");
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Chapter3/src/ch15/Customer.java:
--------------------------------------------------------------------------------
1 | package ch15;
2 |
3 | public class Customer implements Buy, Sell{
4 |
5 | @Override
6 | public void sell() {
7 | System.out.println("customer sell");
8 | }
9 |
10 | @Override
11 | public void buy() {
12 | System.out.println("customer buy");
13 | }
14 |
15 | @Override
16 | public void order() {
17 | System.out.println("customer order");
18 | }
19 |
20 | public void sayHello() {
21 | System.out.println("Hello");
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/Chapter3/src/ch15/CustomerTest.java:
--------------------------------------------------------------------------------
1 | package ch15;
2 |
3 | public class CustomerTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | Customer customer = new Customer();
8 | customer.buy();
9 | customer.sell();
10 | customer.sayHello();
11 |
12 | Buy buyer = customer;
13 | buyer.buy();
14 |
15 | Sell seller = customer;
16 | seller.sell();
17 |
18 | buyer.order();
19 | seller.order();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter3/src/ch15/MyClass.java:
--------------------------------------------------------------------------------
1 | package ch15;
2 |
3 | public class MyClass implements MyInterface{
4 |
5 | @Override
6 | public void x() {
7 | System.out.println("x()");
8 | }
9 |
10 | @Override
11 | public void y() {
12 | System.out.println("y()");
13 | }
14 |
15 | @Override
16 | public void myMethod() {
17 | System.out.println("myMethod()");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Chapter3/src/ch15/MyClassTest.java:
--------------------------------------------------------------------------------
1 | package ch15;
2 |
3 | public class MyClassTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | MyClass mClass = new MyClass();
8 |
9 | X xClass = mClass;
10 | xClass.x();
11 |
12 |
13 | Y yClass = mClass;
14 | yClass.y();
15 |
16 | MyClass iClass = mClass;
17 | iClass.x();
18 | iClass.y();
19 | iClass.myMethod();
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/Chapter3/src/ch15/MyInterface.java:
--------------------------------------------------------------------------------
1 | package ch15;
2 |
3 | public interface MyInterface extends X, Y{
4 |
5 | void myMethod();
6 | }
7 |
--------------------------------------------------------------------------------
/Chapter3/src/ch15/Queue.java:
--------------------------------------------------------------------------------
1 | package ch15;
2 |
3 | public interface Queue {
4 |
5 | void enQueue(String title);
6 | String deQueue();
7 |
8 | int getSize();
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter3/src/ch15/Sell.java:
--------------------------------------------------------------------------------
1 | package ch15;
2 |
3 | public interface Sell {
4 |
5 | void sell();
6 |
7 | default void order() {
8 | System.out.println("판매 주문");
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Chapter3/src/ch15/Shelf.java:
--------------------------------------------------------------------------------
1 | package ch15;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class Shelf {
6 |
7 | protected ArrayList shelf;
8 |
9 | public Shelf() {
10 | shelf = new ArrayList();
11 | }
12 |
13 | public ArrayList getShelf(){
14 | return shelf;
15 | }
16 |
17 | public int getCount() {
18 | return shelf.size();
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter3/src/ch15/X.java:
--------------------------------------------------------------------------------
1 | package ch15;
2 |
3 | public interface X {
4 |
5 | void x();
6 | }
7 |
--------------------------------------------------------------------------------
/Chapter3/src/ch15/Y.java:
--------------------------------------------------------------------------------
1 | package ch15;
2 |
3 | public interface Y {
4 |
5 | void y();
6 | }
7 |
--------------------------------------------------------------------------------
/Chapter3/src/ch16/gamelevel/AdvancedLevel.java:
--------------------------------------------------------------------------------
1 | package ch16.gamelevel;
2 |
3 | public class AdvancedLevel extends PlayerLevel{
4 |
5 | @Override
6 | public void run() {
7 | System.out.println("빨리 달립니다.");
8 | }
9 |
10 | @Override
11 | public void jump() {
12 | System.out.println("높이 jump 합니다.");
13 | }
14 |
15 | @Override
16 | public void turn() {
17 | System.out.println("turn 못하지롱");
18 | }
19 |
20 | @Override
21 | public void showLevelMessage() {
22 | System.out.println("****** 중급자 레벨입니다. ******");
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Chapter3/src/ch16/gamelevel/BeginnerLevel.java:
--------------------------------------------------------------------------------
1 | package ch16.gamelevel;
2 |
3 | public class BeginnerLevel extends PlayerLevel{
4 |
5 | @Override
6 | public void run() {
7 | System.out.println("천천히 달립니다.");
8 | }
9 |
10 | @Override
11 | public void jump() {
12 | System.out.println("jump 못하지롱");
13 | }
14 |
15 | @Override
16 | public void turn() {
17 | System.out.println("turn 못하지롱");
18 | }
19 |
20 | @Override
21 | public void showLevelMessage() {
22 | System.out.println("****** 초급자 레벨입니다. ******");
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/Chapter3/src/ch16/gamelevel/MainBoardPlay.java:
--------------------------------------------------------------------------------
1 | package ch16.gamelevel;
2 |
3 | public class MainBoardPlay {
4 |
5 | public static void main(String[] args) {
6 |
7 | Player player = new Player();
8 | player.play(1);
9 |
10 | AdvancedLevel aLevel = new AdvancedLevel();
11 | player.upgradeLevel(aLevel);
12 | player.play(2);
13 |
14 | SuperLevel sLevel = new SuperLevel();
15 | player.upgradeLevel(sLevel);
16 | player.play(3);
17 |
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter3/src/ch16/gamelevel/Player.java:
--------------------------------------------------------------------------------
1 | package ch16.gamelevel;
2 |
3 | public class Player {
4 |
5 | private PlayerLevel level;
6 |
7 | public Player(){
8 | level = new BeginnerLevel();
9 | level.showLevelMessage();
10 | }
11 |
12 |
13 | public PlayerLevel getLevel() {
14 | return level;
15 | }
16 |
17 | public void upgradeLevel( PlayerLevel level ) {
18 | this.level = level;
19 | level.showLevelMessage();
20 | }
21 |
22 | public void play(int count) {
23 | level.go(count);
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/Chapter3/src/ch16/gamelevel/PlayerLevel.java:
--------------------------------------------------------------------------------
1 | package ch16.gamelevel;
2 |
3 | public abstract class PlayerLevel {
4 |
5 | public abstract void run();
6 | public abstract void jump();
7 | public abstract void turn();
8 | public abstract void showLevelMessage();
9 |
10 |
11 | final public void go(int count) {
12 | run();
13 | for(int i = 0; i
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Chapter4/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 |
--------------------------------------------------------------------------------
/Chapter4/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Chapter4
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Chapter4/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6 | org.eclipse.jdt.core.compiler.compliance=14
7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=enabled
12 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
13 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
14 | org.eclipse.jdt.core.compiler.release=enabled
15 | org.eclipse.jdt.core.compiler.source=14
16 |
--------------------------------------------------------------------------------
/Chapter4/src/ch01/BookTest.java:
--------------------------------------------------------------------------------
1 | package ch01;
2 |
3 | class Book{
4 |
5 | private String title;
6 | private String author;
7 |
8 | public Book(String title, String author) {
9 | this.title = title;
10 | this.author = author;
11 | }
12 |
13 | public String toString() {
14 | return title + "," + author;
15 | }
16 | }
17 |
18 | public class BookTest {
19 |
20 | public static void main(String[] args) {
21 |
22 | Book book = new Book("데미안", "헤르만 헤세");
23 |
24 | System.out.println(book);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Chapter4/src/ch02/EqualTest.java:
--------------------------------------------------------------------------------
1 | package ch02;
2 |
3 | public class EqualTest {
4 |
5 | public static void main(String[] args) throws CloneNotSupportedException {
6 | Student Lee = new Student(100, "Lee");
7 | Student Lee2 = Lee;
8 | Student Shun = new Student(100, "Lee");
9 |
10 | System.out.println(Lee == Shun);
11 | System.out.println(Lee.equals(Shun));
12 |
13 | System.out.println(Lee.hashCode());
14 | System.out.println(Shun.hashCode());
15 |
16 |
17 | Integer i1 = new Integer(100);
18 | Integer i2 = new Integer(100);
19 |
20 | System.out.println(i1.equals(i2));
21 | System.out.println(i1.hashCode());
22 | System.out.println(i2.hashCode());
23 |
24 | System.out.println(System.identityHashCode(i1));
25 | System.out.println(System.identityHashCode(i2));
26 |
27 | Student Lee3 = (Student)Lee.clone();
28 | System.out.println(System.identityHashCode(Lee));
29 | System.out.println(System.identityHashCode(Lee3));
30 |
31 |
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Chapter4/src/ch02/Student.java:
--------------------------------------------------------------------------------
1 | package ch02;
2 |
3 | public class Student implements Cloneable{
4 |
5 | private int studentId;
6 | private String studentName;
7 |
8 | public Student(int studentId, String studentName)
9 | {
10 | this.studentId = studentId;
11 | this.studentName = studentName;
12 | }
13 |
14 | public boolean equals(Object obj) {
15 | if( obj instanceof Student) {
16 | Student std = (Student)obj;
17 | if(this.studentId == std.studentId )
18 | return true;
19 | else return false;
20 | }
21 | return false;
22 |
23 | }
24 |
25 | @Override
26 | public int hashCode() {
27 | return studentId;
28 | }
29 |
30 | @Override
31 | protected Object clone() throws CloneNotSupportedException {
32 | // TODO Auto-generated method stub
33 | return super.clone();
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/Chapter4/src/ch03/StringBuilderTest.java:
--------------------------------------------------------------------------------
1 | package ch03;
2 |
3 | public class StringBuilderTest {
4 |
5 | public static void main(String[] args) {
6 | String java = new String("java");
7 | String android = new String("android");
8 |
9 | StringBuilder buffer = new StringBuilder(java);
10 | System.out.println(System.identityHashCode(buffer));
11 | buffer.append("android");
12 | System.out.println(System.identityHashCode(buffer));
13 |
14 | java = buffer.toString();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Chapter4/src/ch03/StringTest.java:
--------------------------------------------------------------------------------
1 | package ch03;
2 |
3 | public class StringTest {
4 |
5 | public static void main(String[] args) {
6 | String str1 = new String("abc");
7 | String str2 = new String("abc");
8 |
9 | System.out.println(str1 == str2);
10 |
11 | String str3 = "abc";
12 | String str4 = "abc";
13 |
14 | System.out.println(str3 == str4);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Chapter4/src/ch03/StringTest2.java:
--------------------------------------------------------------------------------
1 | package ch03;
2 |
3 | public class StringTest2 {
4 |
5 | public static void main(String[] args) {
6 | String java = new String("java");
7 | String android = new String("android");
8 | System.out.println(System.identityHashCode(java));
9 |
10 | java = java.concat(android);
11 |
12 | System.out.println(java);
13 | System.out.println(System.identityHashCode(java));
14 |
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Chapter4/src/ch03/StringTextBlock.java:
--------------------------------------------------------------------------------
1 | package ch03;
2 |
3 | public class StringTextBlock {
4 |
5 | public static void main(String[] args) {
6 |
7 | String strBlock = """
8 | This
9 | is
10 | text
11 | block
12 | test.""";
13 | System.out.println(strBlock);
14 |
15 | System.out.println(getBlockOfHtml());
16 |
17 | }
18 |
19 | public static String getBlockOfHtml() {
20 | return """
21 |
22 |
23 |
24 | example text
25 |
26 | """;
27 |
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/Chapter4/src/ch04/ClassTest.java:
--------------------------------------------------------------------------------
1 | package ch04;
2 |
3 | import java.lang.reflect.Constructor;
4 | import java.lang.reflect.InvocationTargetException;
5 |
6 | public class ClassTest {
7 |
8 | public static void main(String[] args) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
9 | ClassNotFoundException, NoSuchMethodException, SecurityException {
10 | Person person = new Person("James");
11 | System.out.println(person);
12 |
13 | Class c1 = Class.forName("ch04.Person");
14 | Person person1 = (Person)c1.newInstance();
15 | System.out.println(person1);
16 |
17 | Class[] parameterTypes = {String.class};
18 | Constructor cons = c1.getConstructor(parameterTypes);
19 |
20 | Object[] initargs = {"김유신"};
21 | Person personLee = (Person)cons.newInstance(initargs);
22 | System.out.println(personLee);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Chapter4/src/ch04/Person.java:
--------------------------------------------------------------------------------
1 | package ch04;
2 |
3 | public class Person {
4 | private String name;
5 | private int age;
6 |
7 | public Person() {};
8 |
9 | public Person(String name) {
10 | this.name = name;
11 | }
12 |
13 | public Person(String name, int age) {
14 | this.name = name;
15 | this.age = age;
16 | }
17 |
18 | public String getName() {
19 | return name;
20 | }
21 |
22 | public void setName(String name) {
23 | this.name = name;
24 | }
25 |
26 | public int getAge() {
27 | return age;
28 | }
29 |
30 | public void setAge(int age) {
31 | this.age = age;
32 | }
33 |
34 | public String toString() {
35 | return name;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Chapter4/src/ch04/StringTest.java:
--------------------------------------------------------------------------------
1 | package ch04;
2 |
3 | import java.lang.reflect.Constructor;
4 | import java.lang.reflect.Method;
5 |
6 | public class StringTest {
7 |
8 | public static void main(String[] args) throws ClassNotFoundException {
9 | Class c3 = Class.forName("java.lang.String");
10 |
11 | Constructor[] cons = c3.getConstructors();
12 | for(Constructor con: cons) {
13 | System.out.println(con);
14 | }
15 |
16 | System.out.println();
17 |
18 | Method[] methods = c3.getMethods();
19 | for(Method method : methods) {
20 | System.out.println(method);
21 | }
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/Chapter5/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Chapter5/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 |
--------------------------------------------------------------------------------
/Chapter5/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Chapter5
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Chapter5/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=14
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
13 | org.eclipse.jdt.core.compiler.release=enabled
14 | org.eclipse.jdt.core.compiler.source=14
15 |
--------------------------------------------------------------------------------
/Chapter5/src/ch02/MyArrayTest.java:
--------------------------------------------------------------------------------
1 | package ch02;
2 |
3 | public class MyArrayTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | MyArray array = new MyArray();
8 | array.addElement(10);
9 | array.addElement(20);
10 | array.addElement(30);
11 | array.insertElement(1, 50);
12 | array.printAll();
13 |
14 | System.out.println("===============");
15 | array.removeElement(1);
16 | array.printAll();
17 | System.out.println("===============");
18 |
19 | array.addElement(70);
20 | array.printAll();
21 | System.out.println("===============");
22 | array.removeElement(1);
23 | array.printAll();
24 |
25 | System.out.println("===============");
26 | System.out.println(array.getElement(2));
27 |
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Chapter5/src/ch02/MyObjectArray.java:
--------------------------------------------------------------------------------
1 | package ch02;
2 |
3 | public class MyObjectArray {
4 |
5 | private int cout;
6 | private Object[] array;
7 | public int ARRAY_SIZE;
8 |
9 | public MyObjectArray()
10 | {
11 | ARRAY_SIZE = 10;
12 | array = new Object[ARRAY_SIZE];
13 | }
14 |
15 | public MyObjectArray(int size)
16 | {
17 | ARRAY_SIZE = size;
18 | array = new Object[ARRAY_SIZE];
19 | }
20 |
21 |
22 |
23 |
24 |
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/Chapter5/src/ch03/MyLinkedListTest.java:
--------------------------------------------------------------------------------
1 | package ch03;
2 |
3 | public class MyLinkedListTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | MyLinkedList list = new MyLinkedList();
8 | list.addElement("A");
9 | list.addElement("B");
10 | list.addElement("C");
11 | list.printAll();
12 | list.insertElement(3, "D");
13 | list.printAll();
14 | list.removeElement(0);
15 | list.printAll();
16 | list.removeElement(1);
17 | list.printAll();
18 |
19 | list.insertElement(0, "A-1");
20 | list.printAll();
21 | System.out.println(list.getSize());
22 |
23 | list.removeElement(0);
24 | list.printAll();
25 | System.out.println(list.getSize());
26 |
27 | list.removeAll();
28 | list.printAll();
29 | list.addElement("A");
30 | list.printAll();
31 | System.out.println(list.getElement(0));
32 | list.removeElement(0);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Chapter5/src/ch03/MyListNode.java:
--------------------------------------------------------------------------------
1 | package ch03;
2 |
3 | public class MyListNode {
4 |
5 | private String data; // 자료
6 | public MyListNode next; // 다음 노드를 가리키는 링크
7 |
8 | public MyListNode(){
9 | data = null;
10 | next = null;
11 | }
12 |
13 | public MyListNode(String data){
14 | this.data = data;
15 | this.next = null;
16 | }
17 |
18 | public MyListNode(String data, MyListNode link){
19 | this.data = data;
20 | this.next = link;
21 | }
22 |
23 | public String getData(){
24 | return data;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Chapter5/src/ch04/MyArrayStack.java:
--------------------------------------------------------------------------------
1 | package ch04;
2 |
3 | import ch02.MyArray;
4 |
5 | public class MyArrayStack {
6 |
7 | int top;
8 | MyArray arrayStack;
9 |
10 | public MyArrayStack()
11 | {
12 | top = 0;
13 | arrayStack = new MyArray();
14 | }
15 |
16 | public MyArrayStack(int size)
17 | {
18 | arrayStack = new MyArray(size);
19 | }
20 |
21 | public void push(int data)
22 | {
23 | if(isFull()){
24 | System.out.println("stack is full");
25 | return;
26 | }
27 |
28 | arrayStack.addElement(data);
29 | top++;
30 | }
31 |
32 | public int pop()
33 | {
34 | if (top == 0){
35 | System.out.println("stack is empty");
36 | return MyArray.ERROR_NUM;
37 | }
38 | return arrayStack.removeElement(--top);
39 |
40 | }
41 |
42 | public int peek()
43 | {
44 | if (top == 0){
45 | System.out.println("stack is empty");
46 | return MyArray.ERROR_NUM;
47 | }
48 | return arrayStack.getElement(top-1);
49 | }
50 |
51 | public int getSize()
52 | {
53 | return top;
54 | }
55 |
56 | public boolean isFull()
57 | {
58 | if(top == arrayStack.ARRAY_SIZE){
59 | return true;
60 | }
61 | else return false;
62 | }
63 |
64 | public boolean isEmpty()
65 | {
66 | if (top == 0){
67 | return true;
68 | }
69 | else return false;
70 | }
71 |
72 | public void printAll()
73 | {
74 | arrayStack.printAll();
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/Chapter5/src/ch04/MyArrayStackTest.java:
--------------------------------------------------------------------------------
1 | package ch04;
2 |
3 | public class MyArrayStackTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | MyArrayStack stack = new MyArrayStack(3);
8 |
9 | stack.push(10);
10 | stack.push(20);
11 | stack.push(30);
12 | stack.push(40);
13 |
14 | stack.printAll();
15 |
16 | System.out.println("top element is " + stack.pop());
17 | stack.printAll();
18 | System.out.println("stack size is " + stack.getSize());
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter5/src/ch05/MyListQueue.java:
--------------------------------------------------------------------------------
1 | package ch05;
2 |
3 | import ch03.MyLinkedList;
4 | import ch03.MyListNode;
5 |
6 | interface IQueue{
7 | public void enQueue(String data);
8 | public String deQueue();
9 | public void printAll();
10 | }
11 |
12 | public class MyListQueue extends MyLinkedList implements IQueue{
13 |
14 | MyListNode front;
15 | MyListNode rear;
16 |
17 |
18 | public MyListQueue()
19 | {
20 | front = null;
21 | rear = null;
22 | }
23 |
24 | public void enQueue(String data)
25 | {
26 | MyListNode newNode;
27 | if(isEmpty()) //처음 항목
28 | {
29 | newNode = addElement(data);
30 | front = newNode;
31 | rear = newNode;
32 | }
33 | else
34 | {
35 | newNode = addElement(data);
36 | rear = newNode;
37 | }
38 | System.out.println(newNode.getData() + " added");
39 | }
40 |
41 | public String deQueue()
42 | {
43 | if(isEmpty()){
44 | System.out.println("Queue is Empty");
45 | return null;
46 | }
47 | String data = front.getData();
48 | front = front.next;
49 | if( front == null ){ // 마지막 항목
50 | rear = null;
51 | }
52 | return data;
53 | }
54 |
55 | public void printAll()
56 | {
57 | if(isEmpty()){
58 | System.out.println("Queue is Empty");
59 | return;
60 | }
61 | MyListNode temp = front;
62 | while(temp!= null){
63 | System.out.print(temp.getData() + ",");
64 | temp = temp.next;
65 | }
66 | System.out.println();
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/Chapter5/src/ch05/MyListQueueTest.java:
--------------------------------------------------------------------------------
1 | package ch05;
2 |
3 | public class MyListQueueTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | MyListQueue listQueue = new MyListQueue();
8 | listQueue.enQueue("A");
9 | listQueue.enQueue("B");
10 | listQueue.enQueue("C");
11 | listQueue.enQueue("D");
12 | listQueue.enQueue("E");
13 |
14 | System.out.println(listQueue.deQueue());
15 | listQueue.printAll();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Chapter5/src/ch06/GeneriPrinterTest.java:
--------------------------------------------------------------------------------
1 | package ch06;
2 |
3 | public class GeneriPrinterTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | GenericPrinter powderPrinter = new GenericPrinter();
8 | powderPrinter.setMaterial(new Powder());
9 | System.out.println(powderPrinter);
10 |
11 | GenericPrinter plasticPrinter = new GenericPrinter();
12 | plasticPrinter.setMaterial(new Plastic());
13 | System.out.println(plasticPrinter);
14 |
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/Chapter5/src/ch06/GenericPrinter.java:
--------------------------------------------------------------------------------
1 | package ch06;
2 |
3 | public class GenericPrinter {
4 | private T material;
5 |
6 | public void setMaterial(T material) {
7 | this.material = material;
8 | }
9 |
10 | public T getMaterial() {
11 | return material;
12 | }
13 |
14 | public String toString(){
15 | return material.toString();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Chapter5/src/ch06/Plastic.java:
--------------------------------------------------------------------------------
1 | package ch06;
2 |
3 | public class Plastic {
4 |
5 | public String toString() {
6 | return "재료는 Plastic 입니다";
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/Chapter5/src/ch06/Powder.java:
--------------------------------------------------------------------------------
1 | package ch06;
2 |
3 | public class Powder {
4 |
5 | public String toString() {
6 | return "재료는 Powder 입니다";
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/Chapter5/src/ch06/Water.java:
--------------------------------------------------------------------------------
1 | package ch06;
2 |
3 | public class Water {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/Chapter5/src/ch07/GenericPrinter.java:
--------------------------------------------------------------------------------
1 | package ch07;
2 |
3 | public class GenericPrinter {
4 | private T material;
5 |
6 | public void setMaterial(T material) {
7 | this.material = material;
8 | }
9 |
10 | public T getMaterial() {
11 | return material;
12 | }
13 |
14 | public String toString(){
15 | return material.toString();
16 | }
17 |
18 | public void printing() {
19 | material.doPrinting();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter5/src/ch07/GenericPrinterTest.java:
--------------------------------------------------------------------------------
1 | package ch07;
2 |
3 | public class GenericPrinterTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | GenericPrinter powderPrinter = new GenericPrinter();
8 | powderPrinter.setMaterial(new Powder());
9 | Powder powder = powderPrinter.getMaterial(); // 형변환 하지 않음
10 | System.out.println(powderPrinter);
11 |
12 | GenericPrinter plasticPrinter = new GenericPrinter();
13 | plasticPrinter.setMaterial(new Plastic());
14 | Plastic plastic = plasticPrinter.getMaterial(); // 형변환 하지 않음
15 | System.out.println(plasticPrinter);
16 |
17 | /* GenericPrinter powderPrinter2 = new GenericPrinter();
18 | powderPrinter2.setMaterial(new Powder());
19 | Powder powder = (Powder)powderPrinter.getMaterial();
20 | System.out.println(powderPrinter);
21 | */
22 | //GenericPrinter printer = new GenericPrinter();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Chapter5/src/ch07/GenericPrinterTest2.java:
--------------------------------------------------------------------------------
1 | package ch07;
2 |
3 | public class GenericPrinterTest2 {
4 |
5 | public static void main(String[] args) {
6 |
7 | GenericPrinter powderPrinter = new GenericPrinter();
8 | powderPrinter.setMaterial(new Powder());
9 | powderPrinter.printing();
10 |
11 | GenericPrinter plasticPrinter = new GenericPrinter();
12 | plasticPrinter.setMaterial(new Plastic());
13 | plasticPrinter.printing();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Chapter5/src/ch07/Material.java:
--------------------------------------------------------------------------------
1 | package ch07;
2 |
3 | public abstract class Material {
4 |
5 | public abstract void doPrinting();
6 | }
7 |
--------------------------------------------------------------------------------
/Chapter5/src/ch07/MyArrayTest.java:
--------------------------------------------------------------------------------
1 | package ch07;
2 |
3 | class MyArrayG{
4 | private Object[] array = new Object[10];
5 | int i;
6 |
7 | public void add(E obj){
8 | array[i++] = obj;
9 | }
10 |
11 | public E get(int index){
12 | return (E)array[index];
13 | }
14 | }
15 |
16 | public class MyArrayTest {
17 |
18 | public static void main(String[] args) {
19 |
20 | MyArrayG myArray1 = new MyArrayG();
21 | myArray1.add(new String("test"));
22 | String str = myArray1.get(0); //형 변환 하지 않음
23 | System.out.println(str);
24 |
25 | MyArrayG myArray2 = new MyArrayG();
26 | myArray2.add(new Integer(100));
27 | Integer num = myArray2.get(0);
28 | System.out.println(num);
29 | }
30 | }
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/Chapter5/src/ch07/MyArrayTest2.java:
--------------------------------------------------------------------------------
1 | package ch07;
2 |
3 | class MyArray{
4 | private Object[] array = new Object[10];
5 | int i;
6 |
7 | public void add(Object obj){
8 | array[i++] = obj;
9 | }
10 |
11 | public Object get(int index){
12 | return array[index];
13 | }
14 | }
15 |
16 | public class MyArrayTest2 {
17 |
18 | public static void main(String[] args) {
19 |
20 | MyArray myArray1 = new MyArray();
21 | myArray1.add(new String("test"));
22 | String str = (String)myArray1.get(0);
23 | System.out.println(str);
24 |
25 | MyArray myArray2 = new MyArray();
26 | myArray2.add(new Integer(100));
27 | Integer num = (Integer)myArray2.get(0);
28 | System.out.println(num);
29 | }
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/Chapter5/src/ch07/Plastic.java:
--------------------------------------------------------------------------------
1 | package ch07;
2 |
3 | public class Plastic extends Material{
4 |
5 | public void doPrinting() {
6 | System.out.println("Plastic 재료로 출력합니다");
7 | }
8 |
9 | public String toString() {
10 | return "재료는 Plastic 입니다";
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter5/src/ch07/Powder.java:
--------------------------------------------------------------------------------
1 | package ch07;
2 |
3 | public class Powder extends Material{
4 |
5 | public void doPrinting() {
6 | System.out.println("Powder 재료로 출력합니다");
7 | }
8 |
9 | public String toString() {
10 | return "재료는 Powder 입니다";
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter5/src/ch07/ThreeDPrinter.java:
--------------------------------------------------------------------------------
1 | package ch07;
2 |
3 | public class ThreeDPrinter {
4 |
5 | private Object material;
6 |
7 | public void setMaterial(Object material) {
8 | this.material = material;
9 | }
10 |
11 | public Object getMaterial() {
12 | return material;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter5/src/ch07/ThreeDPrinterTest.java:
--------------------------------------------------------------------------------
1 | package ch07;
2 |
3 | public class ThreeDPrinterTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | ThreeDPrinter printer = new ThreeDPrinter();
8 | Powder p1 = new Powder();
9 | printer.setMaterial(p1);
10 | Powder p2 = (Powder)printer.getMaterial();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter5/src/ch07/Water.java:
--------------------------------------------------------------------------------
1 | package ch07;
2 |
3 | public class Water {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/Chapter5/src/ch08/GenericMethod.java:
--------------------------------------------------------------------------------
1 | package ch08;
2 |
3 | public class GenericMethod {
4 |
5 | public static double makeRectangle(Point p1, Point p2) {
6 | double left = ((Number)p1.getX()).doubleValue();
7 | double right =((Number)p2.getX()).doubleValue();
8 | double top = ((Number)p1.getY()).doubleValue();
9 | double bottom = ((Number)p2.getY()).doubleValue();
10 |
11 | double width = right - left;
12 | double height = bottom - top;
13 |
14 | return width * height;
15 | }
16 |
17 | public static void main(String[] args) {
18 |
19 | Point p1 = new Point(0, 0.0);
20 | Point p2 = new Point<>(10, 10.0);
21 |
22 | double rect = GenericMethod.makeRectangle(p1, p2);
23 | System.out.println("두 점으로 만들어진 사각형의 넓이는 " + rect + "입니다.");
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Chapter5/src/ch08/Point.java:
--------------------------------------------------------------------------------
1 | package ch08;
2 |
3 | public class Point {
4 |
5 | T x;
6 | V y;
7 |
8 | Point(T x, V y){
9 | this.x = x;
10 | this.y = y;
11 | }
12 |
13 | public T getX() {
14 | return x;
15 | }
16 |
17 | public V getY() {
18 | return y;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter5/src/ch10/Member.java:
--------------------------------------------------------------------------------
1 | package ch10;
2 |
3 | public class Member {
4 |
5 | private int memberId; //회원 아이디
6 | private String memberName; //회원 이름
7 |
8 | public Member(int memberId, String memberName){ //생성자
9 | this.memberId = memberId;
10 | this.memberName = memberName;
11 | }
12 |
13 | public int getMemberId() { //
14 | return memberId;
15 | }
16 | public void setMemberId(int memberId) {
17 | this.memberId = memberId;
18 | }
19 | public String getMemberName() {
20 | return memberName;
21 | }
22 | public void setMemberName(String memberName) {
23 | this.memberName = memberName;
24 | }
25 |
26 | @Override
27 | public String toString(){ //toString 메소드 오버로딩
28 | return memberName + " 회원님의 아이디는 " + memberId + "입니다";
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Chapter5/src/ch10/MemberArrayList.java:
--------------------------------------------------------------------------------
1 | package ch10;
2 |
3 | import java.util.ArrayList; // 사용할 클래스 import
4 | import java.util.Iterator;
5 |
6 | public class MemberArrayList {
7 |
8 | private ArrayList arrayList; // ArrayList 선언
9 |
10 | public MemberArrayList(){
11 | arrayList = new ArrayList(); //멤버로 선언한 ArrayList 생성
12 | }
13 |
14 | public void addMember(Member member){ //ArrayList 에 멤버 추가
15 | arrayList.add(member);
16 | }
17 |
18 | public boolean removeMember(int memberId){ // 멤버 아이디를 매개변수로, 삭제 여부를 반환
19 |
20 | /* for(int i =0; i ir = arrayList.iterator();
31 | while(ir.hasNext()) {
32 | Member member = ir.next();
33 | int tempId = member.getMemberId();
34 | if(tempId == memberId){ // 멤버아이디가 매개변수와 일치하면
35 | arrayList.remove(member); // 해당 멤버를 삭제
36 | return true; // true 반환
37 | }
38 | }
39 |
40 | System.out.println(memberId + "가 존재하지 않습니다"); //for 가 끝날때 까지 return 이 안된경우
41 | return false;
42 | }
43 |
44 | public void showAllMember(){
45 | for(Member member : arrayList){
46 | System.out.println(member);
47 | }
48 | System.out.println();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/Chapter5/src/ch10/MemberArrayListTest.java:
--------------------------------------------------------------------------------
1 | package ch10;
2 |
3 | public class MemberArrayListTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | MemberArrayList memberArrayList = new MemberArrayList();
8 |
9 | Member memberLee = new Member(1001, "이순신");
10 | Member memberKim = new Member(1002, "김유신");
11 | Member memberKang = new Member(1003, "강감찬");
12 | Member memberHong = new Member(1004, "홍길동");
13 |
14 | memberArrayList.addMember(memberLee);
15 | memberArrayList.addMember(memberKim);
16 | memberArrayList.addMember(memberKang);
17 | memberArrayList.addMember(memberHong);
18 |
19 | memberArrayList.showAllMember();
20 |
21 | memberArrayList.removeMember(memberHong.getMemberId());
22 | memberArrayList.showAllMember();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Chapter5/src/ch12/HashSetTest.java:
--------------------------------------------------------------------------------
1 | package ch12;
2 |
3 | import java.util.HashSet;
4 |
5 | public class HashSetTest {
6 |
7 | public static void main(String[] args) {
8 |
9 | HashSet hashSet = new HashSet();
10 | hashSet.add(new String("김유신"));
11 | hashSet.add(new String("이순신"));
12 | hashSet.add(new String("홍연의"));
13 | hashSet.add(new String("강감찬"));
14 | hashSet.add(new String("강감찬"));
15 |
16 | System.out.println(hashSet);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter5/src/ch12/Member.java:
--------------------------------------------------------------------------------
1 | package ch12;
2 |
3 | public class Member {
4 |
5 | private int memberId; //회원 아이디
6 | private String memberName; //회원 이름
7 |
8 | public Member(int memberId, String memberName){ //생성자
9 | this.memberId = memberId;
10 | this.memberName = memberName;
11 | }
12 |
13 | public int getMemberId() { //
14 | return memberId;
15 | }
16 | public void setMemberId(int memberId) {
17 | this.memberId = memberId;
18 | }
19 | public String getMemberName() {
20 | return memberName;
21 | }
22 | public void setMemberName(String memberName) {
23 | this.memberName = memberName;
24 | }
25 |
26 | @Override
27 | public int hashCode() {
28 | return memberId;
29 | }
30 |
31 | @Override
32 | public boolean equals(Object obj) {
33 | if( obj instanceof Member){
34 | Member member = (Member)obj;
35 | if( this.memberId == member.memberId )
36 | return true;
37 | else
38 | return false;
39 | }
40 | return false;
41 | }
42 |
43 | @Override
44 | public String toString(){ //toString 메소드 오버로딩
45 | return memberName + " 회원님의 아이디는 " + memberId + "입니다";
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/Chapter5/src/ch12/MemberHashSet.java:
--------------------------------------------------------------------------------
1 | package ch12;
2 |
3 | import java.util.HashSet;
4 | import java.util.Iterator;
5 |
6 |
7 | public class MemberHashSet {
8 | private HashSet hashSet;
9 |
10 | public MemberHashSet(){
11 | hashSet = new HashSet();
12 | }
13 |
14 | public void addMember(Member member){
15 | hashSet.add(member);
16 | }
17 |
18 | public boolean removeMember(int memberId){
19 |
20 | Iterator ir = hashSet.iterator();
21 |
22 | while( ir.hasNext()){
23 | Member member = ir.next();
24 | int tempId = member.getMemberId();
25 | if( tempId == memberId){
26 | hashSet.remove(member);
27 | return true;
28 | }
29 | }
30 |
31 | System.out.println(memberId + "가 존재하지 않습니다");
32 | return false;
33 | }
34 |
35 | public void showAllMember(){
36 | for(Member member : hashSet){
37 | System.out.println(member);
38 | }
39 | System.out.println();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Chapter5/src/ch12/MemberHashSetTest.java:
--------------------------------------------------------------------------------
1 | package ch12;
2 |
3 | public class MemberHashSetTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | MemberHashSet memberHashSet = new MemberHashSet();
8 |
9 | Member memberLee = new Member(1001, "이순신");
10 | Member memberKim = new Member(1002, "김유신");
11 | Member memberKang = new Member(1003, "강감찬");
12 |
13 |
14 | memberHashSet.addMember(memberLee);
15 | memberHashSet.addMember(memberKim);
16 | memberHashSet.addMember(memberKang);
17 | memberHashSet.showAllMember();
18 |
19 | Member memberHong = new Member(1003, "홍길동"); //1003 아이디 중복
20 | memberHashSet.addMember(memberHong);
21 | memberHashSet.showAllMember();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Chapter5/src/ch13/ComparatorTest.java:
--------------------------------------------------------------------------------
1 | package ch13;
2 |
3 | import java.util.Comparator;
4 | import java.util.Set;
5 | import java.util.TreeSet;
6 |
7 | class MyCompare implements Comparator{
8 |
9 | @Override
10 | public int compare(String s1, String s2) {
11 | return (s1.compareTo(s2)) *-1 ;
12 | }
13 | }
14 |
15 | public class ComparatorTest {
16 |
17 | public static void main(String[] args) {
18 |
19 | Set set = new TreeSet(new MyCompare());
20 | set.add("aaa");
21 | set.add("ccc");
22 | set.add("bbb");
23 |
24 | System.out.println(set);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Chapter5/src/ch13/Member.java:
--------------------------------------------------------------------------------
1 | package ch13;
2 |
3 | public class Member implements Comparable{
4 |
5 | private int memberId; //회원 아이디
6 | private String memberName; //회원 이름
7 |
8 | public Member(int memberId, String memberName){ //생성자
9 | this.memberId = memberId;
10 | this.memberName = memberName;
11 | }
12 |
13 | public int getMemberId() { //
14 | return memberId;
15 | }
16 | public void setMemberId(int memberId) {
17 | this.memberId = memberId;
18 | }
19 | public String getMemberName() {
20 | return memberName;
21 | }
22 | public void setMemberName(String memberName) {
23 | this.memberName = memberName;
24 | }
25 |
26 | @Override
27 | public String toString(){ //toString 메소드 오버로딩
28 | return memberName + " 회원님의 아이디는 " + memberId + "입니다";
29 | }
30 |
31 | @Override
32 | public int hashCode() {
33 | return memberId;
34 | }
35 |
36 | @Override
37 | public boolean equals(Object obj) {
38 | if( obj instanceof Member){
39 | Member member = (Member)obj;
40 | if( this.memberId == member.memberId )
41 | return true;
42 | else
43 | return false;
44 | }
45 | return false;
46 | }
47 |
48 | @Override
49 | public int compareTo(Member member) {
50 |
51 | //return (this.memberId - member.memberId); //오름차순
52 | return (this.memberId - member.memberId) * (-1); //내림 차순
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Chapter5/src/ch13/MemberTreeSet.java:
--------------------------------------------------------------------------------
1 | package ch13;
2 |
3 | import java.util.Iterator;
4 | import java.util.TreeSet;
5 |
6 |
7 |
8 | public class MemberTreeSet {
9 |
10 | private TreeSet treeSet;
11 |
12 | public MemberTreeSet(){
13 | treeSet = new TreeSet();
14 | }
15 |
16 | public void addMember(Member member){
17 | treeSet.add(member);
18 | }
19 |
20 | public boolean removeMember(int memberId){
21 |
22 | Iterator ir = treeSet.iterator();
23 |
24 | while( ir.hasNext()){
25 | Member member = ir.next();
26 | int tempId = member.getMemberId();
27 | if( tempId == memberId){
28 | treeSet.remove(member);
29 | return true;
30 | }
31 | }
32 |
33 | System.out.println(memberId + "가 존재하지 않습니다");
34 | return false;
35 | }
36 |
37 | public void showAllMember(){
38 | for(Member member : treeSet){
39 | System.out.println(member);
40 | }
41 | System.out.println();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Chapter5/src/ch13/MemberTreeSetTest.java:
--------------------------------------------------------------------------------
1 | package ch13;
2 |
3 | public class MemberTreeSetTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | MemberTreeSet memberTreeSet = new MemberTreeSet();
8 |
9 |
10 | Member memberKim = new Member(1003, "김유신");
11 | Member memberLee = new Member(1001, "이순신");
12 | Member memberKang = new Member(1002, "강감찬");
13 |
14 |
15 | memberTreeSet.addMember(memberKim);
16 | memberTreeSet.addMember(memberLee);
17 | memberTreeSet.addMember(memberKang);
18 | memberTreeSet.showAllMember();
19 |
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter5/src/ch13/TreeSetTest.java:
--------------------------------------------------------------------------------
1 | package ch13;
2 |
3 | import java.util.TreeSet;
4 |
5 | public class TreeSetTest {
6 |
7 | public static void main(String[] args) {
8 |
9 | TreeSet treeSet = new TreeSet();
10 | treeSet.add("홍길동");
11 | treeSet.add("강감찬");
12 | treeSet.add("이순신");
13 |
14 | for(String str : treeSet) {
15 | System.out.println(str);
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter5/src/ch14/Member.java:
--------------------------------------------------------------------------------
1 | package ch14;
2 |
3 | public class Member implements Comparable{
4 |
5 | private int memberId; //회원 아이디
6 | private String memberName; //회원 이름
7 |
8 | public Member(int memberId, String memberName){ //생성자
9 | this.memberId = memberId;
10 | this.memberName = memberName;
11 | }
12 |
13 | public int getMemberId() { //
14 | return memberId;
15 | }
16 | public void setMemberId(int memberId) {
17 | this.memberId = memberId;
18 | }
19 | public String getMemberName() {
20 | return memberName;
21 | }
22 | public void setMemberName(String memberName) {
23 | this.memberName = memberName;
24 | }
25 |
26 | @Override
27 | public String toString(){ //toString 메소드 오버로딩
28 | return memberName + " 회원님의 아이디는 " + memberId + "입니다";
29 | }
30 |
31 | @Override
32 | public int hashCode() {
33 | return memberId;
34 | }
35 |
36 | @Override
37 | public boolean equals(Object obj) {
38 | if( obj instanceof Member){
39 | Member member = (Member)obj;
40 | if( this.memberId == member.memberId )
41 | return true;
42 | else
43 | return false;
44 | }
45 | return false;
46 | }
47 |
48 | @Override
49 | public int compareTo(Member member) {
50 |
51 | //return (this.memberId - member.memberId); //오름차순
52 | return (this.memberId - member.memberId) * (-1); //내림 차순
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Chapter5/src/ch14/MemberHashMap.java:
--------------------------------------------------------------------------------
1 | package ch14;
2 |
3 | import java.util.HashMap;
4 | import java.util.Iterator;
5 |
6 |
7 | public class MemberHashMap {
8 |
9 | private HashMap hashMap;
10 |
11 | public MemberHashMap()
12 | {
13 | hashMap = new HashMap();
14 | }
15 |
16 | public void addMember(Member member){
17 |
18 | hashMap.put(member.getMemberId(), member);
19 |
20 | }
21 |
22 | public boolean removeMember(int memberId){
23 |
24 | if(hashMap.containsKey(memberId)){
25 | hashMap.remove(memberId);
26 | return true;
27 | }
28 |
29 | System.out.println(memberId + "가 존재하지 않습니다");
30 | return false;
31 | }
32 |
33 | public void showAllMember(){
34 | Iterator ir = hashMap.keySet().iterator();
35 | while (ir.hasNext()){
36 | int key = ir.next();
37 | Member member = hashMap.get(key);
38 | System.out.println(member);
39 | }
40 | System.out.println();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Chapter5/src/ch14/MemberHashMapTest.java:
--------------------------------------------------------------------------------
1 | package ch14;
2 |
3 |
4 | public class MemberHashMapTest {
5 |
6 | public static void main(String[] args) {
7 |
8 | MemberHashMap memberHashMap = new MemberHashMap();
9 |
10 |
11 | Member memberLee = new Member(1001, "이순신");
12 | Member memberKim = new Member(1002, "김유신");
13 | Member memberKang = new Member(1003, "강감찬");
14 | Member memberHong = new Member(1004, "홍길동");
15 |
16 | memberHashMap.addMember(memberLee);
17 | memberHashMap.addMember(memberKim);
18 | memberHashMap.addMember(memberKang);
19 | memberHashMap.addMember(memberHong);
20 |
21 | memberHashMap.showAllMember();
22 |
23 | memberHashMap.removeMember(1004);
24 | memberHashMap.showAllMember();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Chapter6/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Chapter6/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 |
--------------------------------------------------------------------------------
/Chapter6/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Chapter6
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Chapter6/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=14
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
13 | org.eclipse.jdt.core.compiler.release=enabled
14 | org.eclipse.jdt.core.compiler.source=14
15 |
--------------------------------------------------------------------------------
/Chapter6/a.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/easyspubjava/FastCampus/32eccedaccc72813db2efaf1010a3541b76ef502/Chapter6/a.zip
--------------------------------------------------------------------------------
/Chapter6/copy.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/easyspubjava/FastCampus/32eccedaccc72813db2efaf1010a3541b76ef502/Chapter6/copy.zip
--------------------------------------------------------------------------------
/Chapter6/data.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/easyspubjava/FastCampus/32eccedaccc72813db2efaf1010a3541b76ef502/Chapter6/data.txt
--------------------------------------------------------------------------------
/Chapter6/external.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/easyspubjava/FastCampus/32eccedaccc72813db2efaf1010a3541b76ef502/Chapter6/external.out
--------------------------------------------------------------------------------
/Chapter6/fine.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/easyspubjava/FastCampus/32eccedaccc72813db2efaf1010a3541b76ef502/Chapter6/fine.txt
--------------------------------------------------------------------------------
/Chapter6/input.txt:
--------------------------------------------------------------------------------
1 | ABC
--------------------------------------------------------------------------------
/Chapter6/input2.txt:
--------------------------------------------------------------------------------
1 | ABCDEFGHIJKLMNOPQRSTUVWXYZ
--------------------------------------------------------------------------------
/Chapter6/log.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/easyspubjava/FastCampus/32eccedaccc72813db2efaf1010a3541b76ef502/Chapter6/log.txt
--------------------------------------------------------------------------------
/Chapter6/output.txt:
--------------------------------------------------------------------------------
1 | ABC
--------------------------------------------------------------------------------
/Chapter6/output2.txt:
--------------------------------------------------------------------------------
1 | ABCDEFGHIJKLMNOPQRSTUVWXYZ
--------------------------------------------------------------------------------
/Chapter6/output3.txt:
--------------------------------------------------------------------------------
1 | CDEFGHIJKL
--------------------------------------------------------------------------------
/Chapter6/outwriter.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/easyspubjava/FastCampus/32eccedaccc72813db2efaf1010a3541b76ef502/Chapter6/outwriter.txt
--------------------------------------------------------------------------------
/Chapter6/random.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/easyspubjava/FastCampus/32eccedaccc72813db2efaf1010a3541b76ef502/Chapter6/random.txt
--------------------------------------------------------------------------------
/Chapter6/reader.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/easyspubjava/FastCampus/32eccedaccc72813db2efaf1010a3541b76ef502/Chapter6/reader.txt
--------------------------------------------------------------------------------
/Chapter6/serial.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/easyspubjava/FastCampus/32eccedaccc72813db2efaf1010a3541b76ef502/Chapter6/serial.out
--------------------------------------------------------------------------------
/Chapter6/src/ch01/AnonymousInnerTest.java:
--------------------------------------------------------------------------------
1 | package ch01;
2 |
3 | class Outter2{
4 |
5 | Runnable getRunnable(int i){
6 |
7 | int num = 100;
8 |
9 | return new Runnable() {
10 |
11 | @Override
12 | public void run() {
13 | //num = 200; //에러 남
14 | //i = 10; //에러 남
15 | System.out.println(i);
16 | System.out.println(num);
17 | }
18 | };
19 | }
20 |
21 | Runnable runner = new Runnable() {
22 |
23 | @Override
24 | public void run() {
25 | System.out.println("Runnable 이 구현된 익명 클래스 변수");
26 |
27 | }
28 | };
29 | }
30 |
31 | public class AnonymousInnerTest {
32 |
33 | public static void main(String[] args) {
34 | Outter2 out = new Outter2();
35 |
36 | Runnable runnerble = out.getRunnable(10);
37 | runnerble.run();
38 |
39 | out.runner.run();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Chapter6/src/ch01/LocalInnerTest.java:
--------------------------------------------------------------------------------
1 | package ch01;
2 |
3 | class Outer{
4 |
5 | int outNum = 100;
6 | static int sNum = 200;
7 |
8 |
9 | Runnable getRunnable(int i){
10 |
11 | int num = 100;
12 |
13 | class MyRunnable implements Runnable{
14 |
15 | int localNum = 10;
16 |
17 | @Override
18 | public void run() {
19 | //num = 200; //에러 남. 지역변수는 상수로 바뀜
20 | //i = 100; //에러 남. 매개 변수 역시 지역변수처럼 상수로 바뀜
21 | System.out.println("i =" + i);
22 | System.out.println("num = " +num);
23 | System.out.println("localNum = " +localNum);
24 |
25 | System.out.println("outNum = " + outNum + "(외부 클래스 인스턴스 변수)");
26 | System.out.println("Outter.sNum = " + Outer.sNum + "(외부 클래스 정적 변수)");
27 | }
28 | }
29 | return new MyRunnable();
30 | }
31 | }
32 |
33 | public class LocalInnerTest {
34 |
35 | public static void main(String[] args) {
36 |
37 | Outer out = new Outer();
38 | Runnable runner = out.getRunnable(10);
39 | runner.run();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Chapter6/src/ch03/Add.java:
--------------------------------------------------------------------------------
1 | package ch03;
2 |
3 | @FunctionalInterface
4 | public interface Add {
5 |
6 | public int add(int x, int y);
7 | }
8 |
--------------------------------------------------------------------------------
/Chapter6/src/ch03/MyNumber.java:
--------------------------------------------------------------------------------
1 | package ch03;
2 |
3 | @FunctionalInterface
4 | public interface MyNumber {
5 |
6 | int getMax(int num1, int num2);
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/Chapter6/src/ch03/TestAdd.java:
--------------------------------------------------------------------------------
1 | package ch03;
2 |
3 | public class TestAdd {
4 |
5 | public static void main(String[] args) {
6 |
7 | Add addF = (x, y) -> x + y;
8 |
9 | System.out.println(addF.add(3,5));
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter6/src/ch03/TestMyNumber.java:
--------------------------------------------------------------------------------
1 | package ch03;
2 |
3 | public class TestMyNumber {
4 |
5 | public static void main(String[] args) {
6 | MyNumber max = (x, y)->(x>= y)? x:y; // 람다식을 인터페이스 자료형 max 변수에 대입
7 |
8 | System.out.println(max.getMax(10, 20));// 인터페이스 자료형 변수로 함수 호출
9 |
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Chapter6/src/ch04/StringConCatImpl.java:
--------------------------------------------------------------------------------
1 | package ch04;
2 |
3 | public class StringConCatImpl implements StringConcat{
4 |
5 | @Override
6 | public void makeString(String s1, String s2) {
7 | System.out.println( s1 + "," + s2 );
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter6/src/ch04/StringConcat.java:
--------------------------------------------------------------------------------
1 | package ch04;
2 |
3 | public interface StringConcat {
4 |
5 | public void makeString(String s1, String s2);
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/Chapter6/src/ch04/TestLambda.java:
--------------------------------------------------------------------------------
1 | package ch04;
2 |
3 | interface PrintString{
4 |
5 | void showString(String str);
6 | }
7 |
8 | public class TestLambda {
9 |
10 | public static void main(String[] args) {
11 |
12 | PrintString lambdaStr = s->System.out.println(s); //람다식을 변수에 대입
13 | lambdaStr.showString("hello lambda_1");
14 |
15 | showMyString(lambdaStr); //메서드 매개변수로 전달
16 |
17 | PrintString reStr = returnString();
18 | reStr.showString("hello ");
19 |
20 | }
21 |
22 | public static void showMyString(PrintString p) {
23 | p.showString("hello lambda_2");
24 | }
25 |
26 | public static PrintString returnString() { //반환 값으로 사용
27 | return s->System.out.println(s + "world");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Chapter6/src/ch04/TestStringConcat.java:
--------------------------------------------------------------------------------
1 | package ch04;
2 |
3 | public class TestStringConcat {
4 |
5 | public static void main(String[] args) {
6 |
7 | String s1 = "Hello";
8 | String s2 = "World";
9 | StringConCatImpl concat1 = new StringConCatImpl();
10 | concat1.makeString(s1, s2);
11 | int i = 100;
12 |
13 | StringConcat concat2 = (s, v)->System.out.println(s + "," + v ); //System.out.println(i);
14 | concat2.makeString(s1, s2);
15 | i = 300;
16 |
17 | StringConcat concat3 = new StringConcat() {
18 |
19 | @Override
20 | public void makeString(String s1, String s2) {
21 |
22 | System.out.println( s1 + "," + s2 );
23 | }
24 | };
25 |
26 | concat3.makeString(s1, s2);
27 |
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/Chapter6/src/ch05/ArrayListStreamTest.java:
--------------------------------------------------------------------------------
1 | package ch05;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.stream.Stream;
6 |
7 | public class ArrayListStreamTest {
8 |
9 | public static void main(String[] args) {
10 | List sList = new ArrayList();
11 | sList.add("Tomas");
12 | sList.add("Edward");
13 | sList.add("Jack");
14 |
15 | Stream stream = sList.stream();
16 | stream.forEach(s->System.out.print(s + " "));
17 | System.out.println();
18 |
19 | sList.stream().sorted().forEach(s->System.out.print(s+ " "));
20 | sList.stream().map(s->s.length()).forEach(n->System.out.println(n));
21 | sList.stream().filter(s->s.length() >= 5).forEach(s->System.out.println(s));
22 |
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/Chapter6/src/ch05/IntArrayStreamTest.java:
--------------------------------------------------------------------------------
1 | package ch05;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 | import java.util.List;
6 |
7 | public class IntArrayStreamTest {
8 |
9 | public static void main(String[] args) {
10 | int[] arr = {1,2,3,4,5};
11 | Arrays.stream(arr).forEach(n->System.out.print(n + "\t"));
12 | System.out.println();
13 |
14 | int sum = Arrays.stream(arr).sum();
15 | System.out.println("sum: " + sum);
16 |
17 | List list = new ArrayList();
18 | list.add(1);
19 | list.add(2);
20 | list.add(3);
21 | list.add(4);
22 | list.add(5);
23 | int sum2 = list.stream().mapToInt(n->n.intValue()).sum();
24 | System.out.println(sum2);
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/Chapter6/src/ch05/IntArrayTest.java:
--------------------------------------------------------------------------------
1 | package ch05;
2 |
3 | import java.util.Arrays;
4 |
5 | public class IntArrayTest {
6 |
7 | public static void main(String[] args) {
8 |
9 | int[] arr = {1,2,3,4,5};
10 |
11 | int sumVal = Arrays.stream(arr).sum();
12 | long count = Arrays.stream(arr).count();
13 |
14 | System.out.println(sumVal);
15 | System.out.println(count);
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter6/src/ch06/ReduceTest.java:
--------------------------------------------------------------------------------
1 | package ch06;
2 |
3 | import java.util.Arrays;
4 | import java.util.function.BinaryOperator;
5 |
6 | class CompareString implements BinaryOperator{
7 |
8 | @Override
9 | public String apply(String s1, String s2) {
10 | if (s1.getBytes().length >= s2.getBytes().length) return s1;
11 | else return s2;
12 | }
13 | }
14 |
15 | public class ReduceTest {
16 |
17 | public static void main(String[] args) {
18 |
19 | String[] greetings = {"안녕하세요~~~", "hello", "Good morning", "반갑습니다^^"};
20 |
21 | System.out.println(Arrays.stream(greetings).reduce("", (s1, s2)->
22 | {if (s1.getBytes().length >= s2.getBytes().length)
23 | return s1;
24 | else return s2;}));
25 |
26 | String str = Arrays.stream(greetings).reduce(new CompareString()).get(); //BinaryOperator를 구현한 클래스 이용
27 | System.out.println(str);
28 |
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Chapter6/src/ch07/TravelCustomer.java:
--------------------------------------------------------------------------------
1 | package ch07;
2 |
3 | public class TravelCustomer {
4 |
5 | private String name; //이름
6 | private int age; //나이
7 | private int price; //가격
8 |
9 | public TravelCustomer(String name, int age, int price) {
10 | this.name = name;
11 | this.age = age;
12 | this.price = price;
13 | }
14 |
15 | public String getName() {
16 | return name;
17 | }
18 |
19 | public int getAge() {
20 | return age;
21 | }
22 |
23 | public int getPrice() {
24 | return price;
25 | }
26 |
27 | public void setName(String name) {
28 | this.name = name;
29 | }
30 |
31 | public void setAge(int age) {
32 | this.age = age;
33 | }
34 |
35 | public void setPrice(int price) {
36 | this.price = price;
37 | }
38 |
39 | public String toString() {
40 | return "name: " + name + "age: " + age + "price: " + price;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/Chapter6/src/ch07/TravelTest.java:
--------------------------------------------------------------------------------
1 | package ch07;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class TravelTest {
7 |
8 | public static void main(String[] args) {
9 | TravelCustomer customerLee = new TravelCustomer("이순신", 40, 100);
10 | TravelCustomer customerKim = new TravelCustomer("김유신", 20, 100);
11 | TravelCustomer customerHong = new TravelCustomer("홍길동", 13, 50);
12 |
13 | List customerList = new ArrayList<>();
14 | customerList.add(customerLee);
15 | customerList.add(customerKim);
16 | customerList.add(customerHong);
17 |
18 | System.out.println("== 고객 명단 추가된 순서대로 출력 ==");
19 | customerList.stream().map(c->c.getName()).forEach(s->System.out.println(s));
20 |
21 | int total = customerList.stream().mapToInt(c->c.getPrice()).sum();
22 | System.out.println("총 여행 비용은 :" + total + "입니다");
23 |
24 | System.out.println("== 20세 이상 고객 명단 정렬하여 출력 ==");
25 | customerList.stream().filter(c->c.getAge() >= 20).map(c->c.getName()).sorted().forEach(s->System.out.println(s));
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/Chapter6/src/ch08/ArrayExceptionHandling.java:
--------------------------------------------------------------------------------
1 | package ch08;
2 |
3 | public class ArrayExceptionHandling {
4 |
5 | public static void main(String[] args) {
6 | int[] arr = {1,2,3,4,5};
7 | try{
8 | for(int i=0; i<=5; i++){
9 | System.out.println(arr[i]);
10 | }
11 | }catch(ArrayIndexOutOfBoundsException e){
12 | System.out.println(e);
13 | }
14 | System.out.println("비정상 종료되지 않았습니다.");
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Chapter6/src/ch09/AutoCloseObj.java:
--------------------------------------------------------------------------------
1 | package ch09;
2 |
3 | public class AutoCloseObj implements AutoCloseable{
4 |
5 | @Override
6 | public void close() throws Exception {
7 | System.out.println("리소스가 close() 되었습니다");
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter6/src/ch09/AutoCloseTest.java:
--------------------------------------------------------------------------------
1 | package ch09;
2 |
3 | public class AutoCloseTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | AutoCloseObj obj = new AutoCloseObj();
8 | try (obj){
9 | throw new Exception();
10 | }catch(Exception e) {
11 | System.out.println("예외 부분 입니다");
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter6/src/ch09/FileExceptionHandling.java:
--------------------------------------------------------------------------------
1 | package ch09;
2 |
3 | import java.io.FileInputStream;
4 | import java.io.FileNotFoundException;
5 | import java.io.IOException;
6 |
7 | public class FileExceptionHandling {
8 |
9 | public static void main(String[] args) {
10 | FileInputStream fis = null;
11 | try {
12 | fis = new FileInputStream("a.txt");
13 | } catch (FileNotFoundException e) {
14 | System.out.println(e);
15 | //return;
16 | }finally{
17 | if(fis != null){
18 | try {
19 | fis.close();
20 | } catch (IOException e) {
21 | // TODO Auto-generated catch block
22 | e.printStackTrace();
23 | }
24 | }
25 | System.out.println("항상 수행 됩니다.");
26 | }
27 | System.out.println("여기도 수행됩니다.");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Chapter6/src/ch09/ThrowsException.java:
--------------------------------------------------------------------------------
1 | package ch09;
2 |
3 | import java.io.FileInputStream;
4 | import java.io.FileNotFoundException;
5 |
6 | public class ThrowsException {
7 |
8 | public Class loadClass(String fileName, String className) throws FileNotFoundException, ClassNotFoundException{
9 | FileInputStream fis = new FileInputStream(fileName); //FileNotFoundException 발생
10 | Class c = Class.forName(className); //ClassNotFoundException 발생
11 | return c;
12 | }
13 |
14 | public static void main(String[] args) {
15 |
16 | ThrowsException test = new ThrowsException();
17 |
18 | try {
19 | test.loadClass("a.txt", "java.lang.String");
20 |
21 | }catch (FileNotFoundException e) {
22 | e.printStackTrace();
23 | } catch (ClassNotFoundException e) {
24 | e.printStackTrace();
25 | }catch (Exception e) {
26 | e.printStackTrace();
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/Chapter6/src/ch09/ThrowsException2.java:
--------------------------------------------------------------------------------
1 | package ch09;
2 |
3 | import java.io.FileInputStream;
4 | import java.io.FileNotFoundException;
5 |
6 | public class ThrowsException2 {
7 |
8 | public Class loadClass(String fileName, String className) throws FileNotFoundException, ClassNotFoundException{
9 | FileInputStream fis = new FileInputStream(fileName); //FileNotFoundException 발생
10 | Class c = Class.forName(className); //ClassNotFoundException 발생
11 | return c;
12 | }
13 |
14 | public static void main(String[] args) {
15 |
16 | ThrowsException2 test = new ThrowsException2();
17 |
18 | try {
19 | test.loadClass("a.txt", "java.lang.String");
20 | } catch (FileNotFoundException | ClassNotFoundException e) {
21 | // TODO Auto-generated catch block
22 | e.printStackTrace();
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Chapter6/src/ch10/PasswordException.java:
--------------------------------------------------------------------------------
1 | package ch10;
2 |
3 | public class PasswordException extends IllegalArgumentException{
4 |
5 | public PasswordException(String message) {
6 | super(message);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/Chapter6/src/ch10/Test.java:
--------------------------------------------------------------------------------
1 | package ch10;
2 |
3 | public class Test {
4 |
5 | public static void main(String[] args) {
6 |
7 |
8 | String pass = new String("abc");
9 | System.out.println(pass.matches("[a-zA-Z]+")); //true
10 |
11 | String pass2 = new String("abc1");
12 | System.out.println(pass2.matches("[a-zA-Z]+")); //false
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter6/src/ch11/LoggerTest.java:
--------------------------------------------------------------------------------
1 | package ch11;
2 |
3 | public class LoggerTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | MyLogger myLogger = MyLogger.getLogger();
8 |
9 | myLogger.log("test");
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter6/src/ch11/Student.java:
--------------------------------------------------------------------------------
1 | package ch11;
2 |
3 |
4 | public class Student {
5 |
6 | private String studentName;
7 | MyLogger myLogger = MyLogger.getLogger();
8 |
9 | public Student(String studentName){
10 |
11 | if(studentName == null){
12 |
13 | throw new StudentNameFormatException("name must not be null");
14 | }
15 | if( studentName.split(" ").length > 3)
16 | throw new StudentNameFormatException("이름이 너무 길어요");
17 |
18 | this.studentName = studentName;
19 | }
20 |
21 |
22 | public String getStudentName() {
23 |
24 | myLogger.fine("begin getStudentName()");
25 |
26 | return studentName;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Chapter6/src/ch11/StudentNameFormatException.java:
--------------------------------------------------------------------------------
1 | package ch11;
2 |
3 | public class StudentNameFormatException extends IllegalArgumentException{
4 |
5 | public StudentNameFormatException(String message){
6 | super(message);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/Chapter6/src/ch11/StudentTest.java:
--------------------------------------------------------------------------------
1 | package ch11;
2 |
3 | public class StudentTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | MyLogger myLogger = MyLogger.getLogger();
8 |
9 | String name = null;
10 | try{
11 | Student student = new Student(name);
12 |
13 | }catch( StudentNameFormatException e ){
14 | myLogger.warning(e.getMessage());
15 | }
16 |
17 | try{
18 | Student student = new Student("Edward Jon Kim Test");
19 | }catch ( StudentNameFormatException e){
20 | myLogger.warning(e.getMessage());
21 | }
22 |
23 | Student student = new Student("James");
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Chapter6/src/ch13/SystemInTest1.java:
--------------------------------------------------------------------------------
1 | package ch13;
2 |
3 | import java.io.IOException;
4 |
5 | public class SystemInTest1 {
6 |
7 | public static void main(String[] args) {
8 | System.out.println("알파벳 하나를 쓰고 [Enter]를 누르세요");
9 |
10 | int i;
11 | try {
12 | i = System.in.read();
13 | System.out.println(i);
14 | System.out.println((char)i);
15 | } catch (IOException e) {
16 | // TODO Auto-generated catch block
17 | e.printStackTrace();
18 | }
19 |
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/Chapter6/src/ch13/SystemInTest2.java:
--------------------------------------------------------------------------------
1 | package ch13;
2 |
3 | import java.io.IOException;
4 |
5 | public class SystemInTest2 {
6 |
7 | public static void main(String[] args) {
8 | System.out.println("알파벳 여러 개를 쓰고 [Enter]를 누르세요");
9 |
10 | int i;
11 | try {
12 | while( (i = System.in.read()) != '\n' ) {
13 | System.out.print((char)i);
14 | }
15 | } catch (IOException e) {
16 | e.printStackTrace();
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Chapter6/src/ch14/FileInputStreamTest1.java:
--------------------------------------------------------------------------------
1 | package ch14;
2 |
3 | import java.io.FileInputStream;
4 | import java.io.IOException;
5 |
6 | public class FileInputStreamTest1 {
7 |
8 | public static void main(String[] args) {
9 | FileInputStream fis = null;
10 |
11 | try {
12 | fis = new FileInputStream("input.txt");
13 |
14 | System.out.println((char)fis.read());
15 | System.out.println((char)fis.read());
16 | System.out.println((char)fis.read());
17 |
18 | } catch (IOException e) {
19 | System.out.println(e);
20 | } finally{
21 | try {
22 | fis.close();
23 | } catch (IOException e) {
24 | System.out.println(e);
25 | } catch (NullPointerException e){
26 | System.out.println(e);
27 | }
28 | }
29 | System.out.println("end");
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/Chapter6/src/ch14/FileInputStreamTest2.java:
--------------------------------------------------------------------------------
1 | package ch14;
2 |
3 | import java.io.FileInputStream;
4 | import java.io.FileNotFoundException;
5 | import java.io.IOException;
6 |
7 | public class FileInputStreamTest2 {
8 |
9 | public static void main(String[] args) {
10 |
11 | try(FileInputStream fis = new FileInputStream("input.txt")){
12 | int i;
13 | while ( (i = fis.read()) != -1){
14 | System.out.println((char)i);
15 | }
16 | System.out.println("end");
17 | } catch (FileNotFoundException e) {
18 | e.printStackTrace();
19 | } catch (IOException e) {
20 | e.printStackTrace();
21 | }
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/Chapter6/src/ch14/FileInputStreamTest3.java:
--------------------------------------------------------------------------------
1 | package ch14;
2 | import java.io.FileInputStream;
3 | import java.io.IOException;
4 |
5 | public class FileInputStreamTest3 {
6 |
7 | public static void main(String[] args) {
8 |
9 | try (FileInputStream fis = new FileInputStream("input2.txt")){
10 |
11 | byte[] bs = new byte[10];
12 | int i;
13 | while ( (i = fis.read(bs)) != -1){
14 | /*for(byte b : bs){
15 | System.out.print((char)b);
16 | }*/
17 | for(int k= 0; k
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Chapter7-Up/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 |
--------------------------------------------------------------------------------
/Chapter7-Up/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Chapter7-Up
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Chapter7-Up/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=14
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
13 | org.eclipse.jdt.core.compiler.release=enabled
14 | org.eclipse.jdt.core.compiler.source=14
15 |
--------------------------------------------------------------------------------
/Chapter7-Up/src/grade/BasicEvaluation.java:
--------------------------------------------------------------------------------
1 | package grade;
2 |
3 | public class BasicEvaluation implements GradeEvaluation{
4 |
5 | @Override
6 | public String getGrade(int point) {
7 | String grade;
8 |
9 | if(point >=90 && point <=100)
10 | grade = "A";
11 | else if(point >=80 && point <=89)
12 | grade = "B";
13 | else if(point >=70 && point <=79)
14 | grade = "C";
15 | else if(point >=55 && point <=69)
16 | grade = "D";
17 | else
18 | grade = "F";
19 | return grade;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter7-Up/src/grade/GradeEvaluation.java:
--------------------------------------------------------------------------------
1 | package grade;
2 |
3 | public interface GradeEvaluation {
4 | public String getGrade(int point);
5 | }
6 |
--------------------------------------------------------------------------------
/Chapter7-Up/src/grade/MajorEvaluation.java:
--------------------------------------------------------------------------------
1 | package grade;
2 |
3 | public class MajorEvaluation implements GradeEvaluation{
4 |
5 | @Override
6 | public String getGrade(int point) {
7 | String grade;
8 | if(point >=95 && point <=100)
9 | grade = "S";
10 | else if(point >=90 && point <=94)
11 | grade = new String("A");
12 | else if(point >=80 && point <=89)
13 | grade = "B";
14 | else if(point >=70 && point <=79)
15 | grade = "C";
16 | else if(point >=60 && point <=69)
17 | grade = "D";
18 | else
19 | grade = "F";
20 | return grade;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Chapter7-Up/src/grade/PassFailEvaluation.java:
--------------------------------------------------------------------------------
1 | package grade;
2 |
3 | public class PassFailEvaluation implements GradeEvaluation{
4 |
5 | @Override
6 | public String getGrade(int point) {
7 | if (point >= 70)
8 | return "P";
9 | else
10 | return "F";
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter7-Up/src/school/School.java:
--------------------------------------------------------------------------------
1 | package school;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class School {
6 |
7 | private static School instance = new School();
8 |
9 | private static String SCHOOL_NAME = "Good School";
10 | private ArrayList studentList = new ArrayList();
11 | private ArrayList subjectList = new ArrayList();
12 |
13 | private School(){}
14 |
15 | public static School getInstance(){
16 | if(instance == null)
17 | instance = new School();
18 | return instance;
19 | }
20 |
21 | public ArrayList getStudentList(){
22 | return studentList;
23 | }
24 |
25 | public void addStudent(Student student){
26 | studentList.add(student);
27 | }
28 |
29 | public void addSubject(Subject subject) {
30 | subjectList.add(subject);
31 | }
32 |
33 | public ArrayList getSubjectList() {
34 | return subjectList;
35 | }
36 |
37 | public void setSubjectList(ArrayList subjectList) {
38 | this.subjectList = subjectList;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Chapter7-Up/src/school/Score.java:
--------------------------------------------------------------------------------
1 | package school;
2 |
3 | public class Score {
4 | int studentId; //학번
5 | Subject subject; //과목
6 | int point; //점수
7 |
8 | public Score( int studentId, Subject subject, int point){
9 | this.studentId = studentId;
10 | this.subject = subject;
11 | this.point = point;
12 | }
13 |
14 | public int getStudentId() {
15 | return studentId;
16 | }
17 |
18 | public void setStudentId(int studentId) {
19 | this.studentId = studentId;
20 | }
21 |
22 | public Subject getSubject() {
23 | return subject;
24 | }
25 |
26 | public void setSubject(Subject subject) {
27 | this.subject = subject;
28 | }
29 |
30 | public int getPoint() {
31 | return point;
32 | }
33 |
34 | public void setPoint(int point) {
35 | this.point = point;
36 | }
37 |
38 | public String toString(){
39 | return "학번:" + studentId + "," + subject.getSubjectName() + ":" + point;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Chapter7-Up/src/school/Student.java:
--------------------------------------------------------------------------------
1 | package school;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class Student {
6 |
7 | private int studentId; //학번
8 | private String studentName; //이름
9 | private Subject majorSubject; //중점 과목
10 |
11 | //학생의 성적 리스트
12 | //addSubjectSocre() 메서드가 호출되면 리스트에 추가 됨
13 | private ArrayList scoreList = new ArrayList();
14 |
15 | public Student( int studentId, String studentName, Subject majorSubject){
16 | this.studentId = studentId;
17 | this.studentName = studentName;
18 | this.majorSubject = majorSubject;
19 | }
20 |
21 | public void addSubjectScore(Score score){
22 | scoreList.add(score);
23 | }
24 |
25 | public int getStudentId() {
26 | return studentId;
27 | }
28 |
29 | public void setStudentId(int studentId) {
30 | this.studentId = studentId;
31 | }
32 |
33 | public String getStudentName() {
34 | return studentName;
35 | }
36 |
37 | public void setStudentName(String studentName) {
38 | this.studentName = studentName;
39 | }
40 |
41 | public Subject getMajorSubject() {
42 | return majorSubject;
43 | }
44 |
45 | public void setMajorSubject(Subject majorSubject) {
46 | this.majorSubject = majorSubject;
47 | }
48 |
49 | public ArrayList getScoreList(){
50 | return scoreList;
51 | }
52 |
53 | public void setScoreList(ArrayList scoreList) {
54 | this.scoreList = scoreList;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Chapter7-Up/src/school/Subject.java:
--------------------------------------------------------------------------------
1 | package school;
2 |
3 | import java.util.ArrayList;
4 | import utils.Define;
5 |
6 |
7 | public class Subject {
8 | private String subjectName; //과목 이름
9 | private int subjectId; // 과목 고유번호
10 | private int gradeType; // 과목 평가 방법 기본은 A,B 방식
11 |
12 | //수강 신청한 학생 리스트
13 | //register() 메서드를 호출하면 리스트에 추가 됨
14 | private ArrayList studentList = new ArrayList();
15 |
16 | public Subject(String subjectName, int subjectId){
17 | this.subjectName = subjectName;
18 | this.subjectId = subjectId;
19 | this.gradeType = Define.AB_TYPE; //기본적으로 A, B 타입
20 | }
21 |
22 | public String getSubjectName() {
23 | return subjectName;
24 | }
25 |
26 | public void setSubjectName(String subjectName) {
27 | this.subjectName = subjectName;
28 | }
29 |
30 | public int getSubjectId() {
31 | return subjectId;
32 | }
33 |
34 | public void setSubjectId(int subjectId) {
35 | this.subjectId = subjectId;
36 | }
37 |
38 | public ArrayList getStudentList() {
39 | return studentList;
40 | }
41 |
42 | public void setStudentList(ArrayList studentList) {
43 | this.studentList = studentList;
44 | }
45 |
46 | public int getGradeType() {
47 | return gradeType;
48 | }
49 |
50 | public void setGradeType(int gradeType) {
51 | this.gradeType = gradeType;
52 | }
53 |
54 | public void register(Student student){ //수강신청
55 | studentList.add(student);
56 | }
57 | }
--------------------------------------------------------------------------------
/Chapter7-Up/src/utils/Define.java:
--------------------------------------------------------------------------------
1 | package utils;
2 |
3 | public class Define {
4 |
5 | public static final int KOREAN = 1001; //국어
6 | public static final int MATH = 2001; //수학
7 | public static final int DANCE = 3001; //방송댄스
8 |
9 | public static final int AB_TYPE = 0; // A, B, C
10 | public static final int SAB_TYPE = 1; // S, A, B, c
11 | public static final int PF_TYPE = 2; // P, F
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/Chapter7/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Chapter7/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 |
--------------------------------------------------------------------------------
/Chapter7/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Chapter7
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Chapter7/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=14
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
13 | org.eclipse.jdt.core.compiler.release=enabled
14 | org.eclipse.jdt.core.compiler.source=14
15 |
--------------------------------------------------------------------------------
/Chapter7/src/grade/BasicEvaluation.java:
--------------------------------------------------------------------------------
1 | package grade;
2 |
3 | public class BasicEvaluation implements GradeEvaluation{
4 |
5 | @Override
6 | public String getGrade(int point) {
7 | String grade;
8 |
9 | if(point >=90 && point <=100)
10 | grade = "A";
11 | else if(point >=80 && point <=89)
12 | grade = "B";
13 | else if(point >=70 && point <=79)
14 | grade = "C";
15 | else if(point >=55 && point <=69)
16 | grade = "D";
17 | else
18 | grade = "F";
19 | return grade;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter7/src/grade/GradeEvaluation.java:
--------------------------------------------------------------------------------
1 | package grade;
2 |
3 | public interface GradeEvaluation {
4 | public String getGrade(int point);
5 | }
6 |
--------------------------------------------------------------------------------
/Chapter7/src/grade/MajorEvaluation.java:
--------------------------------------------------------------------------------
1 | package grade;
2 |
3 | public class MajorEvaluation implements GradeEvaluation{
4 |
5 | @Override
6 | public String getGrade(int point) {
7 | String grade;
8 | if(point >=95 && point <=100)
9 | grade = "S";
10 | else if(point >=90 && point <=94)
11 | grade = new String("A");
12 | else if(point >=80 && point <=89)
13 | grade = "B";
14 | else if(point >=70 && point <=79)
15 | grade = "C";
16 | else if(point >=60 && point <=69)
17 | grade = "D";
18 | else
19 | grade = "F";
20 | return grade;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Chapter7/src/school/School.java:
--------------------------------------------------------------------------------
1 | package school;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class School {
6 |
7 | private static School instance = new School();
8 |
9 | private static String SCHOOL_NAME = "Good School";
10 | private ArrayList studentList = new ArrayList();
11 | private ArrayList subjectList = new ArrayList();
12 |
13 | private School(){}
14 |
15 | public static School getInstance(){
16 | if(instance == null)
17 | instance = new School();
18 | return instance;
19 | }
20 |
21 | public ArrayList getStudentList(){
22 | return studentList;
23 | }
24 |
25 | public void addStudent(Student student){
26 | studentList.add(student);
27 | }
28 |
29 | public void addSubject(Subject subject) {
30 | subjectList.add(subject);
31 | }
32 |
33 | public ArrayList getSubjectList() {
34 | return subjectList;
35 | }
36 |
37 | public void setSubjectList(ArrayList subjectList) {
38 | this.subjectList = subjectList;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Chapter7/src/school/Score.java:
--------------------------------------------------------------------------------
1 | package school;
2 |
3 | public class Score {
4 | int studentId; //학번
5 | Subject subject; //과목
6 | int point; //점수
7 |
8 | public Score( int studentId, Subject subject, int point){
9 | this.studentId = studentId;
10 | this.subject = subject;
11 | this.point = point;
12 | }
13 |
14 | public int getStudentId() {
15 | return studentId;
16 | }
17 |
18 | public void setStudentId(int studentId) {
19 | this.studentId = studentId;
20 | }
21 |
22 | public Subject getSubject() {
23 | return subject;
24 | }
25 |
26 | public void setSubject(Subject subject) {
27 | this.subject = subject;
28 | }
29 |
30 | public int getPoint() {
31 | return point;
32 | }
33 |
34 | public void setPoint(int point) {
35 | this.point = point;
36 | }
37 |
38 | public String toString(){
39 | return "학번:" + studentId + "," + subject.getSubjectName() + ":" + point;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Chapter7/src/school/Student.java:
--------------------------------------------------------------------------------
1 | package school;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class Student {
6 |
7 | private int studentId; //학번
8 | private String studentName; //이름
9 | private Subject majorSubject; //중점 과목
10 |
11 | //학생의 성적 리스트
12 | //addSubjectSocre() 메서드가 호출되면 리스트에 추가 됨
13 | private ArrayList scoreList = new ArrayList();
14 |
15 | public Student( int studentId, String studentName, Subject majorSubject){
16 | this.studentId = studentId;
17 | this.studentName = studentName;
18 | this.majorSubject = majorSubject;
19 | }
20 |
21 | public void addSubjectScore(Score score){
22 | scoreList.add(score);
23 | }
24 |
25 | public int getStudentId() {
26 | return studentId;
27 | }
28 |
29 | public void setStudentId(int studentId) {
30 | this.studentId = studentId;
31 | }
32 |
33 | public String getStudentName() {
34 | return studentName;
35 | }
36 |
37 | public void setStudentName(String studentName) {
38 | this.studentName = studentName;
39 | }
40 |
41 | public Subject getMajorSubject() {
42 | return majorSubject;
43 | }
44 |
45 | public void setMajorSubject(Subject majorSubject) {
46 | this.majorSubject = majorSubject;
47 | }
48 |
49 | public ArrayList getScoreList(){
50 | return scoreList;
51 | }
52 |
53 | public void setScoreList(ArrayList scoreList) {
54 | this.scoreList = scoreList;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Chapter7/src/school/Subject.java:
--------------------------------------------------------------------------------
1 | package school;
2 |
3 | import java.util.ArrayList;
4 | import utils.Define;
5 |
6 |
7 | public class Subject {
8 | private String subjectName; //과목 이름
9 | private int subjectId; // 과목 고유번호
10 | private int gradeType; // 과목 평가 방법 기본은 A,B 방식
11 |
12 | //수강 신청한 학생 리스트
13 | //register() 메서드를 호출하면 리스트에 추가 됨
14 | private ArrayList studentList = new ArrayList();
15 |
16 | public Subject(String subjectName, int subjectId){
17 | this.subjectName = subjectName;
18 | this.subjectId = subjectId;
19 | this.gradeType = Define.AB_TYPE; //기본적으로 A, B 타입
20 | }
21 |
22 | public String getSubjectName() {
23 | return subjectName;
24 | }
25 |
26 | public void setSubjectName(String subjectName) {
27 | this.subjectName = subjectName;
28 | }
29 |
30 | public int getSubjectId() {
31 | return subjectId;
32 | }
33 |
34 | public void setSubjectId(int subjectId) {
35 | this.subjectId = subjectId;
36 | }
37 |
38 | public ArrayList getStudentList() {
39 | return studentList;
40 | }
41 |
42 | public void setStudentList(ArrayList studentList) {
43 | this.studentList = studentList;
44 | }
45 |
46 | public int getGradeType() {
47 | return gradeType;
48 | }
49 |
50 | public void setGradeType(int gradeType) {
51 | this.gradeType = gradeType;
52 | }
53 |
54 | public void register(Student student){ //수강신청
55 | studentList.add(student);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/Chapter7/src/utils/Define.java:
--------------------------------------------------------------------------------
1 | package utils;
2 |
3 | public class Define {
4 |
5 | public static final int KOREAN = 1001; //국어
6 | public static final int MATH = 2001; //수학
7 |
8 | public static final int AB_TYPE = 0; // A, B, C
9 | public static final int SAB_TYPE = 1; // S, A, B, c
10 | public static final int PF_TYPE = 2; // P, F
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter8/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Chapter8/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 |
--------------------------------------------------------------------------------
/Chapter8/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Chapter8
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Chapter8/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/ch06=UTF-8
3 | encoding//src/ch06/maze/Robot.java=UTF-8
4 | encoding//src/ch06/test/MazeTest.java=UTF-8
5 | encoding/=UTF-8
6 |
--------------------------------------------------------------------------------
/Chapter8/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=14
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
13 | org.eclipse.jdt.core.compiler.release=enabled
14 | org.eclipse.jdt.core.compiler.source=14
15 |
--------------------------------------------------------------------------------
/Chapter8/src/ch01/MinMaxProblem.java:
--------------------------------------------------------------------------------
1 | package ch01;
2 |
3 | public class MinMaxProblem {
4 |
5 | public static void main(String[] args) {
6 |
7 | int[] numbers = {10, 55, 23, 2, 79, 101, 16, 82, 30, 45};
8 |
9 | int min = numbers[0];
10 | int max = numbers[0];
11 | int minPos = 0;
12 | int maxPos = 0;
13 |
14 | for(int i=1; i numbers[i]) {
17 | min = numbers[i];
18 | minPos = i+1;
19 | }
20 |
21 | if(max < numbers[i]) {
22 | max = numbers[i];
23 | maxPos = i+1;
24 | }
25 | }
26 |
27 | System.out.println("가장 큰 값은 " + max + "이고, 위치는 " + maxPos + "번째 입니다.");
28 | System.out.println("가장 작은 값은 " + min + "이고, 위치는 " + minPos + "번째 입니다.");
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/Chapter8/src/ch02/BinarySearchProblem.java:
--------------------------------------------------------------------------------
1 | package ch02;
2 |
3 | public class BinarySearchProblem {
4 |
5 | public static void main(String[] args) {
6 |
7 | int[] numbers = {12, 25, 31, 48, 54, 66, 70, 83, 95, 108};
8 |
9 | int target = 83;
10 |
11 | int left = 0;
12 | int right = numbers.length-1;
13 | int mid = (left + right)/2;
14 |
15 | int temp = numbers[mid];
16 | boolean find = false;
17 |
18 | while(left <= right) {
19 |
20 | if(target == temp) { //수를 찾은 경우
21 | find = true;
22 | break;
23 | }
24 | else if(target < temp) { // 찾으려는 수가 더 작은 경우
25 | right = mid-1;
26 |
27 | }
28 | else {
29 | left = mid+1;
30 | }
31 | mid = (left + right)/2;
32 | temp = numbers[mid];
33 | }
34 |
35 | if(find == true)
36 | {
37 | mid++;
38 | System.out.println("찾는 수는 " + mid + "번째 있습니다.");
39 | }
40 | else System.out.println("찾는 수가 없습니다.");
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Chapter8/src/ch03/InsertionSort.java:
--------------------------------------------------------------------------------
1 | package ch03;
2 |
3 | public class InsertionSort {
4 |
5 | public static void insertionSort(int[] arr, int count) {
6 |
7 | int i = 0, j = 0;
8 | int temp = 0;
9 |
10 | for(i = 1; i < count; i++) {
11 | temp = arr[i];
12 | j = i;
13 | while((j > 0) && arr[j-1] > temp) {
14 | arr[j] = arr[j-1];
15 | j = j - 1;
16 | }
17 | arr[j] = temp;
18 |
19 | System.out.println("반복 -" + i);
20 | printSort(arr, count);
21 | }
22 |
23 | }
24 |
25 | public static void printSort(int value[], int count)
26 | {
27 | int i = 0;
28 | for(i = 0; i < count; i++) {
29 | System.out.print(value[i] + "\t");
30 | }
31 | System.out.println();
32 | }
33 |
34 | public static void main(String[] args) {
35 |
36 | int[] arr = {80, 50, 70, 10, 60, 20, 40, 30 };
37 |
38 | insertionSort(arr, 8);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/Chapter8/src/ch04/bfs/BfsSearch.java:
--------------------------------------------------------------------------------
1 | package ch04.bfs;
2 |
3 | import java.util.ArrayList;
4 | import ch04.graph.UndirectedGraph;
5 |
6 | public class BfsSearch {
7 |
8 | int count;
9 | boolean[] visited;
10 | ArrayList queue;
11 | int[][] matrix;
12 |
13 | public BfsSearch(int count){
14 | this.count = count;
15 | visited = new boolean[count];
16 | queue = new ArrayList();
17 | }
18 |
19 | public void bfsTraversal() {
20 |
21 | queue.add(0);
22 | visited[0] = true;
23 |
24 | while(queue.size() != 0) {
25 | int node = queue.remove(0);
26 |
27 | System.out.print(node + " ");
28 |
29 | for(int j = 0; j stack;
12 | int[][] matrix;
13 |
14 | public DfsSearch(int count){
15 | this.count = count;
16 | visited = new boolean[count];
17 | stack = new Stack();
18 | }
19 |
20 | public void bfsTraversal() {
21 |
22 | stack.push(0);
23 | visited[0] = true;
24 |
25 | while(stack.size() != 0) {
26 | int node = stack.pop();
27 |
28 | System.out.print(node + " ");
29 |
30 | for(int j = 0; j stack = new Stack();
13 | Move Move;
14 | Maze maze = new Maze();
15 |
16 | public int[][] DIRECTION_OFFSETS =
17 | {
18 | {0, -1}, //
--------------------------------------------------------------------------------
/Chapter8/src/ch06/test/MazeTest.java:
--------------------------------------------------------------------------------
1 | package ch06.test;
2 |
3 | import ch06.maze.Maze;
4 | import ch06.maze.Robot;
5 |
6 |
7 | public class MazeTest {
8 |
9 | public static void main(String[] args) {
10 |
11 | Robot robot;
12 | System.out.println("異
--------------------------------------------------------------------------------
/Chapter8/src/ch07/Fibonacci.java:
--------------------------------------------------------------------------------
1 | package ch07;
2 |
3 | public class Fibonacci {
4 |
5 | int[] value;
6 | int number;
7 |
8 | public Fibonacci(int number) {
9 | this.number = number;
10 | value = new int[number];
11 | }
12 |
13 | public int fibonacciRecur(int n) {
14 |
15 |
16 | if (n == 0) return 0;
17 | if (n == 1) return 1;
18 |
19 | return fibonacciRecur(n - 1) + fibonacciRecur(n - 2);
20 | }
21 |
22 | public int fibonacciIter(int n) {
23 |
24 | int ppre = 0;
25 | int pre = 1;
26 | int current = 0;
27 |
28 | if (n == 0) return 0;
29 | if (n == 1) return 1;
30 |
31 | for (int i = 2; i <= n; i++) {
32 |
33 | current = ppre + pre;
34 | ppre = pre;
35 | pre = current;
36 | }
37 |
38 | return current;
39 | }
40 |
41 | public int fibonacciMem(int n) {
42 |
43 | value[0] = 0;
44 | value[1] = 1;
45 | int result = 0;
46 |
47 | if (n == 0) {
48 | return value[0];
49 | }
50 |
51 | if (n == 1) {
52 | return value[1];
53 | }
54 |
55 | for(int i = 2; i<=n; i++) {
56 |
57 | result = value[i-1] + value[i-2];
58 |
59 | if(value[i] == 0) {
60 | value[i] = result;
61 | }
62 |
63 | }
64 |
65 | return result;
66 | }
67 |
68 |
69 | public static void main(String[] args) {
70 |
71 | Fibonacci fib = new Fibonacci(100);
72 |
73 | int result = fib.fibonacciRecur(10);
74 | System.out.println(result);
75 |
76 | result = fib.fibonacciIter(10);
77 | System.out.println(result);
78 |
79 | result = fib.fibonacciMem(10);
80 | System.out.println(result);
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/Chapter8/src/ch08/GreedyTest.java:
--------------------------------------------------------------------------------
1 | package ch08;
2 |
3 | public class GreedyTest {
4 |
5 | public static void main(String[] args) {
6 |
7 | int[] coins = {500, 100, 50, 10}; //
8 | int price = 8370;
9 | int count;
10 |
11 | for (int i = 0; i< coins.length; i++) {
12 | count = 0;
13 | count += price / coins[i];
14 | price = price % coins[i];
15 |
16 | System.out.println( coins[i] + "吏
--------------------------------------------------------------------------------
/Chapter8/src/ch09/BruteForceSearch.java:
--------------------------------------------------------------------------------
1 | package ch09;
2 |
3 | public class BruteForceSearch {
4 |
5 | public static void main(String[] args) {
6 | int[] bills = { 1, 2, 5, 10, 20, 50 };
7 |
8 | int count = 0;
9 | int money = 100;
10 | int i0, i1, i2, i3, i4;
11 |
12 | for (i0 = money; i0 >= 0; i0 -= bills[0]) {
13 | for (i1 = i0; i1 >= 0; i1 -= bills[1]) {
14 | for (i2 = i1; i2 >= 0; i2 -= bills[2]) {
15 | for (i3 = i2; i3 >= 0; i3 -= bills[3]) {
16 | for (i4 = i3; i4 >= 0; i4 -= bills[4])
17 | if (i4 % bills[5] == 0)
18 | count++;
19 | }
20 | }
21 | }
22 | }
23 |
24 | System.out.println("吏
--------------------------------------------------------------------------------
/Chapter8/src/ch10/CountingProblem.java:
--------------------------------------------------------------------------------
1 | package ch10;
2 |
3 | public class CountingProblem {
4 |
5 | public static void main(String[] args) {
6 | int[] people = { 55, 40, 27, 99, 76, 81, 29, 31,33, 62};
7 | int[] ages = new int[10]; //
--------------------------------------------------------------------------------