This commit is contained in:
2025-09-21 21:55:05 +08:00
parent 4264c76aa8
commit 9a58125862
22 changed files with 376 additions and 99 deletions

38
.gitignore vendored Normal file
View File

@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

6
.idea/copilot.data.migration.agent.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AgentMigrationStateService">
<option name="migrationStatus" value="COMPLETED" />
</component>
</project>

6
.idea/copilot.data.migration.ask.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AskMigrationStateService">
<option name="migrationStatus" value="COMPLETED" />
</component>
</project>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Ask2AgentMigrationStateService">
<option name="migrationStatus" value="COMPLETED" />
</component>
</project>

6
.idea/copilot.data.migration.edit.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EditMigrationStateService">
<option name="migrationStatus" value="COMPLETED" />
</component>
</project>

7
.idea/encodings.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

14
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="22" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -1,5 +0,0 @@
public class Hello {
public void greet(String name) {
System.out.println("Hello, " + name + "!");
}
}

Binary file not shown.

View File

@@ -1,11 +0,0 @@
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
Hello hello = new Hello();
hello.greet("Alice");
}
}

View File

@@ -1,27 +0,0 @@
package JavaBasicStudy;
public class HelloJava {
enum Color {
RED,ORANGE,YELLOW,GREEN,BLUE,BLACK,WHITE
}
public static void main(String[] args) {
HelloJava helloJava = new HelloJava();
helloJava.testHuHangTao();
}
public void testHuHangTao(){
SWPUStudent HuHangTao = new SWPUStudent("胡航滔", 20, "2024520541", "网络工程", 3.8, "hht@stu.swpu.edu.cn", "12345678901", "四川省广安市", "");
HuHangTao.ShowInfo();
HuHangTao.setGpa(4.5);
HuHangTao.setEmail(HuHangTao.getStudentID() + "@stu.swpu.edu.cn");
HuHangTao.setPhoneNumber("18782345678");
HuHangTao.ShowInfo();
}
}

View File

@@ -1,25 +0,0 @@
package JavaBasicStudy;
public class JavaBasicDataType {
public int integerType = 100; //整数类型
public float floatType = 3.14f; //单精度浮点类型
public double doubleType = 3.141592653589793; //双精度浮点类型
public char charType = 'A'; //字符类型
public boolean booleanType = true; //布尔类型
public String stringType = "Hello, Java!"; //字符串类型
public long longType = 123456789L; //长整型
public short shortType = 32000; //短整型
public byte byteType = 100; //字节型
public void displayDataTypes() {
System.out.println("整数类型 (int): " + integerType);
System.out.println("单精度浮点类型 (float): " + floatType);
System.out.println("双精度浮点类型 (double): " + doubleType);
System.out.println("字符类型 (char): " + charType);
System.out.println("布尔类型 (boolean): " + booleanType);
System.out.println("字符串类型 (String): " + stringType);
System.out.println("长整型 (long): " + longType);
System.out.println("短整型 (short): " + shortType);
System.out.println("字节型 (byte): " + byteType);
}
}

21
LICENSE
View File

@@ -1,21 +0,0 @@
MIT License
Copyright (c) 2025 ShuMengya
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

17
pom.xml Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>smy.javastudy</groupId>
<artifactId>SmyJavaStudy</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@@ -0,0 +1,17 @@
package smy.javastudy;
public class GrammarPractice {
public void Exchange(String input){
switch (input){
case "刘道熙":
System.out.println("是畜生");
break;
case "唐伟":
System.out.println("是大帅比");
break;
default:
System.out.println("不知道");
break;
}
}
}

View File

@@ -0,0 +1,74 @@
package smy.javastudy;
public class JavaBasicDataType {
public int integerType = 100; //整数类型
public float floatType = 3.14f; //单精度浮点类型
public double doubleType = 3.141592653589793; //双精度浮点类型
public char charType = 'A'; //字符类型
public boolean booleanType = true; //布尔类型
public String stringType = "Hello, Java!"; //字符串类型
public long longType = 123456789L; //长整型
public short shortType = 32000; //短整型
public byte byteType = 100; //字节型
public void displayDataTypes() {
System.out.println("==================================================");
System.out.println("整数类型 (int): " + integerType);
System.out.println("单精度浮点类型 (float): " + floatType);
System.out.println("双精度浮点类型 (double): " + doubleType);
System.out.println("字符类型 (char): " + charType);
System.out.println("布尔类型 (boolean): " + booleanType);
System.out.println("字符串类型 (String): " + stringType);
System.out.println("长整型 (long): " + longType);
System.out.println("短整型 (short): " + shortType);
System.out.println("字节型 (byte): " + byteType);
System.out.println("==================================================");
}
public void ShowDataTypesInfo() {
System.out.println("==================================================");
System.out.println("基本类型byte 二进制位数:"+Byte.SIZE);
System.out.println("包装类java.lang.Byte");
System.out.println("最小值Byte.MIN_VALUE="+Byte.MIN_VALUE);
System.out.println("最大值Byte.MAX_VALUE="+Byte.MAX_VALUE);
System.out.println();
System.out.println("基本类型short 二进制位数:"+Short.SIZE);
System.out.println("包装类java.lang.Short");
System.out.println("最小值Short.MIN_VALUE="+Short.MIN_VALUE);
System.out.println("最大值Short.Max_Value="+Short.MAX_VALUE);
System.out.println();
System.out.println("基本类型int 二进制位数:"+Integer.SIZE);
System.out.println("包装类java.lang.Integer");
System.out.println("最小值Integer.MIN_VALUE="+Integer.MIN_VALUE);
System.out.println("最大值Integer.Max_Value="+Integer.MAX_VALUE);
System.out.println();
System.out.println("基本类型long 二进制位数:"+Long.SIZE);
System.out.println("包装类java.lang.Long");
System.out.println("最小值Long.MIN_VALUE="+Long.MIN_VALUE);
System.out.println("最大值Long.Max_Value="+Long.MAX_VALUE);
System.out.println();
System.out.println("基本类型float 二进制位数:"+Float.SIZE);
System.out.println("包装类java.lang.Float");
System.out.println("最小值Float.MIN_VALUE="+Float.MIN_VALUE);
System.out.println("最大值Float.Max_Value="+Float.MAX_VALUE);
System.out.println();
System.out.println("基本类型double 二进制位数:"+Double.SIZE);
System.out.println("包装类java.lang.Double");
System.out.println("最小值Double.MIN_VALUE="+Double.MIN_VALUE);
System.out.println("最大值Double.Max_Value="+Double.MAX_VALUE);
System.out.println();
System.out.println("基本类型char 二进制位数:"+Character.SIZE);
System.out.println("包装类java.lang.Character");
System.out.println("最小值Character.MIN_VALUE="+(int)Character.MIN_VALUE);
System.out.println("最大值Character.Max_Value="+(int)Character.MAX_VALUE);
System.out.println("==================================================");
}
}

View File

@@ -0,0 +1,43 @@
package smy.javastudy;
public class Main {
final double PI = 3.14159;
int decimal = 100;
int octal = 0144;
int hexa = 0x64;
//项目唯一主函数
public static void main(String[] args) {
//TIP 当文本光标位于高亮显示的文本处时按 <shortcut actionId="ShowIntentionActions"/>
// 查看 IntelliJ IDEA 建议如何修正。
System.out.printf("Hello and welcome!\n");
Main main = new Main();
main.testHuHangTao();
JavaBasicDataType dataType = new JavaBasicDataType();
dataType.ShowDataTypesInfo();
GrammarPractice grammarPractice = new GrammarPractice();
grammarPractice.Exchange("刘道熙");
grammarPractice.Exchange("唐伟");
grammarPractice.Exchange("树萌芽");
NumberAndMathDemo demo = new NumberAndMathDemo();
demo.numberClassUsage();
demo.mathClassUsage();
}
public void testHuHangTao(){
SWPUStudent HuHangTao = new SWPUStudent("胡航滔", 20, "2024520541", "网络工程", 3.8, "hht@stu.swpu.edu.cn", "12345678901", "四川省广安市", "");
HuHangTao.ShowInfo();
HuHangTao.setGpa(4.5);
HuHangTao.setEmail(HuHangTao.getStudentID() + "@stu.swpu.edu.cn");
HuHangTao.setPhoneNumber("18782345678");
HuHangTao.ShowInfo();
}
}

View File

@@ -0,0 +1,89 @@
package smy.javastudy;
import java.math.BigDecimal;
import java.math.BigInteger;
public class NumberAndMathDemo {
public void numberClassUsage() {
System.out.println("=========================Number类的用法=========================");
// Number 是一个抽象类,其子类包括 Integer、Double、Float 等。
// 我们可以用它来持有任何数字类型。
Number num1 = 123;
Number num2 = 456.78;
System.out.println("num1 是: " + num1 + ",类型是 " + num1.getClass().getName());
System.out.println("num2 是: " + num2 + ",类型是 " + num2.getClass().getName());
// xxxValue() 方法用于转换为基本数据类型
System.out.println("num1 作为 int: " + num1.intValue());
System.out.println("num1 作为 double: " + num1.doubleValue());
System.out.println("num2 作为 int: " + num2.intValue()); // 注意:这会截断小数部分
System.out.println("num2 作为 long: " + num2.longValue());
System.out.println("num2 作为 float: " + num2.floatValue());
System.out.println("num2 作为 byte: " + num2.byteValue());
System.out.println("num2 作为 short: " + num2.shortValue());
// compareTo() 方法 (来自 Comparable 接口, 由 Number 的子类实现)
Integer int1 = 100;
Integer int2 = 200;
System.out.println("比较 100 和 200: " + int1.compareTo(int2)); // 如果小于则为-1如果等于则为0如果大于则为1
// equals() 方法
Double double1 = 123.45;
Double double2 = 123.45;
System.out.println("用 equals() 比较 123.45 和 123.45: " + double1.equals(double2));
// 使用 BigInteger 和 BigDecimal 处理非常大的数字
BigInteger bigInt = new BigInteger("12345678901234567890");
BigDecimal bigDecimal = new BigDecimal("1234567890.0987654321");
System.out.println("BigInteger: " + bigInt);
System.out.println("BigDecimal: " + bigDecimal);
// 大数的算术运算
BigInteger bigIntSum = bigInt.add(new BigInteger("1"));
System.out.println("BigInteger 的和: " + bigIntSum);
BigDecimal bigDecimalProduct = bigDecimal.multiply(new BigDecimal("2.5"));
System.out.println("BigDecimal 的积: " + bigDecimalProduct);
System.out.println("=========================Number类的用法=========================");
}
public void mathClassUsage() {
System.out.println("\n=========================Math类的用法=========================");
double x = 45.6;
double y = -78.9;
double angle = 45.0;
// 基本算术方法
System.out.println(y + " 的绝对值是: " + Math.abs(y));
System.out.println(x + " 的向上取整是: " + Math.ceil(x)); // 向上取整
System.out.println(x + " 的向下取整是: " + Math.floor(x)); // 向下取整
System.out.println(x + " 的四舍五入是: " + Math.round(x)); // 四舍五入到最近的整数
System.out.println(x + "" + y + " 的最大值是: " + Math.max(x, y));
System.out.println(x + "" + y + " 的最小值是: " + Math.min(x, y));
// 指数和对数函数
System.out.println("e^2 是: " + Math.exp(2));
System.out.println("10 的自然对数是: " + Math.log(10));
System.out.println("100 的以10为底的对数是: " + Math.log10(100));
System.out.println("2^3 是: " + Math.pow(2, 3));
System.out.println("16 的平方根是: " + Math.sqrt(16));
// 三角函数
double radians = Math.toRadians(angle);
System.out.println(angle + " 度的正弦值是: " + Math.sin(radians));
System.out.println(angle + " 度的余弦值是: " + Math.cos(radians));
System.out.println(angle + " 度的正切值是: " + Math.tan(radians));
System.out.println("" + radians + " 弧度转换为度: " + Math.toDegrees(radians));
// 随机数生成
// Math.random() 返回一个大于等于 0.0 且小于 1.0 的 double 值
System.out.println("一个随机数: " + Math.random());
// 获取一个范围内的随机整数,例如 [1, 10]
int randomInt = (int) (Math.random() * 10) + 1;
System.out.println("一个 1 到 10 之间的随机整数: " + randomInt);
System.out.println("\n=========================Math类的用法=========================");
}
}

View File

@@ -1,4 +1,4 @@
package JavaBasicStudy;
package smy.javastudy;
public class SWPUStudent {
private String name; //学生姓名
@@ -11,6 +11,7 @@ public class SWPUStudent {
private String address; //住址
private String gender; //性别
//学生类构造函数
public SWPUStudent(String name, int age, String studentID, String major, double gpa, String email, String phoneNumber, String address, String gender) {
this.name = name;
this.age = age;
@@ -23,7 +24,7 @@ public class SWPUStudent {
this.gender = gender;
}
//展示学生基本信息
public void ShowInfo() {
System.out.println("==================================");
System.out.println("西南石油大学学生信息:");
@@ -42,6 +43,7 @@ public class SWPUStudent {
//======================对学生属性进行封装==================================
//姓名
public String getName() {
return name;
}
@@ -51,7 +53,7 @@ public class SWPUStudent {
}
//年龄
public int getAge() {
return age;
}
@@ -61,7 +63,7 @@ public class SWPUStudent {
}
//学生ID
public String getStudentID() {
return studentID;
}
@@ -71,7 +73,7 @@ public class SWPUStudent {
}
//专业
public String getMajor() {
return major;
}
@@ -81,7 +83,7 @@ public class SWPUStudent {
}
//学分绩点
public double getGpa() {
return gpa;
}
@@ -91,7 +93,7 @@ public class SWPUStudent {
}
//邮箱
public String getEmail() {
return email;
}
@@ -101,7 +103,7 @@ public class SWPUStudent {
}
//电话号码
public String getPhoneNumber() {
return phoneNumber;
}
@@ -111,7 +113,7 @@ public class SWPUStudent {
}
//家庭住址
public String getAddress() {
return address;
}
@@ -121,7 +123,7 @@ public class SWPUStudent {
}
//年龄
public String getGender() {
return gender;
}

View File

@@ -0,0 +1,27 @@
package smy.javastudy;
import java.lang.Number;
public class TestNumberClass {
//基本类型转换
public void typeConversion(){
Number num1 = 1234.56;
System.out.println(num1);
System.out.println(num1.getClass());
System.out.println(num1.intValue());
System.out.println(num1.longValue());
System.out.println(num1.doubleValue());
System.out.println(num1.floatValue());
System.out.println(num1.byteValue());
}
//数值比较
public void compareNum(){
Integer x = 10;
Double y = 10.0;
System.out.println(x.doubleValue()==y.doubleValue());
}
//处理大数
//public
}