Compare commits
52 Commits
b495294af3
...
v24.1219
| Author | SHA1 | Date | |
|---|---|---|---|
| 6719f1e7b2 | |||
| a21a66a542 | |||
| a3d1677a4c | |||
| 4ba14576e7 | |||
| fdaf7334c8 | |||
| 1de9754569 | |||
| 2852b5f178 | |||
| 01d80d8ad2 | |||
| c99f6f67b2 | |||
| 8aa6947e2b | |||
| 26fcbfbd91 | |||
| e4d146365b | |||
| 4d9579e13d | |||
| 5a4df5e6f3 | |||
| d1ec1423dd | |||
| c2923336e6 | |||
| 9e780a4f1b | |||
| f3cb1fe50d | |||
| 0d57276315 | |||
| c21520d8ee | |||
| c0479e5bba | |||
| 6da1f053fb | |||
| c977d365d8 | |||
| c26c27561c | |||
| 9c663672aa | |||
| 4d4a3beb6a | |||
| 78135ec799 | |||
| ff273fbcde | |||
| ce86998025 | |||
| f80521d4a5 | |||
| a6c121d9a1 | |||
| 886c549976 | |||
| 730e6a8592 | |||
| fe9964116e | |||
| 57e12cb859 | |||
| 66c059eb0f | |||
| 00a5c68f22 | |||
| 8f3a52c938 | |||
| e645d37dad | |||
| 02bb45886d | |||
| a86d757053 | |||
| 58ad0dd15a | |||
| cf6183c5b8 | |||
| 87f3d76415 | |||
| 761fcb4905 | |||
| 8737a64402 | |||
| a63465ac67 | |||
| c34ef6f2c2 | |||
| a3e84dc516 | |||
| 028ae17647 | |||
| 7c6c325b73 | |||
| 52b68a5706 |
@@ -7,5 +7,6 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="lib" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
BIN
lib/mysql-connector-java-8.0.11.jar
Executable file
BIN
lib/mysql-connector-java-8.0.11.jar
Executable file
Binary file not shown.
1
resources/chapter7/config/helper_3.c
Normal file
1
resources/chapter7/config/helper_3.c
Normal file
@@ -0,0 +1 @@
|
||||
#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\n
|
||||
1
resources/chapter7/config/interface_4.c
Normal file
1
resources/chapter7/config/interface_4.c
Normal file
@@ -0,0 +1 @@
|
||||
#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\n
|
||||
1
resources/chapter7/config/service_5.c
Normal file
1
resources/chapter7/config/service_5.c
Normal file
@@ -0,0 +1 @@
|
||||
#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\n
|
||||
1
resources/chapter7/config/test_2/docs_3/data_2.java
Normal file
1
resources/chapter7/config/test_2/docs_3/data_2.java
Normal file
@@ -0,0 +1 @@
|
||||
public class GeneratedClass {\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\n}\n
|
||||
1
resources/chapter7/config/test_2/docs_3/product_3.java
Normal file
1
resources/chapter7/config/test_2/docs_3/product_3.java
Normal file
@@ -0,0 +1 @@
|
||||
public class GeneratedClass {\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\n}\n
|
||||
1
resources/chapter7/config/test_2/docs_3/user_1.java
Normal file
1
resources/chapter7/config/test_2/docs_3/user_1.java
Normal file
@@ -0,0 +1 @@
|
||||
public class GeneratedClass {\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\n}\n
|
||||
1
resources/chapter7/config/utils_1.java
Normal file
1
resources/chapter7/config/utils_1.java
Normal file
@@ -0,0 +1 @@
|
||||
public class GeneratedClass {\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\n}\n
|
||||
1
resources/chapter7/create.sh
Normal file
1
resources/chapter7/create.sh
Normal file
@@ -0,0 +1 @@
|
||||
Hello World! This is a random content. Always write clean and maintainable code. Documentation is very important for any project. Always write clean and maintainable code. Software development is both an art and science. The C programming language is powerful and efficient. Testing is an essential part of development. This file was automatically generated. Always write clean and maintainable code. Hello World! This is a random content. Remember to add proper comments in your code. Documentation is very important for any project. Hello World! This is a random content. The C programming language is powerful and efficient. Software development is both an art and science. Documentation is very important for any project. Always write clean and maintainable code. Documentation is very important for any project. Testing is an essential part of development. Documentation is very important for any project. Documentation is very important for any project. Java is a popular programming language. This is a sample text for testing purposes. The C programming language is powerful and efficient. The C programming language is powerful and efficient. Testing is an essential part of development. Hello World! This is a random content. This is a sample text for testing purposes. Testing is an essential part of development. The C programming language is powerful and efficient. Testing is an essential part of development. Testing is an essential part of development. Hello World! This is a random content. Always write clean and maintainable code. This is a sample text for testing purposes. Software development is both an art and science. Hello World! This is a random content. Testing is an essential part of development. Java is a popular programming language. Remember to add proper comments in your code. Testing is an essential part of development. Always write clean and maintainable code. Software development is both an art and science. This file was automatically generated. Testing is an essential part of development. Always write clean and maintainable code. Remember to add proper comments in your code. Java is a popular programming language. Java is a popular programming language. Documentation is very important for any project. Always write clean and maintainable code. Testing is an essential part of development. This is a sample text for testing purposes. The C programming language is powerful and efficient. This file was automatically generated. Hello World! This is a random content. Java is a popular programming language. Always write clean and maintainable code. This file was automatically generated. The C programming language is powerful and efficient. Testing is an essential part of development. This is a sample text for testing purposes. Hello World! This is a random content. Testing is an essential part of development. Always write clean and maintainable code. Java is a popular programming language. This is a sample text for testing purposes. Hello World! This is a random content. Documentation is very important for any project. Documentation is very important for any project. This is a sample text for testing purposes. The C programming language is powerful and efficient. This is a sample text for testing purposes. Always write clean and maintainable code. The C programming language is powerful and efficient. Always write clean and maintainable code. This is a sample text for testing purposes. This is a sample text for testing purposes. Software development is both an art and science. Hello World! This is a random content. Remember to add proper comments in your code. Software development is both an art and science. Documentation is very important for any project. Testing is an essential part of development. This is a sample text for testing purposes. Testing is an essential part of development. Documentation is very important for any project. Java is a popular programming language. This file was automatically generated. Documentation is very important for any project. This file was automatically generated. Documentation is very important for any project. The C programming language is powerful and efficient. This is a sample text for testing purposes. This is a sample text for testing purposes. Documentation is very important for any project. Documentation is very important for any project. This is a sample text for testing purposes. Remember to add proper comments in your code. Documentation is very important for any project. Software development is both an art and science. This file was automatically generated.
|
||||
1
resources/chapter7/fill.sh
Normal file
1
resources/chapter7/fill.sh
Normal file
@@ -0,0 +1 @@
|
||||
The C programming language is powerful and efficient. This is a sample text for testing purposes. This is a sample text for testing purposes. Software development is both an art and science. This is a sample text for testing purposes. Hello World! This is a random content. Documentation is very important for any project. The C programming language is powerful and efficient. The C programming language is powerful and efficient. Software development is both an art and science. Hello World! This is a random content. This file was automatically generated. This is a sample text for testing purposes. Always write clean and maintainable code. Software development is both an art and science. This is a sample text for testing purposes. Documentation is very important for any project. Java is a popular programming language. Software development is both an art and science. Software development is both an art and science. Java is a popular programming language. Always write clean and maintainable code. Hello World! This is a random content. Testing is an essential part of development. The C programming language is powerful and efficient. This file was automatically generated. Java is a popular programming language. This file was automatically generated. Testing is an essential part of development. Hello World! This is a random content. Hello World! This is a random content. Remember to add proper comments in your code. Testing is an essential part of development. The C programming language is powerful and efficient. Documentation is very important for any project. Documentation is very important for any project. The C programming language is powerful and efficient. This is a sample text for testing purposes. Documentation is very important for any project. Remember to add proper comments in your code. Java is a popular programming language. The C programming language is powerful and efficient. Always write clean and maintainable code. This is a sample text for testing purposes. This file was automatically generated. Documentation is very important for any project. Remember to add proper comments in your code. Remember to add proper comments in your code. Remember to add proper comments in your code. Documentation is very important for any project. Remember to add proper comments in your code. Remember to add proper comments in your code. Always write clean and maintainable code. Java is a popular programming language. This file was automatically generated. This is a sample text for testing purposes. Software development is both an art and science. Hello World! This is a random content. Java is a popular programming language. Remember to add proper comments in your code. Documentation is very important for any project. Documentation is very important for any project. Always write clean and maintainable code. This is a sample text for testing purposes. Documentation is very important for any project. Documentation is very important for any project. Remember to add proper comments in your code. Testing is an essential part of development. The C programming language is powerful and efficient.
|
||||
@@ -0,0 +1 @@
|
||||
Remember to add proper comments in your code. Documentation is very important for any project. Hello World! This is a random content. Java is a popular programming language. Always write clean and maintainable code. Java is a popular programming language. This file was automatically generated. Software development is both an art and science. Always write clean and maintainable code. Remember to add proper comments in your code. The C programming language is powerful and efficient. Hello World! This is a random content. Documentation is very important for any project. This is a sample text for testing purposes. The C programming language is powerful and efficient. Java is a popular programming language. The C programming language is powerful and efficient. Software development is both an art and science. Software development is both an art and science. Remember to add proper comments in your code. Remember to add proper comments in your code. Testing is an essential part of development. Documentation is very important for any project. Java is a popular programming language. This file was automatically generated. This is a sample text for testing purposes. Always write clean and maintainable code. Testing is an essential part of development. This is a sample text for testing purposes. This file was automatically generated. This file was automatically generated. Always write clean and maintainable code. Software development is both an art and science. Always write clean and maintainable code. Hello World! This is a random content. The C programming language is powerful and efficient. Testing is an essential part of development. The C programming language is powerful and efficient. Hello World! This is a random content. Remember to add proper comments in your code. Java is a popular programming language. Hello World! This is a random content. Testing is an essential part of development. Java is a popular programming language. Software development is both an art and science. Always write clean and maintainable code. Hello World! This is a random content. Always write clean and maintainable code. Software development is both an art and science. Always write clean and maintainable code. Always write clean and maintainable code. This is a sample text for testing purposes. Documentation is very important for any project. Documentation is very important for any project. Remember to add proper comments in your code. Always write clean and maintainable code. Always write clean and maintainable code. This is a sample text for testing purposes. Always write clean and maintainable code. This file was automatically generated. Always write clean and maintainable code. Always write clean and maintainable code. Documentation is very important for any project. Testing is an essential part of development. Hello World! This is a random content. This file was automatically generated. Java is a popular programming language. Always write clean and maintainable code. Documentation is very important for any project. Java is a popular programming language. The C programming language is powerful and efficient. Hello World! This is a random content. Software development is both an art and science. Java is a popular programming language. Java is a popular programming language. This is a sample text for testing purposes. Software development is both an art and science. The C programming language is powerful and efficient. The C programming language is powerful and efficient. Testing is an essential part of development. Hello World! This is a random content. This is a sample text for testing purposes. Testing is an essential part of development. Documentation is very important for any project. Hello World! This is a random content. Documentation is very important for any project. Always write clean and maintainable code. Hello World! This is a random content. The C programming language is powerful and efficient. This is a sample text for testing purposes. This is a sample text for testing purposes. Always write clean and maintainable code. Always write clean and maintainable code. Java is a popular programming language. Testing is an essential part of development. The C programming language is powerful and efficient. This is a sample text for testing purposes. The C programming language is powerful and efficient. Hello World! This is a random content. This is a sample text for testing purposes. Documentation is very important for any project. Software development is both an art and science. The C programming language is powerful and efficient. This file was automatically generated. Java is a popular programming language. Documentation is very important for any project. Remember to add proper comments in your code. This is a sample text for testing purposes. Testing is an essential part of development. Testing is an essential part of development.
|
||||
1
resources/chapter7/models/config_2/config_3/user_2.java
Normal file
1
resources/chapter7/models/config_2/config_3/user_2.java
Normal file
@@ -0,0 +1 @@
|
||||
public class GeneratedClass {\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\n}\n
|
||||
@@ -0,0 +1 @@
|
||||
public class GeneratedClass {\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\n}\n
|
||||
@@ -0,0 +1 @@
|
||||
#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\n
|
||||
1
resources/chapter7/models/source_2/services_3/data_4.c
Normal file
1
resources/chapter7/models/source_2/services_3/data_4.c
Normal file
@@ -0,0 +1 @@
|
||||
#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\n
|
||||
@@ -0,0 +1 @@
|
||||
This file was automatically generated. This file was automatically generated. Remember to add proper comments in your code. Software development is both an art and science. The C programming language is powerful and efficient. Testing is an essential part of development. Java is a popular programming language. Hello World! This is a random content. Software development is both an art and science. Software development is both an art and science. Remember to add proper comments in your code. Testing is an essential part of development. This is a sample text for testing purposes. Documentation is very important for any project. Documentation is very important for any project. Testing is an essential part of development. Java is a popular programming language. This file was automatically generated. Software development is both an art and science. Always write clean and maintainable code. Always write clean and maintainable code. The C programming language is powerful and efficient. Hello World! This is a random content. Documentation is very important for any project. Documentation is very important for any project. This file was automatically generated. This file was automatically generated. Java is a popular programming language. Always write clean and maintainable code. Testing is an essential part of development. The C programming language is powerful and efficient. Java is a popular programming language. Always write clean and maintainable code. Testing is an essential part of development. Documentation is very important for any project. Software development is both an art and science. This is a sample text for testing purposes. This file was automatically generated. The C programming language is powerful and efficient. Remember to add proper comments in your code. The C programming language is powerful and efficient. Java is a popular programming language. Remember to add proper comments in your code.
|
||||
1
resources/chapter7/models/source_2/services_3/user_2.c
Normal file
1
resources/chapter7/models/source_2/services_3/user_2.c
Normal file
@@ -0,0 +1 @@
|
||||
#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\n
|
||||
1
resources/chapter7/resources_2/resources_3/config_2.c
Normal file
1
resources/chapter7/resources_2/resources_3/config_2.c
Normal file
@@ -0,0 +1 @@
|
||||
#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\n
|
||||
@@ -0,0 +1 @@
|
||||
This file was automatically generated. This is a sample text for testing purposes. Remember to add proper comments in your code. This is a sample text for testing purposes. Always write clean and maintainable code. This is a sample text for testing purposes. Software development is both an art and science. This file was automatically generated. Testing is an essential part of development. Java is a popular programming language. This file was automatically generated. Remember to add proper comments in your code. The C programming language is powerful and efficient. Java is a popular programming language. Always write clean and maintainable code. This file was automatically generated. Documentation is very important for any project. The C programming language is powerful and efficient. Testing is an essential part of development. Always write clean and maintainable code. The C programming language is powerful and efficient. Always write clean and maintainable code. This is a sample text for testing purposes. Always write clean and maintainable code. Java is a popular programming language. Remember to add proper comments in your code. Remember to add proper comments in your code. Software development is both an art and science. This file was automatically generated. Documentation is very important for any project. The C programming language is powerful and efficient. Hello World! This is a random content. Software development is both an art and science. Documentation is very important for any project. Always write clean and maintainable code. Remember to add proper comments in your code. Hello World! This is a random content. Hello World! This is a random content. Testing is an essential part of development. Java is a popular programming language. Remember to add proper comments in your code. The C programming language is powerful and efficient. Testing is an essential part of development. This is a sample text for testing purposes. Testing is an essential part of development. Hello World! This is a random content. Documentation is very important for any project. Documentation is very important for any project. The C programming language is powerful and efficient. The C programming language is powerful and efficient. This file was automatically generated. Hello World! This is a random content. Documentation is very important for any project. Software development is both an art and science. Remember to add proper comments in your code. Software development is both an art and science. This is a sample text for testing purposes. Remember to add proper comments in your code. Always write clean and maintainable code. Software development is both an art and science. Java is a popular programming language. Remember to add proper comments in your code. Remember to add proper comments in your code. This file was automatically generated. Java is a popular programming language. This is a sample text for testing purposes. Testing is an essential part of development. This file was automatically generated. Hello World! This is a random content. Remember to add proper comments in your code. Hello World! This is a random content. Hello World! This is a random content. This file was automatically generated. This is a sample text for testing purposes. Always write clean and maintainable code. This file was automatically generated. This file was automatically generated. Hello World! This is a random content. Testing is an essential part of development. Software development is both an art and science. Always write clean and maintainable code. Remember to add proper comments in your code. Hello World! This is a random content. Hello World! This is a random content. Software development is both an art and science. Hello World! This is a random content. Testing is an essential part of development. This is a sample text for testing purposes. Software development is both an art and science. Software development is both an art and science. Remember to add proper comments in your code. Hello World! This is a random content. Always write clean and maintainable code. Testing is an essential part of development. Java is a popular programming language. The C programming language is powerful and efficient. Documentation is very important for any project. Hello World! This is a random content. This file was automatically generated. Software development is both an art and science. Always write clean and maintainable code. The C programming language is powerful and efficient. The C programming language is powerful and efficient. Testing is an essential part of development. Hello World! This is a random content. Java is a popular programming language. Software development is both an art and science. Testing is an essential part of development. Remember to add proper comments in your code. The C programming language is powerful and efficient. Java is a popular programming language. Testing is an essential part of development.
|
||||
@@ -0,0 +1 @@
|
||||
This file was automatically generated. Remember to add proper comments in your code. Hello World! This is a random content. Remember to add proper comments in your code. Remember to add proper comments in your code. This is a sample text for testing purposes. Hello World! This is a random content. Testing is an essential part of development. Always write clean and maintainable code. Testing is an essential part of development. Java is a popular programming language. This is a sample text for testing purposes. This file was automatically generated. The C programming language is powerful and efficient. Software development is both an art and science. This is a sample text for testing purposes. This is a sample text for testing purposes. Always write clean and maintainable code. Testing is an essential part of development. This is a sample text for testing purposes. Always write clean and maintainable code. The C programming language is powerful and efficient. Remember to add proper comments in your code. Java is a popular programming language. Hello World! This is a random content. This file was automatically generated. Always write clean and maintainable code. Always write clean and maintainable code. Documentation is very important for any project. This file was automatically generated. The C programming language is powerful and efficient. Software development is both an art and science. Testing is an essential part of development. Always write clean and maintainable code. Hello World! This is a random content. The C programming language is powerful and efficient. Always write clean and maintainable code. Software development is both an art and science. Remember to add proper comments in your code. Remember to add proper comments in your code. Hello World! This is a random content. Testing is an essential part of development. Documentation is very important for any project. Testing is an essential part of development. Always write clean and maintainable code. This is a sample text for testing purposes. This is a sample text for testing purposes. Software development is both an art and science. Documentation is very important for any project. Software development is both an art and science. Java is a popular programming language. Always write clean and maintainable code. The C programming language is powerful and efficient. This is a sample text for testing purposes.
|
||||
1
resources/chapter7/resources_2/resources_3/user_3.c
Normal file
1
resources/chapter7/resources_2/resources_3/user_3.c
Normal file
@@ -0,0 +1 @@
|
||||
#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\n
|
||||
1
resources/chapter7/service_2.c
Normal file
1
resources/chapter7/service_2.c
Normal file
@@ -0,0 +1 @@
|
||||
#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\n
|
||||
46
src/chapter10/Example01.java
Normal file
46
src/chapter10/Example01.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package chapter10;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.sql.DriverManager;
|
||||
|
||||
public class Example01 {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// 1. 加载驱动
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
|
||||
// 2. 准备连接参数
|
||||
String url = "jdbc:mysql://localhost:3306/school?characterEncoding=utf-8&useSSL=false&serverTimezone=UTC";
|
||||
String username = "root";
|
||||
String password = "root";
|
||||
|
||||
// 使用try-with-resources自动关闭资源
|
||||
try (
|
||||
// 创建连接
|
||||
Connection connection = DriverManager.getConnection(url, username, password);
|
||||
// 创建语句对象
|
||||
Statement statement = connection.createStatement();
|
||||
// 执行查询获取结果集
|
||||
ResultSet resultSet = statement.executeQuery("select * from student")
|
||||
) {
|
||||
// 处理结果集
|
||||
while (resultSet.next()) {
|
||||
int id = resultSet.getInt("id");
|
||||
String name = resultSet.getString("name");
|
||||
int age = resultSet.getInt("age");
|
||||
String gender = resultSet.getString("gender");
|
||||
String className = resultSet.getString("class");
|
||||
|
||||
System.out.println("id=" + id + ", name=" + name + ", age=" + age +
|
||||
", gender=" + gender + ", className=" + className);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
37
src/chapter10/Example02.java
Normal file
37
src/chapter10/Example02.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package chapter10;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Statement;
|
||||
import java.sql.DriverManager;
|
||||
|
||||
public class Example02 {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// 1. 加载驱动
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
|
||||
// 2. 准备连接参数
|
||||
String url = "jdbc:mysql://localhost:3306/school?characterEncoding=utf-8&useSSL=false&serverTimezone=UTC";
|
||||
String username = "root";
|
||||
String password = "root";
|
||||
|
||||
// 使用try-with-resources自动关闭资源
|
||||
try (
|
||||
Connection connection = DriverManager.getConnection(url, username, password);
|
||||
Statement statement = connection.createStatement()
|
||||
) {
|
||||
// 准备INSERT语句
|
||||
String sql = "INSERT INTO student (name, age, gender, class, score) " +
|
||||
"VALUES ('小张', 19, 'M', '计算机1班', 88.5)";
|
||||
|
||||
// 执行INSERT语句
|
||||
int rows = statement.executeUpdate(sql);
|
||||
|
||||
// 输出受影响的行数
|
||||
System.out.println("成功插入 " + rows + " 条数据");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
32
src/chapter2/ClassScoreAnalyzer.java
Normal file
32
src/chapter2/ClassScoreAnalyzer.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package chapter2;
|
||||
|
||||
public class ClassScoreAnalyzer {
|
||||
public static void main(String[] args) {
|
||||
// 1. 创建并初始化数组
|
||||
int[] testScores = {85, 92, 78, 95, 88};
|
||||
|
||||
// 2. 使用循环打印所有学生的成绩
|
||||
for (int i = 0; i < testScores.length; i++) {
|
||||
System.out.println("学生" + (i + 1) + "的成绩:" + testScores[i]);
|
||||
}
|
||||
|
||||
// 4. 调用 findHighestScore 方法并打印结果
|
||||
int highestScore = findHighestScore(testScores);
|
||||
System.out.println("班级最高分是:" + highestScore);
|
||||
}
|
||||
|
||||
// 3. 编写 findHighestScore 方法
|
||||
public static int findHighestScore(int[] scores) {
|
||||
if (scores == null || scores.length == 0) {
|
||||
return -1; // 返回-1表示数组为空或null
|
||||
}
|
||||
|
||||
int max = scores[0]; // 假设第一个元素是最大的
|
||||
for (int i = 1; i < scores.length; i++) {
|
||||
if (scores[i] > max) {
|
||||
max = scores[i];
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
package chapter2;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Department {
|
||||
@@ -1,3 +1,5 @@
|
||||
package chapter2;
|
||||
|
||||
public class Example07 {
|
||||
public static void main(String[] args) {
|
||||
int x = 5;
|
||||
@@ -1,3 +1,5 @@
|
||||
package chapter2;
|
||||
|
||||
public class Example08 {
|
||||
public static void main(String[] args) {
|
||||
int num = 20;
|
||||
@@ -1,3 +1,5 @@
|
||||
package chapter2;
|
||||
|
||||
public class Example09 {
|
||||
public static void main(String[] args) {
|
||||
int grade = 75;
|
||||
@@ -1,3 +1,5 @@
|
||||
package chapter2;
|
||||
|
||||
public class Example10 {
|
||||
public static void main(String[] args) {
|
||||
int x = 0;
|
||||
@@ -1,3 +1,5 @@
|
||||
package chapter2;
|
||||
|
||||
public class Example11 {
|
||||
public static void main(String[] args) {
|
||||
int week = 1;
|
||||
@@ -1,3 +1,5 @@
|
||||
package chapter2;
|
||||
|
||||
public class Example12 {
|
||||
public static void main(String[] args) {
|
||||
int x = 5; // 定义变量x,初始值为1
|
||||
@@ -1,3 +1,5 @@
|
||||
package chapter2;
|
||||
|
||||
public class Example13 {
|
||||
public static void main(String[] args) {
|
||||
int x = 5;
|
||||
@@ -1,3 +1,5 @@
|
||||
package chapter2;
|
||||
|
||||
public class Example14 {
|
||||
public static void main(String[] args) {
|
||||
int sum = 0;
|
||||
@@ -1,10 +1,12 @@
|
||||
package chapter2;
|
||||
|
||||
public class Example16 {
|
||||
public static void main(String[] args) {
|
||||
int x = 1;
|
||||
while (x <= 4) {
|
||||
System.out.println("x = " + x);
|
||||
if (x == 3) {
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
x ++;
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
package chapter2;
|
||||
|
||||
public class Example17 {
|
||||
public static void main(String[] args) {
|
||||
int x = 1;
|
||||
@@ -1,6 +1,8 @@
|
||||
package chapter2;
|
||||
|
||||
public class Example19 {
|
||||
public static void main(String[] args) {
|
||||
printRectangle(3, 40);
|
||||
printRectangle(3, 5);
|
||||
}
|
||||
|
||||
// 下面定义了一个打印矩形的方法,接收两个参数,其中height为高,width为宽
|
||||
@@ -8,10 +10,8 @@ public class Example19 {
|
||||
// 下面是使用嵌套for循环实现*打印矩形
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++) {
|
||||
System.out.print("*");
|
||||
|
||||
}
|
||||
// System.out.print("\n");
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
}
|
||||
13
src/chapter2/Example20.java
Normal file
13
src/chapter2/Example20.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package chapter2;
|
||||
|
||||
public class Example20 {
|
||||
public static void main(String[] args) {
|
||||
int area = getArea(3, 5);
|
||||
System.out.println("The area is " + area);
|
||||
}
|
||||
|
||||
public static int getArea(int x, int y) {
|
||||
int temp = x * y;
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
29
src/chapter2/Example21.java
Normal file
29
src/chapter2/Example21.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package chapter2;
|
||||
|
||||
public class Example21 {
|
||||
public static void main(String[] args) {
|
||||
// 下面针对求和方法的调用
|
||||
int sum1 = add(1, 2);
|
||||
int sum2 = add(2, 2, 3);
|
||||
double sum3 = add(1.2, 2.3);
|
||||
// 下面的代码是打印求和的结果
|
||||
System.out.println("sum1 = " + sum1);
|
||||
System.out.println("sum2 = " + sum2);
|
||||
System.out.println("sum3 = " + sum3);
|
||||
}
|
||||
|
||||
// 下面的方法实现了两个整数相加
|
||||
public static int add(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
// 下面的方法实现了三个整数相加
|
||||
public static int add(int a, int b, int c) {
|
||||
return a + b + c;
|
||||
}
|
||||
|
||||
// 下面的方法实现了两个小数相加
|
||||
public static double add(double a, double b) {
|
||||
return a + b;
|
||||
}
|
||||
}
|
||||
15
src/chapter2/Example22.java
Normal file
15
src/chapter2/Example22.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package chapter2;
|
||||
|
||||
public class Example22 {
|
||||
public static void main(String[] args) {
|
||||
int[] arr; // 声明变量
|
||||
arr = new int[3]; // 创建数据对象
|
||||
|
||||
System.out.println("arr[0] = " + arr[0]); // 访问数组中的第一个元素
|
||||
System.out.println("arr[1] = " + arr[1]); // 访问数组中的第二个元素
|
||||
System.out.println("arr[2] = " + arr[2]); // 访问数组中的第三个元素
|
||||
|
||||
System.out.println("数组的长度是:" + arr.length); // 打印数组的长度
|
||||
|
||||
}
|
||||
}
|
||||
14
src/chapter2/Example23.java
Normal file
14
src/chapter2/Example23.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package chapter2;
|
||||
|
||||
public class Example23 {
|
||||
public static void main(String[] args) {
|
||||
int[] arr = new int[4]; // 定义可以存储4个元素的整数类型数组
|
||||
arr[0] = 1; // 为第1个元素赋值1
|
||||
arr[1] = 1; // 为第2个元素赋值2
|
||||
//依次打印数组中每个元素的值
|
||||
System.out.println("arr[0]: " + arr[0]);
|
||||
System.out.println("arr[1]: " + arr[1]);
|
||||
System.out.println("arr[2]: " + arr[2]);
|
||||
System.out.println("arr[3]: " + arr[3]);
|
||||
}
|
||||
}
|
||||
7
src/chapter2/GetMax.java
Normal file
7
src/chapter2/GetMax.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package chapter2;
|
||||
|
||||
public class GetMax {
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
package chapter2;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class SuperMarket {
|
||||
@@ -29,26 +31,23 @@ public class SuperMarket {
|
||||
int cupnumber = sc1.nextInt();
|
||||
double cupnum = cupnumber * cup;
|
||||
System.out.println("你购买了水杯" + cupnumber + "个,需要花费" + cupnum + "元");
|
||||
System.out.println("需要继续购买请输入Y,否则输入N");
|
||||
continueShopping = sc1.next();
|
||||
break;
|
||||
case 2:
|
||||
System.out.println("请输入你需要购买苹果的数量:");
|
||||
int applenumber = sc1.nextInt();
|
||||
double applenum = applenumber * apple;
|
||||
System.out.println("你购买了苹果" + applenumber + "斤,需要花费" + applenum + "元");
|
||||
System.out.println("需要继续购买请输入Y,否则输入N");
|
||||
continueShopping = sc1.next();
|
||||
break;
|
||||
case 3:
|
||||
System.out.println("请输入你需要购买香蕉的数量:");
|
||||
int banananumber = sc1.nextInt();
|
||||
double banananum = banananumber * banana;
|
||||
System.out.println("你购买了香蕉" + banananumber + "斤,需要花费" + banananum + "元");
|
||||
System.out.println("需要继续购买请输入Y,否则输入N");
|
||||
continueShopping = sc1.next();
|
||||
break;
|
||||
}
|
||||
|
||||
System.out.println("需要继续购买请输入Y,否则输入N");
|
||||
continueShopping = sc1.next();
|
||||
}
|
||||
|
||||
System.out.println("期待您的下次光临!");
|
||||
122
src/chapter2/User.java
Normal file
122
src/chapter2/User.java
Normal file
@@ -0,0 +1,122 @@
|
||||
package chapter2;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class User {
|
||||
// 存储用户名和密码
|
||||
// 两个数组前加上static属性,这样做是为了让本类都可以使用到这两个数组
|
||||
static String[] usernames = new String[10];
|
||||
static String[] passwords = new String[10];
|
||||
|
||||
static int count = 1;
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 假设系统中已经有一个用户
|
||||
usernames[0] = "java";
|
||||
passwords[0] = "123456";
|
||||
|
||||
while (true) {
|
||||
print();
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.println("请选择功能:");
|
||||
int option = input.nextInt();
|
||||
switch (option) {
|
||||
case 0:
|
||||
System.exit(0);
|
||||
case 1:
|
||||
login();
|
||||
break;
|
||||
case 2:
|
||||
register();
|
||||
break;
|
||||
case 3:
|
||||
show();
|
||||
break;
|
||||
default:
|
||||
System.out.println("输入错误!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 登录功能,键盘输入用户名与密码
|
||||
* 使用for循环加if判断验证输入的用户名与密码是否正确
|
||||
*/
|
||||
public static void login() {
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
System.out.println("请输入用户名:");
|
||||
String username = input.next();
|
||||
|
||||
System.out.println("请输入密码:");
|
||||
String password = input.next();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (username.equals(usernames[i]) && password.equals(passwords[i])) {
|
||||
System.out.println("登录成功!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("登录失败,请重新输入");
|
||||
}
|
||||
|
||||
/*
|
||||
* 注册功能
|
||||
* 定义一个boolean变量,使用for循序判断用户是否存在
|
||||
* 如果用户不存在,在数组中插入注册的账号密码时
|
||||
* 可能会有数组长度不够的情况,所以需要使用到
|
||||
* 增加数组的长度,这里调用增加数组长度的方法add()。
|
||||
*/
|
||||
public static void register() {
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
System.out.println("请输入用户名:");
|
||||
String username = input.next();
|
||||
|
||||
System.out.println("请输入密码:");
|
||||
String password = input.next();
|
||||
|
||||
boolean flag = true;
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (username.equals(usernames[i])) {
|
||||
System.out.println("用户名已存在");
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (flag) {
|
||||
if (count < usernames.length) {
|
||||
count++;
|
||||
usernames[count - 1] = username;
|
||||
passwords[count - 1] = password;
|
||||
System.out.println("注册成功!");
|
||||
} else {
|
||||
System.out.println("数组空间不足!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 查看功能
|
||||
*/
|
||||
public static void show() {
|
||||
for (int i = 0; i < count; i++) {
|
||||
System.out.println("用户名:" + usernames[i] + ",密码:" + passwords[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 打印功能菜单
|
||||
*/
|
||||
public static void print() {
|
||||
System.out.println("-----------------用户管理系统-------------------");
|
||||
System.out.println("1.登录功能");
|
||||
System.out.println("2.注册功能");
|
||||
System.out.println("3.查看");
|
||||
System.out.println("0.退出");
|
||||
System.out.println("-----------------用户管理系统-------------------");
|
||||
}
|
||||
}
|
||||
37
src/chapter3/Example01.java
Normal file
37
src/chapter3/Example01.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package chapter3;
|
||||
|
||||
//class Student {
|
||||
// String name;
|
||||
// int age;
|
||||
// String sex;
|
||||
//
|
||||
// void read() {
|
||||
// System.out.println("大家好,我是" + name + ",我在看书!");
|
||||
// }
|
||||
//
|
||||
// void introduce() {
|
||||
// System.out.println("大家好,我叫" + name + ",我今年" + age + "岁了,我是" + sex + "孩");
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//public class Example01 {
|
||||
// public static void main(String[] args) {
|
||||
// Student s1 = new Student();
|
||||
// Student s2 = new Student();
|
||||
//
|
||||
// s1.name = "小明";
|
||||
// s1.sex = "男";
|
||||
// s1.age = 20;
|
||||
//
|
||||
//
|
||||
// s2.name = "小红";
|
||||
// s2.sex = "女";
|
||||
// s2.age = 19;
|
||||
//
|
||||
// s1.read();
|
||||
// s2.read();
|
||||
//
|
||||
// s1.introduce();
|
||||
// s2.introduce();
|
||||
// }
|
||||
//}
|
||||
63
src/chapter3/Example05.java
Normal file
63
src/chapter3/Example05.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package chapter3;
|
||||
|
||||
class Book {
|
||||
int id; // 编号
|
||||
String name; // 书名
|
||||
|
||||
// public Book() {
|
||||
// this.id = 0;
|
||||
// this.name = "未命名";
|
||||
// System.out.println("初始化:无参构造被调用!");
|
||||
// }
|
||||
|
||||
// public Book(int id, String name) {
|
||||
// this.id = id;
|
||||
// }
|
||||
|
||||
// 打印信息
|
||||
public void print() {
|
||||
System.out.println("print函数 - ID:" + this.id + ",书名:" + this.name);
|
||||
}
|
||||
|
||||
// 获取书号
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
// 设置书号
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
// 获取书名
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
// 设置书名
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Book[] books = new Book[10];
|
||||
|
||||
// 使用 setter 初始化
|
||||
books[0] = new Book();
|
||||
books[0].print();
|
||||
System.out.println("初始化:手动");
|
||||
books[0].setId(1);
|
||||
books[0].setName("Java教程");
|
||||
books[0].print();
|
||||
|
||||
System.out.println("============");
|
||||
|
||||
// 直接访问属性进行初始化(注意访问控制)
|
||||
books[1] = new Book();
|
||||
books[1].print();
|
||||
System.out.println("初始化:手动");
|
||||
books[1].id = 2;
|
||||
books[1].name = "JSP教程";
|
||||
books[1].print();
|
||||
}
|
||||
}
|
||||
22
src/chapter3/Example09.java
Normal file
22
src/chapter3/Example09.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package chapter3;
|
||||
|
||||
class Student {
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
public Student(String name, int age) {
|
||||
name = name;
|
||||
age = age;
|
||||
}
|
||||
|
||||
public void read() {
|
||||
System.out.println("我是" + name + ",我今年" + age + "岁");
|
||||
}
|
||||
}
|
||||
|
||||
public class Example09 {
|
||||
public static void main(String[] args) {
|
||||
Student stu = new Student("小明", 15);
|
||||
stu.read();
|
||||
}
|
||||
}
|
||||
48
src/chapter3/Example14.java
Normal file
48
src/chapter3/Example14.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package chapter3;
|
||||
|
||||
/**
|
||||
* 静态属性示例:
|
||||
* 改变一个对象的静态属性,所有同类的其他对象,其静态属性会同时改变
|
||||
* 即静态属性被所有同类对象共享
|
||||
* 通过 类名.静态属性名 可以访问该属性
|
||||
*/
|
||||
|
||||
// Student 类
|
||||
class Student14 {
|
||||
String name;
|
||||
int age;
|
||||
static String school = "A大学";
|
||||
public Student14(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public void info() {
|
||||
System.out.println("姓名:" + this.name + ",年龄:" + this.age + ",学校:" + school);
|
||||
}
|
||||
}
|
||||
|
||||
// 为了安放 main 方法
|
||||
public class Example14 {
|
||||
public static void main(String[] args) {
|
||||
Student14 stu1 = new Student14("张三", 18);
|
||||
Student14 stu2 = new Student14("李四", 19);
|
||||
Student14 stu3 = new Student14("王五", 20);
|
||||
|
||||
stu1.info();
|
||||
stu2.info();
|
||||
stu3.info();
|
||||
|
||||
stu1.school = "B大学";
|
||||
stu1.info();
|
||||
stu2.info();
|
||||
stu3.info();
|
||||
|
||||
Student14.school = "C大学";
|
||||
stu1.info();
|
||||
stu2.info();
|
||||
stu3.info();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
36
src/chapter3/demo31/Book.java
Normal file
36
src/chapter3/demo31/Book.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package chapter3.demo31;
|
||||
|
||||
public class Book {
|
||||
private final int id; // 编号
|
||||
private final String name; // 书名
|
||||
private final double price; // 价格
|
||||
private final int storage; // 库存
|
||||
|
||||
// 有参构造
|
||||
public Book(int id, String name, double price, int storage) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.price = price;
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
// 获取书号
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
// 获取书名
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
// 获取价格
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
// 获取库存
|
||||
public int getStorage() {
|
||||
return storage;
|
||||
}
|
||||
}
|
||||
43
src/chapter3/demo31/Order.java
Normal file
43
src/chapter3/demo31/Order.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package chapter3.demo31;
|
||||
|
||||
public class Order {
|
||||
private final String orderId;
|
||||
private final OrderItem[] items;
|
||||
private double total;
|
||||
|
||||
// 有参构造
|
||||
public Order(String orderId) {
|
||||
this.orderId = orderId;
|
||||
this.items = new OrderItem[3];
|
||||
}
|
||||
|
||||
// 获取订单号
|
||||
public String getOrderId() {
|
||||
return orderId;
|
||||
}
|
||||
|
||||
// 获取订单列表
|
||||
public OrderItem[] getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
// 获取订单总额
|
||||
public double getTotal() {
|
||||
calTotal();
|
||||
return total;
|
||||
}
|
||||
|
||||
// 指定一个订单项
|
||||
public void setItem(OrderItem item, int i) {
|
||||
this.items[i] = item;
|
||||
}
|
||||
|
||||
// 计算订单总额
|
||||
public void calTotal() {
|
||||
double total = 0;
|
||||
for (OrderItem item : items) {
|
||||
total += item.getNum() * item.getBook().getPrice();
|
||||
}
|
||||
this.total = total;
|
||||
}
|
||||
}
|
||||
22
src/chapter3/demo31/OrderItem.java
Normal file
22
src/chapter3/demo31/OrderItem.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package chapter3.demo31;
|
||||
|
||||
public class OrderItem {
|
||||
private final Book book;
|
||||
private final int num;
|
||||
|
||||
// 有参构造方法
|
||||
public OrderItem(Book book, int num) {
|
||||
this.book = book;
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
// 获取图书对象
|
||||
public Book getBook() {
|
||||
return book;
|
||||
}
|
||||
|
||||
// 获取订购图书数量
|
||||
public int getNum() {
|
||||
return num;
|
||||
}
|
||||
}
|
||||
64
src/chapter3/demo31/PayBooks.java
Normal file
64
src/chapter3/demo31/PayBooks.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package chapter3.demo31;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class PayBooks {
|
||||
public static void main(String[] args) {
|
||||
Book[] books = new Book[3];
|
||||
// 模拟从数据库中读取图书信息并输出
|
||||
outBooks(books);
|
||||
// 顾客购买图书
|
||||
Order order = purchase(books);
|
||||
// 输出订单信息
|
||||
outOrder(order);
|
||||
}
|
||||
|
||||
// 顾客购买图书
|
||||
public static Order purchase(Book[] books) {
|
||||
Order order = new Order("00001");
|
||||
OrderItem item = null;
|
||||
Scanner in = new Scanner(System.in);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
System.out.println("请输入图书编号选择图书:");
|
||||
int cno = in.nextInt();
|
||||
System.out.println("请输入购买图书数量:");
|
||||
int pnum = in.nextInt();
|
||||
item = new OrderItem(books[cno - 1], pnum);
|
||||
order.setItem(item, i);
|
||||
System.out.println("请继续购买图书。");
|
||||
}
|
||||
in.close();
|
||||
return order;
|
||||
}
|
||||
|
||||
// 输出订单信息
|
||||
public static void outOrder(Order order) {
|
||||
System.out.println("\n===================图书订单===================");
|
||||
System.out.println("图书订单号:" + order.getOrderId());
|
||||
System.out.println("图书名称\t购买数量\t图书单价");
|
||||
System.out.println("--------------------------------------");
|
||||
OrderItem[] items = order.getItems();
|
||||
for (OrderItem item : items) {
|
||||
System.out.println(
|
||||
item.getBook().getName() + "\t" + item.getNum() + "\t" + item.getBook().getPrice());
|
||||
}
|
||||
System.out.println("---------------------------------------");
|
||||
System.out.println("订单总额:\t\t" + order.getTotal());
|
||||
}
|
||||
|
||||
// 模拟从数据库中读取图书信息并输出
|
||||
public static void outBooks(Book[] books) {
|
||||
books[0] = new Book(1, "Java教程", 30.6, 30);
|
||||
books[1] = new Book(2, "JSP教程", 42.1, 40);
|
||||
books[2] = new Book(3, "SSH架构", 47.3, 15);
|
||||
System.out.println("===================图书列表===================");
|
||||
System.out.println("图书编号\t图书名称\t\t图书单价\t库存数量");
|
||||
System.out.println("---------------------------------------");
|
||||
for (int i = 0; i < books.length; i++) {
|
||||
System.out.println(
|
||||
i + 1 + "\t" + books[i].getName() + "\t" + books[i].getPrice() + "\t" + books[i].getStorage());
|
||||
}
|
||||
System.out.println("---------------------------------------");
|
||||
}
|
||||
}
|
||||
16
src/chapter3/demo34/Main.java
Normal file
16
src/chapter3/demo34/Main.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package chapter3.demo34;
|
||||
|
||||
/**
|
||||
* Main类,程序的入口点
|
||||
*/
|
||||
public class Main {
|
||||
/**
|
||||
* 主方法
|
||||
* @param args 命令行参数
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// 创建VotingSystem对象并开始投票
|
||||
VotingSystem votingSystem = new VotingSystem();
|
||||
votingSystem.startVoting();
|
||||
}
|
||||
}
|
||||
95
src/chapter3/demo34/Voter.java
Normal file
95
src/chapter3/demo34/Voter.java
Normal file
@@ -0,0 +1,95 @@
|
||||
package chapter3.demo34;
|
||||
|
||||
/**
|
||||
* Voter类代表一个投票者
|
||||
*/
|
||||
public class Voter {
|
||||
// 最大投票人数
|
||||
private static final int MAX_COUNT = 50;
|
||||
// 当前投票人数
|
||||
private static int count = 0;
|
||||
// 存储所有投票者的数组
|
||||
private static Voter[] voters = new Voter[MAX_COUNT];
|
||||
|
||||
// 投票者姓名
|
||||
private String name;
|
||||
// 投票意见(true表示赞同,false表示反对)
|
||||
private boolean opinion;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @param name 投票者姓名
|
||||
*/
|
||||
public Voter(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 投票方法
|
||||
* @param opinion 投票意见
|
||||
*/
|
||||
public void vote(boolean opinion) {
|
||||
// 检查是否达到最大投票人数
|
||||
if (count >= MAX_COUNT) {
|
||||
System.out.println("投票已结束,已达到最大投票数。");
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查是否重复投票
|
||||
if (hasVoted(this.name)) {
|
||||
System.out.println(name + ",请勿重复投票。");
|
||||
return;
|
||||
}
|
||||
|
||||
// 记录投票意见
|
||||
this.opinion = opinion;
|
||||
voters[count] = this;
|
||||
count++;
|
||||
System.out.println(name + ",感谢您的投票。");
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查指定姓名的人是否已经投票
|
||||
* @param name 要检查的姓名
|
||||
* @return 如果已投票返回true,否则返回false
|
||||
*/
|
||||
private static boolean hasVoted(String name) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (voters[i].name.equals(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印投票结果
|
||||
*/
|
||||
public static void printResults() {
|
||||
System.out.println("===========投票结果===========");
|
||||
System.out.println("总投票数:" + count);
|
||||
int agreeCount = 0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
System.out.println(voters[i].name + " 的意见:" + (voters[i].opinion ? "赞同" : "反对"));
|
||||
if (voters[i].opinion) {
|
||||
agreeCount++;
|
||||
}
|
||||
}
|
||||
System.out.println("赞同人数:" + agreeCount);
|
||||
System.out.println("反对人数:" + (count - agreeCount));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取投票者姓名
|
||||
* @return 投票者姓名
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
// 静态初始化块,在类加载时执行
|
||||
static {
|
||||
System.out.println("Voter类已加载,准备开始投票。");
|
||||
}
|
||||
}
|
||||
|
||||
44
src/chapter3/demo34/VotingSystem.java
Normal file
44
src/chapter3/demo34/VotingSystem.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package chapter3.demo34;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* VotingSystem类管理整个投票过程
|
||||
*/
|
||||
public class VotingSystem {
|
||||
// 用于接收用户输入
|
||||
private Scanner scanner;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*/
|
||||
public VotingSystem() {
|
||||
this.scanner = new Scanner(System.in);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始投票过程
|
||||
*/
|
||||
public void startVoting() {
|
||||
while (true) {
|
||||
// 输入投票者姓名
|
||||
System.out.println("请输入您的姓名:");
|
||||
String name = scanner.nextLine();
|
||||
Voter voter = new Voter(name);
|
||||
|
||||
// 输入投票意见
|
||||
System.out.println("请投票(Y表示赞同,N表示反对):");
|
||||
String opinion = scanner.nextLine();
|
||||
voter.vote(opinion.equalsIgnoreCase("Y"));
|
||||
|
||||
// 询问是否继续投票
|
||||
System.out.println("是否继续投票?(Y/N)");
|
||||
if (scanner.nextLine().equalsIgnoreCase("N")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 打印投票结果
|
||||
Voter.printResults();
|
||||
}
|
||||
}
|
||||
44
src/chapter4/Example01.java
Normal file
44
src/chapter4/Example01.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package chapter4;
|
||||
|
||||
class Animal {
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
}
|
||||
|
||||
// 定义 Dog 类继承 Animal 类
|
||||
class Dog extends Animal {
|
||||
private String color;
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
public class Example01 {
|
||||
public static void main(String[] args) {
|
||||
Dog dog = new Dog();
|
||||
dog.setName("牧羊犬");
|
||||
dog.setAge(3);
|
||||
System.out.println("名称:" + dog.getName() + ",年龄:" + dog.getAge());
|
||||
}
|
||||
}
|
||||
5
src/chapter4/Example02.java
Normal file
5
src/chapter4/Example02.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package chapter4;
|
||||
|
||||
|
||||
public class Example02 {
|
||||
}
|
||||
46
src/chapter4/Example11/Example11.java
Normal file
46
src/chapter4/Example11/Example11.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package chapter4.Example11;
|
||||
|
||||
interface Animal {
|
||||
int ID = 1; // 接口默认为常量添加 public static final
|
||||
String NAME = "牧羊犬"; // 接口默认为常量添加 public static final
|
||||
|
||||
// 定义抽象方法shout(),接口默认添加 public abstract
|
||||
void shout();
|
||||
|
||||
// 静态方法,默认添加 public
|
||||
static int getID() {
|
||||
return Animal.ID;
|
||||
}
|
||||
|
||||
// 抽象方法
|
||||
public void info();
|
||||
}
|
||||
|
||||
interface Action {
|
||||
public void eat();
|
||||
}
|
||||
|
||||
class Dog implements Animal, Action {
|
||||
public void eat() {
|
||||
System.out.println("喜欢吃骨头");
|
||||
}
|
||||
|
||||
// 重写Animal接口中的抽象方法shout()
|
||||
public void shout() {
|
||||
System.out.println("汪汪...");
|
||||
}
|
||||
|
||||
public void info() {
|
||||
System.out.println("名称:" + NAME);
|
||||
}
|
||||
}
|
||||
|
||||
public class Example11 {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("编号:" + Animal.getID());
|
||||
Dog dog = new Dog();
|
||||
dog.info();
|
||||
dog.shout();
|
||||
dog.eat();
|
||||
}
|
||||
}
|
||||
14
src/chapter4/Example25.java
Normal file
14
src/chapter4/Example25.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package chapter4;
|
||||
|
||||
public class Example25 {
|
||||
public static void main(String[] args) {
|
||||
int result = divide(4, 0);
|
||||
System.out.println("结果:" + result);
|
||||
|
||||
System.out.println("程序继续运行...");
|
||||
}
|
||||
|
||||
public static int divide(int x, int y) {
|
||||
return x / y;
|
||||
}
|
||||
}
|
||||
27
src/chapter4/demo45/Circle.java
Normal file
27
src/chapter4/demo45/Circle.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package chapter4.demo45;
|
||||
|
||||
/**
|
||||
* 圆形类
|
||||
* 必需实现 Shape 接口中的 getArea 和 getPerimeter 方法
|
||||
*/
|
||||
public class Circle implements Shape {
|
||||
// 半径
|
||||
private double radius = 0;
|
||||
private final static double PI = 3.14;
|
||||
|
||||
// 有参构造
|
||||
public Circle(double radius) {
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
// 返回面积
|
||||
public double getArea() {
|
||||
return PI * radius * radius;
|
||||
}
|
||||
|
||||
// 返回周长
|
||||
public double getPerimeter() {
|
||||
return 2 * PI * radius;
|
||||
}
|
||||
|
||||
}
|
||||
51
src/chapter4/demo45/Main.java
Normal file
51
src/chapter4/demo45/Main.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package chapter4.demo45;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
// 处理用户输入
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
while(true) {
|
||||
// 打印菜单
|
||||
ShapeCalculate.printMenu();
|
||||
int select = sc.nextInt();
|
||||
// 判断用户选项
|
||||
switch (select) {
|
||||
case 1: // 圆形
|
||||
System.out.print("请输入圆形的半径:");
|
||||
double radius = sc.nextDouble();
|
||||
Circle circle = new Circle(radius);
|
||||
// Shape circle = new Circle(radius);
|
||||
ShapeCalculate.printArea(circle);
|
||||
ShapeCalculate.printPerimeter(circle);
|
||||
break;
|
||||
case 2: // 长方形
|
||||
System.out.print("请输入长方形的长和宽:");
|
||||
double length = sc.nextDouble();
|
||||
double width = sc.nextDouble();
|
||||
// Shape rectangle = new Rectangle(length, width);
|
||||
Rectangle rectangle = new Rectangle(length, width);
|
||||
ShapeCalculate.printArea(rectangle);
|
||||
ShapeCalculate.printPerimeter(rectangle);
|
||||
break;
|
||||
default:
|
||||
System.out.println("输入错误,请重新选择");
|
||||
ShapeCalculate.printMenu();
|
||||
break;
|
||||
}
|
||||
// 询问用户是否继续
|
||||
System.out.println("继续计算?(Y / N)");
|
||||
String answer = sc.next();
|
||||
if ("N".equalsIgnoreCase(answer)) { // 无论大小写,都识别
|
||||
break;
|
||||
}
|
||||
}
|
||||
System.out.println("感谢您的使用,再见!");
|
||||
sc.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
29
src/chapter4/demo45/Rectangle.java
Normal file
29
src/chapter4/demo45/Rectangle.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package chapter4.demo45;
|
||||
|
||||
/**
|
||||
* 长方形类
|
||||
* 必需实现 Shape 接口中的 getArea 和 getPerimeter 方法
|
||||
*/
|
||||
|
||||
public class Rectangle implements Shape {
|
||||
// 长度
|
||||
private double length = 0;
|
||||
// 宽度
|
||||
private double width = 0;
|
||||
|
||||
// 有参构造
|
||||
public Rectangle(double length, double width) {
|
||||
this.length = length;
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
// 获取面积
|
||||
public double getArea() {
|
||||
return length * width;
|
||||
}
|
||||
|
||||
// 获取周长
|
||||
public double getPerimeter() {
|
||||
return 2 * length + 2 * width;
|
||||
}
|
||||
}
|
||||
15
src/chapter4/demo45/Shape.java
Normal file
15
src/chapter4/demo45/Shape.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package chapter4.demo45;
|
||||
|
||||
/**
|
||||
* 定义“图形”接口,只拥有抽象方法
|
||||
* 后续的圆形和长方形都实现该接口,即圆形和长方形都需要实现 getArea 和 getPerimeter 方法
|
||||
* 通过接口,可以制订“规范、规范”
|
||||
*/
|
||||
public interface Shape {
|
||||
// 获取面积,省略 public abstract
|
||||
double getArea();
|
||||
// 获取周长,省略 public abstract
|
||||
double getPerimeter();
|
||||
}
|
||||
|
||||
|
||||
52
src/chapter4/demo45/ShapeCalculate.java
Normal file
52
src/chapter4/demo45/ShapeCalculate.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package chapter4.demo45;
|
||||
|
||||
/**
|
||||
* 图形计算器类
|
||||
* 1. final 类:防止被继承
|
||||
* 2. 私有构造函数(不可被实例化)
|
||||
* 只有静态方法,不需要实例化,所有方法都可以通过类名调用
|
||||
*/
|
||||
public final class ShapeCalculate {
|
||||
private ShapeCalculate() {
|
||||
throw new AssertionError("不应该被实例化");
|
||||
}
|
||||
|
||||
// 打印图形面积
|
||||
public static void printArea(Shape shape) {
|
||||
if (shape instanceof Rectangle) {
|
||||
System.out.println("正方形面积:"+shape.getArea());
|
||||
} else if (shape instanceof Circle) {
|
||||
System.out.println("圆形面积:"+shape.getArea());
|
||||
} else {
|
||||
System.out.println("未知图形面积:" + shape.getArea());
|
||||
}
|
||||
}
|
||||
|
||||
// 打印图形周长
|
||||
// public static void printPerimeter(Shape shape) {
|
||||
// if (shape instanceof Rectangle) {
|
||||
// System.out.print("长方形");
|
||||
// } else if (shape instanceof Circle) {
|
||||
// System.out.print("圆形");
|
||||
// } else {
|
||||
// System.out.print("未知图形");
|
||||
// }
|
||||
// System.out.println("周长:"+shape.getPerimeter());
|
||||
// }
|
||||
|
||||
public static void printPerimeter(Circle circle) {
|
||||
System.out.println("圆形周长:"+circle.getPerimeter());
|
||||
}
|
||||
|
||||
public static void printPerimeter(Rectangle rectangle) {
|
||||
System.out.println("长方形周长:"+rectangle.getPerimeter());
|
||||
}
|
||||
|
||||
// 打印计算器菜单
|
||||
public static void printMenu() {
|
||||
System.out.println("==========图形计算器==========");
|
||||
System.out.println("1.圆形");
|
||||
System.out.println("2.长方形");
|
||||
System.out.print("请输入序号选择功能:");
|
||||
}
|
||||
}
|
||||
90
src/chapter4/demo49/Main.java
Normal file
90
src/chapter4/demo49/Main.java
Normal file
@@ -0,0 +1,90 @@
|
||||
package chapter4.demo49;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
// 处理用户的输入
|
||||
private static Scanner scanner = new Scanner(System.in);
|
||||
// 用户管理器
|
||||
private static UserManager userManager = UserManager.getInstance();
|
||||
// 当前登录用户
|
||||
private static AbstractUser currentUser = null;
|
||||
|
||||
public static void main(String[] args) {
|
||||
while (true) {
|
||||
printMainMenu();
|
||||
|
||||
try {
|
||||
int choice = scanner.nextInt();
|
||||
switch (choice) {
|
||||
case 1:
|
||||
login();
|
||||
break;
|
||||
case 2:
|
||||
register();
|
||||
break;
|
||||
case 3:
|
||||
if (currentUser instanceof AdminUser) {
|
||||
userManager.showAllUsers();
|
||||
} else {
|
||||
System.out.println("权限不足!");
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (currentUser instanceof AdminUser) {
|
||||
System.out.print("请输入要删除的用户名:");
|
||||
String username = scanner.next();
|
||||
userManager.removeUser(username);
|
||||
System.out.println("删除用户成功!");
|
||||
} else {
|
||||
System.out.println("权限不足!");
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
System.out.println("谢谢使用,再见!");
|
||||
System.exit(0);
|
||||
default:
|
||||
System.out.println("无效的选择!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("发生错误:" + e.getMessage());
|
||||
scanner.nextLine(); // 清除输入缓冲
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void printMainMenu() {
|
||||
System.out.println("\n=====用户管理系统=====");
|
||||
System.out.println("1. 用户登录");
|
||||
System.out.println("2. 用户注册");
|
||||
System.out.println("3. 查看用户列表(需管理员权限)");
|
||||
System.out.println("4. 删除用户(需管理员权限)");
|
||||
System.out.println("0. 退出系统");
|
||||
System.out.println("请选择功能:");
|
||||
}
|
||||
|
||||
private static void login() throws UserException {
|
||||
System.out.print("请输入用户名:");
|
||||
String username = scanner.next();
|
||||
System.out.print("请输入密码:");
|
||||
String password = scanner.next();
|
||||
|
||||
currentUser = userManager.login(username, password);
|
||||
System.out.println("登录成功!欢迎 " + currentUser.getUsername());
|
||||
|
||||
if (currentUser instanceof AdminUser) {
|
||||
System.out.println("您以管理员身份登录");
|
||||
}
|
||||
}
|
||||
|
||||
private static void register() throws UserException {
|
||||
System.out.print("请输入用户名:");
|
||||
String username = scanner.next();
|
||||
System.out.print("请输入密码:");
|
||||
String password = scanner.next();
|
||||
|
||||
NormalUser newUser = new NormalUser(username, password);
|
||||
userManager.addUser(newUser);
|
||||
System.out.println("注册成功!");
|
||||
}
|
||||
}
|
||||
73
src/chapter4/demo49/User.java
Normal file
73
src/chapter4/demo49/User.java
Normal file
@@ -0,0 +1,73 @@
|
||||
package chapter4.demo49;
|
||||
|
||||
// 自定义异常类
|
||||
class UserException extends Exception {
|
||||
public UserException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
// 用户操作接口
|
||||
interface UserOperation {
|
||||
void changePassword(String newPassword) throws UserException;
|
||||
void showInfo();
|
||||
}
|
||||
|
||||
// 抽象用户类
|
||||
abstract class AbstractUser implements UserOperation {
|
||||
protected String username; // 用户名
|
||||
protected String password; // 密码
|
||||
protected String userType; // 用户类型
|
||||
|
||||
// 构造方法
|
||||
public AbstractUser(String username, String password) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
// 检查密码是否正确
|
||||
public boolean checkPassword(String password) {
|
||||
return this.password.equals(password);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showInfo() {
|
||||
System.out.println("用户名:" + username + ",用户类型:" + userType);
|
||||
}
|
||||
}
|
||||
|
||||
// 普通用户类
|
||||
class NormalUser extends AbstractUser {
|
||||
public NormalUser(String username, String password) {
|
||||
super(username, password);
|
||||
this.userType = "普通用户";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changePassword(String newPassword) throws UserException {
|
||||
if (newPassword.length() < 6) {
|
||||
throw new UserException("密码长度不能小于6位");
|
||||
}
|
||||
this.password = newPassword;
|
||||
}
|
||||
}
|
||||
|
||||
// 管理员类
|
||||
class AdminUser extends AbstractUser {
|
||||
public AdminUser(String username, String password) {
|
||||
super(username, password);
|
||||
this.userType = "管理员";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changePassword(String newPassword) throws UserException {
|
||||
if (newPassword.length() < 8) {
|
||||
throw new UserException("管理员密码长度不能小于8位");
|
||||
}
|
||||
this.password = newPassword;
|
||||
}
|
||||
}
|
||||
54
src/chapter4/demo49/UserManager.java
Normal file
54
src/chapter4/demo49/UserManager.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package chapter4.demo49;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
class UserManager {
|
||||
// 保证单例模式
|
||||
private static UserManager instance;
|
||||
// 存储所有用户
|
||||
private Map<String, AbstractUser> users;
|
||||
|
||||
private UserManager() {
|
||||
users = new HashMap<>();
|
||||
// 初始化一个管理员账号
|
||||
users.put("admin", new AdminUser("admin", "admin123"));
|
||||
}
|
||||
|
||||
// 单例模式
|
||||
public static UserManager getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new UserManager();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void addUser(AbstractUser user) throws UserException {
|
||||
if (users.containsKey(user.getUsername())) {
|
||||
throw new UserException("用户名已存在!");
|
||||
}
|
||||
users.put(user.getUsername(), user);
|
||||
}
|
||||
|
||||
public AbstractUser login(String username, String password) throws UserException {
|
||||
AbstractUser user = users.get(username);
|
||||
if (user == null) {
|
||||
throw new UserException("用户不存在!");
|
||||
}
|
||||
if (!user.checkPassword(password)) {
|
||||
throw new UserException("用户名或密码错误!");
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
public void removeUser(String username) {
|
||||
users.remove(username);
|
||||
}
|
||||
|
||||
public void showAllUsers() {
|
||||
System.out.println("当前系统用户列表:");
|
||||
for (AbstractUser user : users.values()) {
|
||||
user.showInfo();
|
||||
}
|
||||
}
|
||||
}
|
||||
15
src/chapter4/example07/Example07.java
Normal file
15
src/chapter4/example07/Example07.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package chapter4.example07;
|
||||
|
||||
final class Animal {
|
||||
// 空
|
||||
}
|
||||
|
||||
//class Dog extends Animal {
|
||||
//
|
||||
//}
|
||||
|
||||
public class Example07 {
|
||||
public static void main(String[] args) {
|
||||
// Dog dog = new Dog();
|
||||
}
|
||||
}
|
||||
19
src/chapter4/example10/Example10.java
Normal file
19
src/chapter4/example10/Example10.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package chapter4.example10;
|
||||
|
||||
abstract class Animal {
|
||||
abstract void shout();
|
||||
|
||||
}
|
||||
|
||||
class Dog extends Animal {
|
||||
void shout() {
|
||||
System.out.println("汪汪...");
|
||||
}
|
||||
}
|
||||
|
||||
public class Example10 {
|
||||
public static void main(String[] args) {
|
||||
Animal dog = new Dog();
|
||||
dog.shout();
|
||||
}
|
||||
}
|
||||
36
src/chapter4/example14/Example14.java
Normal file
36
src/chapter4/example14/Example14.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package chapter4.example14;
|
||||
|
||||
abstract class Animal {
|
||||
abstract void shout();
|
||||
}
|
||||
|
||||
class Cat extends Animal {
|
||||
public void shout() {
|
||||
System.out.println("喵喵...");
|
||||
}
|
||||
}
|
||||
|
||||
class Dog extends Animal {
|
||||
public void shout() {
|
||||
System.out.println("汪汪...");
|
||||
}
|
||||
}
|
||||
|
||||
class Example14 {
|
||||
public static void main(String[] args) {
|
||||
Animal cat = new Cat();
|
||||
Animal dog = new Dog();
|
||||
|
||||
cat.shout();
|
||||
dog.shout();
|
||||
}
|
||||
}
|
||||
|
||||
class Example15 {
|
||||
public static void main(String[] args) {
|
||||
Dog dog = new Dog();
|
||||
Animal an = dog;
|
||||
|
||||
an.shout();
|
||||
}
|
||||
}
|
||||
27
src/chapter4/object/Test.java
Normal file
27
src/chapter4/object/Test.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package chapter4.object;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
class Student {
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
public Student(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
// public String toString() {
|
||||
// return "Student {name=" + name + ", age=" + age + "}";
|
||||
// }
|
||||
}
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
Student s1 = new Student("张三", 23);
|
||||
|
||||
System.out.println(s1);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
21
src/chapter5/Example01.java
Normal file
21
src/chapter5/Example01.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package chapter5;
|
||||
|
||||
public class Example01 {
|
||||
public static void main(String[] args) {
|
||||
// 1、创建一个空的字符串
|
||||
String str1 = new String();
|
||||
// 2、创建一个内容为abcd的字符串
|
||||
String str2 = new String("abcd");
|
||||
// 3、创建一个内容为字符数组的字符串
|
||||
char[] charArray = new char[]{'D', 'E', 'F'};
|
||||
String str3 = new String(charArray);
|
||||
// 4、创建一个内容为字节数组的字符串
|
||||
byte[] arr = {97, 98, 99};
|
||||
String str4 = new String(arr);
|
||||
|
||||
System.out.println("a" + str1 + "b");
|
||||
System.out.println(str2);
|
||||
System.out.println(str3);
|
||||
System.out.println(str4);
|
||||
}
|
||||
}
|
||||
13
src/chapter5/Example02.java
Normal file
13
src/chapter5/Example02.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package chapter5;
|
||||
|
||||
public class Example02 {
|
||||
public static void main(String[] args) {
|
||||
String s = "abcdabc";
|
||||
System.out.println("字符串的长度为:" + s.length());
|
||||
System.out.println("字符串中第一个字符:" + s.charAt(0));
|
||||
System.out.println("字符c第一次出现的位置:" + s.indexOf('c'));
|
||||
System.out.println("字符c最后一次出现的位置:" + s.lastIndexOf('c'));
|
||||
System.out.println("子字符串ab第一次出现的位置:" + s.indexOf("ab"));
|
||||
System.out.println("子字符串ab字符串最后一次出现的位置:" + s.lastIndexOf("ab"));
|
||||
}
|
||||
}
|
||||
24
src/chapter5/Example03.java
Normal file
24
src/chapter5/Example03.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package chapter5;
|
||||
|
||||
public class Example03 {
|
||||
public static void main(String[] args) {
|
||||
String str = "abcdEFG";
|
||||
|
||||
// 1、转换成字符数组
|
||||
System.out.print("将字符串转为字符数组后的结果:");
|
||||
char[] charArray = str.toCharArray();
|
||||
for (char c : charArray) {
|
||||
System.out.print(c); // 打印当前遍历到的字符
|
||||
System.out.print(','); // 每打印一个字符后,加一个逗号
|
||||
}
|
||||
|
||||
// 2、把数字转换成字符串(好用)
|
||||
System.out.println();
|
||||
System.out.print("把数字123转换成字符串的效果:");
|
||||
System.out.println(String.valueOf(123));
|
||||
|
||||
// 3、大小写转换(常用)
|
||||
System.out.println("转换成小写:" + str.toLowerCase());
|
||||
System.out.println("转换成大写:" + str.toUpperCase());
|
||||
}
|
||||
}
|
||||
16
src/chapter5/Example04.java
Normal file
16
src/chapter5/Example04.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package chapter5;
|
||||
|
||||
public class Example04 {
|
||||
public static void main(String[] args) {
|
||||
String name = "王小明";
|
||||
String newName = name.replace("王", "卢");
|
||||
System.out.println("旧名字:" + name + "\n新名字:" + newName);
|
||||
|
||||
System.out.println();
|
||||
|
||||
String name2 = " 王 小明 ";
|
||||
String name3 = name2.trim();
|
||||
System.out.println("去除空格前:" + name2 + "\n去除空格后:" + name3 );
|
||||
// 思考:如何去掉所有空格?
|
||||
}
|
||||
}
|
||||
14
src/chapter5/Example05.java
Normal file
14
src/chapter5/Example05.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package chapter5;
|
||||
|
||||
public class Example05 {
|
||||
public static void main(String[] args) {
|
||||
String s1 = "我是王小明";
|
||||
String s2 = "我是";
|
||||
|
||||
System.out.println("判断开头:" + s1.startsWith("我是"));
|
||||
System.out.println("判断结尾:" + s1.endsWith("小明"));
|
||||
System.out.println("判断包含:" + s1.contains("是"));
|
||||
System.out.println("判空:" + s1.isEmpty());
|
||||
System.out.println("判断相等:" + s1.equals(s2));
|
||||
}
|
||||
}
|
||||
16
src/chapter5/Example06.java
Normal file
16
src/chapter5/Example06.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package chapter5;
|
||||
|
||||
public class Example06 {
|
||||
public static void main(String[] args) {
|
||||
String str = "石家庄-武汉-哈尔滨";
|
||||
// 1、截取
|
||||
System.out.println("从第5个字符截取到末尾:" + str.substring(4));
|
||||
System.out.println("从第5个字符截取到第6个字符:" + str.substring(4, 6));
|
||||
// 2、分割
|
||||
System.out.println("分割后字符串数组中的元素依次是:");
|
||||
String[] array = str.split("-");
|
||||
for (String s : array) {
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
48
src/chapter5/Example08.java
Normal file
48
src/chapter5/Example08.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package chapter5;
|
||||
|
||||
public class Example08 {
|
||||
public static void main(String[] args) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
System.out.println("1、添加------------------------");
|
||||
add(sb);
|
||||
System.out.println("2、删除------------------------");
|
||||
remove(sb);
|
||||
System.out.println("3、修改------------------------");
|
||||
alter();
|
||||
|
||||
}
|
||||
public static void add(StringBuffer sb) {
|
||||
|
||||
sb.append("我王小明");
|
||||
System.out.println("append添加结果:" + sb);
|
||||
|
||||
sb.insert(1, "的名字是");
|
||||
System.out.println("insert添加结果:" + sb);
|
||||
|
||||
sb.append("白");
|
||||
System.out.println("append添加结果:" + sb);
|
||||
}
|
||||
|
||||
public static void alter() {
|
||||
StringBuffer sb = new StringBuffer("我的性别是王小白");
|
||||
sb.replace(2, 4, "姓名");
|
||||
System.out.println("替换指定位置字符串:" + sb);
|
||||
|
||||
sb.setCharAt(0, '你');
|
||||
System.out.println("修改指定位置字符:" + sb);
|
||||
|
||||
System.out.println("翻转:" + sb.reverse());
|
||||
}
|
||||
|
||||
public static void remove(StringBuffer sb) {
|
||||
sb.delete(0, 5);
|
||||
System.out.println("delete的结果:" + sb);
|
||||
|
||||
sb.deleteCharAt(3);
|
||||
System.out.println("deleteCharAt结果:" + sb);
|
||||
|
||||
sb.delete(0, sb.length());
|
||||
System.out.println("清空:" + sb);
|
||||
}
|
||||
}
|
||||
59
src/chapter5/Example09.java
Normal file
59
src/chapter5/Example09.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package chapter5;
|
||||
|
||||
public class Example09 {
|
||||
private static final int TIMES = 100000;
|
||||
|
||||
public static void main(String[] args) {
|
||||
testString();
|
||||
testStringBuffer();
|
||||
testStringBuilder();
|
||||
test();
|
||||
}
|
||||
|
||||
// String时间效率
|
||||
public static void testString() {
|
||||
long start = System.currentTimeMillis();
|
||||
String str = "";
|
||||
for (int i = 0; i < TIMES; i++) {
|
||||
str += "test";
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println("String测试耗时:" + (end - start) + "ms");
|
||||
}
|
||||
|
||||
// StringBuffer时间效率(线程安全)
|
||||
public static void testStringBuffer() {
|
||||
long start = System.currentTimeMillis();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < TIMES; i++) {
|
||||
sb.append("test");
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println("StringBuffer测试耗时:" + (end - start) + "ms");
|
||||
}
|
||||
|
||||
// StringBuilder时间效率(非线程安全)
|
||||
public static void testStringBuilder() {
|
||||
long start = System.currentTimeMillis();
|
||||
StringBuilder sb = new StringBuilder("hello");
|
||||
for (int i = 0; i < TIMES; i++) {
|
||||
sb.append("test");
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println("StringBuilder测试耗时:" + (end - start) + "ms");
|
||||
}
|
||||
|
||||
public static void test() {
|
||||
String s1 = new String("abc");
|
||||
String s2 = new String("abc");
|
||||
System.out.println(s1.equals(s2)); // 打印结果为true
|
||||
StringBuffer sb1 = new StringBuffer("abc");
|
||||
StringBuffer sb2 = new StringBuffer("abc");
|
||||
System.out.println(sb1.equals(sb2)); // 打印结果为false
|
||||
StringBuilder sbr1=new StringBuilder("abc");
|
||||
StringBuilder sbr2=new StringBuilder("abc");
|
||||
System.out.println(sbr1.equals(sbr2)); // 打印结果为false
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
19
src/chapter5/Example10.java
Normal file
19
src/chapter5/Example10.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package chapter5;
|
||||
|
||||
/**
|
||||
* 拷贝数组
|
||||
* System.arraycopy()
|
||||
*/
|
||||
public class Example10 {
|
||||
public static void main(String[] args) {
|
||||
int[] srcArray = {10 ,11, 12, 13, 14, 15, 16};
|
||||
int[] toArray = {20, 21, 22, 23, 24, 25, 26, 27};
|
||||
|
||||
System.arraycopy(srcArray, 2, toArray, 3, 4);
|
||||
|
||||
System.out.println("拷贝后的数组元素为:");
|
||||
for (int i = 0; i < toArray.length; i++) {
|
||||
System.out.println("i : " + toArray[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
src/chapter5/Example11.java
Normal file
18
src/chapter5/Example11.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package chapter5;
|
||||
|
||||
/**
|
||||
* 获取当前时间
|
||||
*/
|
||||
|
||||
public class Example11 {
|
||||
public static void main(String[] args) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
String test = "";
|
||||
for (int i = 0; i < 100000; i ++) {
|
||||
test += "test";
|
||||
}
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
System.out.println("程序运行的时间:" + (endTime - startTime) + "ms");
|
||||
}
|
||||
}
|
||||
21
src/chapter5/Example12.java
Normal file
21
src/chapter5/Example12.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package chapter5;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* 获取系统信息
|
||||
*/
|
||||
public class Example12 {
|
||||
public static void main(String[] args) {
|
||||
// 获取当前系统信息
|
||||
Properties prop = System.getProperties();
|
||||
Enumeration names = prop.propertyNames();
|
||||
while (names.hasMoreElements()) {
|
||||
String key = (String) names.nextElement();
|
||||
String value = prop.getProperty(key);
|
||||
System.out.println(key + "=" + value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
28
src/chapter5/Example13.java
Normal file
28
src/chapter5/Example13.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package chapter5;
|
||||
|
||||
class Person implements AutoCloseable {
|
||||
String name;
|
||||
public Person(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
System.out.println( name + " 要被回收啦!");
|
||||
}
|
||||
}
|
||||
|
||||
public class Example13 {
|
||||
public static void main(String[] args) {
|
||||
Person p1 = new Person("小明");
|
||||
Person p2 = new Person("大王");
|
||||
|
||||
p1 = null;
|
||||
p2 = null;
|
||||
|
||||
System.gc();
|
||||
|
||||
for (int i = 0; i < 1000000; i ++) {
|
||||
// 为了延长程序运行的时间
|
||||
}
|
||||
}
|
||||
}
|
||||
15
src/chapter5/Example14.java
Normal file
15
src/chapter5/Example14.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package chapter5;
|
||||
|
||||
/**
|
||||
* 获取当前虚拟机信息
|
||||
*/
|
||||
|
||||
public class Example14 {
|
||||
public static void main(String[] args) {
|
||||
Runtime rt = Runtime.getRuntime();
|
||||
System.out.println("处理器个数:" + rt.availableProcessors());
|
||||
System.out.println("空闲内存:" + rt.freeMemory()/1024/1024 + "MB");
|
||||
System.out.println("虚拟机中的内存总量:" + rt.totalMemory()/1024/1024 + "MB");
|
||||
System.out.println("最大可用内存:" + rt.maxMemory()/1024/1024 + "MB");
|
||||
}
|
||||
}
|
||||
15
src/chapter5/Example16.java
Normal file
15
src/chapter5/Example16.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package chapter5;
|
||||
|
||||
public class Example16 {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("计算绝对值的结果: " + Math.abs(-10));
|
||||
System.out.println("求大于参数的最小整数: " + Math.ceil(5.6));
|
||||
System.out.println("求小于参数的最大整数: " + Math.floor(-4.2));
|
||||
System.out.println("对小数进行四舍五入后的结果: " + Math.round(-4.6));
|
||||
System.out.println("求两个数的较大值: " + Math.max(2.1, -2.1));
|
||||
System.out.println("求两个数的较小值: " + Math.min(2.1, -2.1));
|
||||
System.out.println("生成一个大于等于0.0小于1.0随机值: " + Math.round(10 * Math.random()));
|
||||
System.out.println("开平方的结果: "+Math.sqrt(4));
|
||||
System.out.println("指数函数的值: "+Math.pow(2, 3));
|
||||
}
|
||||
}
|
||||
13
src/chapter5/Example17.java
Normal file
13
src/chapter5/Example17.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package chapter5;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Example17 {
|
||||
public static void main(String[] args) {
|
||||
Random r = new Random(); // 不传入种子
|
||||
for (int i = 0; i < 10; i++) {
|
||||
// 随机产生10个[0,100)之间的整数
|
||||
System.out.println(r.nextInt(100));
|
||||
}
|
||||
}
|
||||
}
|
||||
13
src/chapter5/Example18.java
Normal file
13
src/chapter5/Example18.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package chapter5;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Example18 {
|
||||
public static void main(String[] args) {
|
||||
Random r = new Random(13);
|
||||
// 随机产生10个[0,100)之间的整数
|
||||
for (int i = 0; i < 10; i++) {
|
||||
System.out.println(r.nextInt(100));
|
||||
}
|
||||
}
|
||||
}
|
||||
12
src/chapter5/Example20.java
Normal file
12
src/chapter5/Example20.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package chapter5;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
public class Example20 {
|
||||
public static void main(String[] args) {
|
||||
Instant now = Instant.now();
|
||||
System.out.println(now);
|
||||
Instant instant = Instant.ofEpochMilli(1000 * 60 * 60 * 24);
|
||||
System.out.println(instant);
|
||||
}
|
||||
}
|
||||
33
src/chapter5/Example21.java
Normal file
33
src/chapter5/Example21.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package chapter5;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class Example21 {
|
||||
public static void main(String[] args) {
|
||||
LocalDate now = LocalDate.now();
|
||||
LocalDate of = LocalDate.of(2015, 12, 12);
|
||||
|
||||
System.out.println("今年是" + now.getYear() + "年");
|
||||
System.out.println("月份:" + now.getMonth());
|
||||
System.out.println("月份:" + now.getMonthValue());
|
||||
System.out.println("日期:" + now.getDayOfMonth());
|
||||
System.out.println("今年中的第几天:" + now.getDayOfYear());
|
||||
System.out.println("周几:" + now.getDayOfWeek());
|
||||
|
||||
System.out.println("\n====判断相关的方法====");
|
||||
|
||||
System.out.println("of是否在now之前?" + of.isBefore(now));
|
||||
System.out.println("of是否在now之后?" + of.isAfter(now));
|
||||
System.out.println("of和now是否相等?" + of.isEqual(now));
|
||||
System.out.println("of是否闰年?" + of.isLeapYear());
|
||||
|
||||
System.out.println("\n====解析和加减操作====");
|
||||
|
||||
String dateStr = "2020-02-12";
|
||||
LocalDate date = LocalDate.parse(dateStr);
|
||||
System.out.println("把字符串转换为日期对象:" + date);
|
||||
System.out.println("年份加1:" + date.plusYears(1));
|
||||
System.out.println("天数减5:" + date.minusDays(5));
|
||||
System.out.println("指定年份为2024:" + date.withYear(2024));
|
||||
}
|
||||
}
|
||||
30
src/chapter5/Example22.java
Normal file
30
src/chapter5/Example22.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package chapter5;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class Example22 {
|
||||
public static void main(String[] args) {
|
||||
// 1. 获取当前时间
|
||||
LocalTime now = LocalTime.now();
|
||||
// 2. 表示过去时间
|
||||
LocalTime of = LocalTime.of(9, 23, 23);
|
||||
// 3. 三个getter
|
||||
System.out.println("时:" + now.getHour());
|
||||
System.out.println("分:" + now.getMinute());
|
||||
System.out.println("秒:" + now.getSecond());
|
||||
|
||||
// 4. 格式转换,借助 DateTimeFormatter
|
||||
System.out.println("\nnow默认格式:" + now);
|
||||
System.out.println("不显示微秒:" + now.withNano(0));
|
||||
System.out.println("转换格式:" + now.format(DateTimeFormatter.ofPattern("HH:mm:ss")));
|
||||
System.out.println("转换格式:" + now.format(DateTimeFormatter.ofPattern("HH点mm分ss秒")));
|
||||
|
||||
// 5. 判断
|
||||
System.out.println("\nof在now之前吗?" + of.isBefore(now));
|
||||
|
||||
// 6. 解析字符串
|
||||
LocalTime time = LocalTime.parse("12:15:30");
|
||||
System.out.println("将字符串转换成时间对象:" + time);
|
||||
}
|
||||
}
|
||||
19
src/chapter5/Example23.java
Normal file
19
src/chapter5/Example23.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package chapter5;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class Example23 {
|
||||
public static void main(String[] args) {
|
||||
// 1. 获取当前时间
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
System.out.println("原格式:" + now);
|
||||
System.out.println("只有日期:" + now.toLocalDate());
|
||||
System.out.println("只有时间:" + now.toLocalTime());
|
||||
// 2. getter 方法
|
||||
System.out.println(now.getYear() +"年" + now.getMonthValue() + "月" + now.getDayOfMonth() + "号 "
|
||||
+ now.getHour() + "点" + now.getMinute() + "分" + now.getSecond() + "秒");
|
||||
// 3. 指定格式
|
||||
System.out.println("指定格式:" + now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
}
|
||||
}
|
||||
20
src/chapter5/Example24.java
Normal file
20
src/chapter5/Example24.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package chapter5;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalTime;
|
||||
|
||||
public class Example24 {
|
||||
public static void main(String[] args) {
|
||||
LocalTime start = LocalTime.now();
|
||||
LocalTime end = LocalTime.of(21, 53, 0);
|
||||
|
||||
Duration duration = Duration.between(start, end);
|
||||
|
||||
System.out.println("时间间隔(纳秒)" + duration.toNanos());
|
||||
System.out.println("时间间隔(毫秒)" + duration.toMillis());
|
||||
System.out.println("时间间隔(秒)" + duration.toSeconds());
|
||||
System.out.println("时间间隔(分钟)" + duration.toMinutes());
|
||||
System.out.println("时间间隔(小时)" + duration.toHours());
|
||||
|
||||
}
|
||||
}
|
||||
16
src/chapter5/Example25.java
Normal file
16
src/chapter5/Example25.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package chapter5;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Period;
|
||||
|
||||
public class Example25 {
|
||||
public static void main(String[] args) {
|
||||
LocalDate birthday = LocalDate.of(2018, 12, 12);
|
||||
LocalDate now = LocalDate.of(2020, 11, 13);
|
||||
|
||||
Period period = Period.between(birthday, now);
|
||||
System.out.println("时间间隔(年)" + period.getYears());
|
||||
System.out.println("时间间隔(月)" + period.getMonths());
|
||||
System.out.println("时间间隔(天)" + period.getDays());
|
||||
}
|
||||
}
|
||||
202
src/chapter5/ShoppingCart.java
Normal file
202
src/chapter5/ShoppingCart.java
Normal file
@@ -0,0 +1,202 @@
|
||||
package chapter5;
|
||||
|
||||
/**
|
||||
* 双十一购物车
|
||||
* 需求:
|
||||
* 1. 添加商品到购物车(商品名称用StringBuilder拼接)
|
||||
* 2. 显示购物车商品清单(把StringBuilder转换为String输出)
|
||||
* 3. 修改商品名称(用String的replace方法)
|
||||
* 4. 删除购物车某个商品(用StringBuilder的delete方法)
|
||||
* 5. 计算购物车商品总价
|
||||
*/
|
||||
public class ShoppingCart {
|
||||
private StringBuilder cart; // 购物车商品列表
|
||||
private double totalPrice; // 总价格
|
||||
|
||||
/**
|
||||
* 构造方法思路:
|
||||
* 1. 创建空的购物车,使用StringBuilder存储商品信息
|
||||
* 2. 初始化总价为0
|
||||
* 为什么使用StringBuilder?因为购物车内容会经常变动,StringBuilder更适合频繁修改
|
||||
*/
|
||||
public ShoppingCart() {
|
||||
cart = new StringBuilder();
|
||||
totalPrice = 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* addItem方法思路:
|
||||
* 1. 判断购物车是否为空
|
||||
* - 如果不空,需要先添加分隔符", "
|
||||
* - 如果是空的,直接添加商品
|
||||
* 2. 拼接商品信息:商品名(¥价格)
|
||||
* 例如:小米手机(¥1999.0)
|
||||
* 3. 更新总价
|
||||
*
|
||||
* 考虑:为什么要加if判断?
|
||||
* - 为了避免第一个商品前也加逗号
|
||||
* - 让商品列表更美观:商品1(¥xx), 商品2(¥xx), 商品3(¥xx)
|
||||
*/
|
||||
public void addItem(String item, double price) {
|
||||
if (!cart.isEmpty()) {
|
||||
cart.append(", ");
|
||||
}
|
||||
cart.append(item).append("(¥").append(price).append(")");
|
||||
totalPrice += price;
|
||||
}
|
||||
|
||||
/**
|
||||
* showCart方法思路:
|
||||
* 1. 先判断购物车是否为空
|
||||
* - 如果为空,返回提示信息
|
||||
* - 如果不为空,显示商品清单和总价
|
||||
* 2. 把StringBuilder转换为String返回
|
||||
*
|
||||
* 为什么要转换成String?
|
||||
* - String更适合显示最终结果
|
||||
* - println方法接收String类型参数
|
||||
*/
|
||||
public String showCart() {
|
||||
if (cart.isEmpty()) {
|
||||
return "购物车是空的呢,快去选购吧!";
|
||||
}
|
||||
return "购物车商品: " + cart.toString() + "\n总价: ¥" + totalPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* modifyItem方法思路:
|
||||
* 1. 先将StringBuilder转换为String
|
||||
* 2. 使用String的replace方法替换商品名
|
||||
* 3. 将修改后的String再转回StringBuilder
|
||||
*
|
||||
* 为什么要转换来转换去?
|
||||
* - String的replace方法使用更方便
|
||||
* - StringBuilder没有直接的替换方法
|
||||
* 注意:这里没有修改价格,实际项目中可能需要考虑价格变化
|
||||
*/
|
||||
public void modifyItem(String oldItem, String newItem) {
|
||||
String cartStr = cart.toString();
|
||||
cartStr = cartStr.replace(oldItem, newItem);
|
||||
cart = new StringBuilder(cartStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* removeItem方法思路:
|
||||
* 1. 找到要删除商品名的起始位置(indexOf)
|
||||
* 2. 如果找到了(start != -1):
|
||||
* - 找到这个商品信息的结束位置(")"的位置再+1)
|
||||
* - 如果后面还有商品,则多删除", "这两个字符
|
||||
* 3. 使用StringBuilder的delete方法删除
|
||||
* 4. 更新总价
|
||||
*
|
||||
* 难点解析:
|
||||
* end < cart.length() && cart.charAt(end) == ','
|
||||
* - 为什么要判断end < cart.length()?避免数组越界
|
||||
* - 为什么要判断逗号?确保后面还有其他商品
|
||||
*/
|
||||
public void removeItem(String item, double price) {
|
||||
int start = cart.indexOf(item);
|
||||
if (start != -1) {
|
||||
int end = cart.indexOf(")", start) + 1;
|
||||
if (end < cart.length() && cart.charAt(end) == ',') {
|
||||
end += 2; // 删除后面的逗号和空格
|
||||
}
|
||||
cart.delete(start, end);
|
||||
totalPrice -= price;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空购物车方法思路:
|
||||
* 1. 使用StringBuilder的setLength(0)清空购物车内容
|
||||
* - 比创建新对象更高效
|
||||
* - 比delete(0,length)更简洁
|
||||
* 2. 重置总价为0
|
||||
*
|
||||
* 为什么用setLength(0)而不是cart = new StringBuilder()?
|
||||
* - setLength(0)只是将长度设为0,原有空间仍可重用
|
||||
* - 创建新对象会产生额外的内存开销
|
||||
*/
|
||||
public void clearCart() {
|
||||
cart = new StringBuilder();
|
||||
totalPrice = 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对购物车中指定商品应用折扣
|
||||
* 折扣范围: 0.0-1.0 (例如0.8表示8折)
|
||||
* 实现思路:
|
||||
* 1. 检查折扣是否合法
|
||||
* 2. 在购物车中查找商品
|
||||
* 3. 提取商品原价
|
||||
* 4. 计算新价格并更新购物车
|
||||
* 5. 更新总价
|
||||
*
|
||||
* @param item 要打折的商品名称
|
||||
* @param discount 折扣率(0.0-1.0)
|
||||
* @throws IllegalArgumentException 当折扣不在有效范围内时抛出
|
||||
*/
|
||||
public void applyDiscount(String item, double discount) {
|
||||
// 验证折扣是否合法
|
||||
if (discount <= 0.0 || discount >= 1.0) {
|
||||
throw new IllegalArgumentException("折扣必须在0.0到1.0之间");
|
||||
}
|
||||
|
||||
// 查找商品在购物车中的位置
|
||||
String cartStr = cart.toString();
|
||||
int itemStart = cartStr.indexOf(item);
|
||||
if (itemStart == -1) {
|
||||
return; // 商品不存在,直接返回
|
||||
}
|
||||
|
||||
// 提取价格信息
|
||||
int priceStart = cartStr.indexOf("¥", itemStart);
|
||||
int priceEnd = cartStr.indexOf(")", priceStart);
|
||||
double originalPrice = Double.parseDouble(cartStr.substring(priceStart + 1, priceEnd));
|
||||
|
||||
// 计算新价格
|
||||
double newPrice = originalPrice * discount;
|
||||
|
||||
// 更新总价
|
||||
totalPrice = totalPrice - originalPrice + newPrice;
|
||||
|
||||
// 更新购物车中的价格
|
||||
String oldPriceStr = String.format("¥%.1f", originalPrice);
|
||||
String newPriceStr = String.format("¥%.1f", newPrice);
|
||||
cart.replace(priceStart, priceEnd, newPriceStr);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 测试购物车
|
||||
ShoppingCart cart = new ShoppingCart();
|
||||
System.out.println(cart.showCart());
|
||||
System.out.println();
|
||||
|
||||
// 添加商品
|
||||
cart.addItem("小米手机", 1999.0);
|
||||
cart.addItem("耳机", 299.0);
|
||||
cart.addItem("充电器", 39.9);
|
||||
System.out.println("添加商品后:");
|
||||
System.out.println(cart.showCart());
|
||||
|
||||
// 修改商品名称
|
||||
cart.modifyItem("小米手机", "华为手机");
|
||||
System.out.println("\n修改商品后:");
|
||||
System.out.println(cart.showCart());
|
||||
|
||||
// 应用商品折扣
|
||||
cart.applyDiscount("耳机", 0.8);
|
||||
System.out.println("\n应用折扣后:");
|
||||
System.out.println(cart.showCart());
|
||||
|
||||
// 删除商品
|
||||
cart.removeItem("耳机", 299.0);
|
||||
System.out.println("\n删除商品后:");
|
||||
System.out.println(cart.showCart());
|
||||
|
||||
// 清空购物车
|
||||
cart.clearCart();
|
||||
System.out.println("\n清空购物车后:");
|
||||
System.out.println(cart.showCart());
|
||||
}
|
||||
}
|
||||
47
src/chapter5/demo51/OrderID.java
Normal file
47
src/chapter5/demo51/OrderID.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package chapter5.demo51;
|
||||
|
||||
public class OrderID {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("====String实现====");
|
||||
int[] time = {2024, 1107, 1040};
|
||||
String orderID = arrayToString(time);
|
||||
System.out.println("订单号 " + orderID);
|
||||
|
||||
System.out.println("\n====StringBuffer实现====");
|
||||
int[] time2 = {2023, 1006, 1200};
|
||||
String orderID2 = arrayToString(time2);
|
||||
System.out.println("订单号 " + orderID2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将数组拼接成字符串,并在首尾添加`OID:[]`
|
||||
* 注意:使用String实现
|
||||
* @param arr 存放数字的数组
|
||||
* @return 拼接后的字符串,格式为`[202411071040]`
|
||||
*/
|
||||
public static String arrayToString(int[] arr) {
|
||||
String s = "";
|
||||
s += "OID:[";
|
||||
for (int c : arr) {
|
||||
s += c;
|
||||
}
|
||||
s += ']';
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将数组拼接成字符串,并在首尾添加`OID:[]`
|
||||
* 注:使用StringBuffer实现
|
||||
* @param arr 存放数字的数组
|
||||
* @return 拼接后的字符串,格式为`[202411071040]`
|
||||
*/
|
||||
public static String arrayToStringUsingBuffer(int[] arr) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("OID:[");
|
||||
for (int c : arr) {
|
||||
sb.append(c);
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
43
src/chapter5/demo55.java
Normal file
43
src/chapter5/demo55.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package chapter5;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class demo55 {
|
||||
public static void main(String[] args) {
|
||||
Scanner scn = new Scanner(System.in);
|
||||
System.out.println("请输入要判断的年份:");
|
||||
int year = scn.nextInt();
|
||||
|
||||
System.out.println("方法一:" + year + "的2月有" + getNumOfDaysInFeb1(year) + "天");
|
||||
System.out.println("方法二:" + year + "的2月有" + getNumOfDaysInFeb2(year) + "天");
|
||||
}
|
||||
|
||||
/**
|
||||
* 思路一
|
||||
* @param year 年份
|
||||
* @return 2月的天数
|
||||
*/
|
||||
public static int getNumOfDaysInFeb1(int year) {
|
||||
LocalDate date = LocalDate.of(year, 3, 1);
|
||||
LocalDate feb = date.minusDays(1);
|
||||
return feb.getDayOfMonth();
|
||||
}
|
||||
|
||||
/**
|
||||
* 思路二
|
||||
* @param year 年份
|
||||
* @return 2月的天数
|
||||
*/
|
||||
public static int getNumOfDaysInFeb2(int year) {
|
||||
LocalDate date = LocalDate.of(year, 1, 1);
|
||||
if (date.isLeapYear()) {
|
||||
return 29;
|
||||
} else {
|
||||
return 28;
|
||||
}
|
||||
|
||||
// return date.isLeapYear() ? 29 : 28;
|
||||
}
|
||||
|
||||
}
|
||||
38
src/chapter6/Example01.java
Normal file
38
src/chapter6/Example01.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package chapter6;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Example01 {
|
||||
public static void main(String[] args) {
|
||||
ArrayList list = new ArrayList();
|
||||
list.add("张三");
|
||||
list.add("李四");
|
||||
list.add("王五");
|
||||
list.add("赵六");
|
||||
list.add("钱七");
|
||||
list.add("孙八");
|
||||
|
||||
// 获取集合中元素的个数
|
||||
System.out.println("元素个数:" + list.size());
|
||||
// 取出指定位置的元素
|
||||
System.out.println("第2个元素" + list.get(1));
|
||||
// 取出所有元素
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
System.out.print(list.get(i) + "\t");
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
// 删除第2个元素
|
||||
list.remove(1);
|
||||
// 取出所有元素
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
System.out.print(list.get(i) + "\t");
|
||||
}
|
||||
|
||||
// 计算位置
|
||||
System.out.println("\n赵六是第" + list.indexOf("赵六"));
|
||||
|
||||
// 直接打印所有元素,不用手动遍历
|
||||
System.out.println(list.toString());
|
||||
}
|
||||
}
|
||||
24
src/chapter6/Example02.java
Normal file
24
src/chapter6/Example02.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package chapter6;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class Example02 {
|
||||
public static void main(String[] args) {
|
||||
LinkedList link = new LinkedList();
|
||||
link.add("张三");
|
||||
link.add("李四");
|
||||
link.add("王五");
|
||||
link.add("赵六");
|
||||
link.add("钱七");
|
||||
link.add("孙八");
|
||||
|
||||
System.out.println(link.toString()); // 取出并打印该集合中的元素
|
||||
link.add(3, "Student"); // 向该集合中指定位置插入元素
|
||||
link.addFirst("First"); // 向该集合第一个位置插入元素
|
||||
System.out.println(link);
|
||||
System.out.println(link.getFirst()); // 取出该集合中第一个元素
|
||||
link.remove(3); // 移除该集合中指定位置的元素
|
||||
link.removeFirst(); // 移除该集合中第一个元素
|
||||
System.out.println(link);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user