This commit is contained in:
2025-09-12 11:09:13 +08:00
parent 240ecb0fff
commit 4264c76aa8
6 changed files with 203 additions and 0 deletions

5
HelloWorld/Hello.java Normal file
View File

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

BIN
HelloWorld/HelloWorld.class Normal file

Binary file not shown.

View File

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

View File

@@ -0,0 +1,27 @@
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

@@ -0,0 +1,25 @@
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);
}
}

View File

@@ -0,0 +1,135 @@
package JavaBasicStudy;
public class SWPUStudent {
private String name; //学生姓名
private int age; //学生年龄
private String studentID; //学号
private String major; //专业
private double gpa; //绩点
private String email; //电子邮件
private String phoneNumber; //电话号码
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;
this.studentID = studentID;
this.major = major;
this.gpa = gpa;
this.email = email;
this.phoneNumber = phoneNumber;
this.address = address;
this.gender = gender;
}
public void ShowInfo() {
System.out.println("==================================");
System.out.println("西南石油大学学生信息:");
System.out.println("姓名: " + name);
System.out.println("年龄: " + age);
System.out.println("学号: " + studentID);
System.out.println("专业: " + major);
System.out.println("绩点: " + gpa);
System.out.println("电子邮件: " + email);
System.out.println("电话号码: " + phoneNumber);
System.out.println("住址: " + address);
System.out.println("性别: " + gender);
System.out.println("==================================");
}
//======================对学生属性进行封装==================================
public String getName() {
return name;
}
public String setName(String name) {
return this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getStudentID() {
return studentID;
}
public void setStudentID(String studentID) {
this.studentID = studentID;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public double getGpa() {
return gpa;
}
public void setGpa(double gpa) {
this.gpa = gpa;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
//======================对学生属性进行封装==================================
}