增加文件

This commit is contained in:
JRNitre 2024-04-19 08:37:54 +08:00
parent 6aaa1e35c4
commit 922aa12ec5
4 changed files with 219 additions and 0 deletions

View File

@ -0,0 +1,36 @@
/*
* Function: 盒子类
* Date: 2024 04 18
* Code by: JRNitre
* */
package javaAssignment_20240418;
public class box {
double length;
double width;
double height;
public void setBox_length (double l){
length = l;
}
public void setBox_width (double w){
width = w;
}
public void setBox_height (double h){
height = h;
}
public void printVolume(){
System.out.println(height * width * length);
}
public static void main (String[] args){
box b_1 = new box();
b_1.setBox_height(5);
b_1.setBox_length(2);
b_1.setBox_width(3);
b_1.printVolume();
}
}

View File

@ -0,0 +1,44 @@
/*
* Function: 虚数和
* Date: 2024 04 18
* Code by: JRNitre
* */
package javaAssignment_20240418;
public class complex {
// 实部
private int realPart;
// 虚部
private int imaginePart;
// 无参构造方法
public complex() {
this.realPart = 0;
this.imaginePart = 0;
}
// 有参构造方法
public complex (int r, int i){
this.realPart = r;
this.imaginePart = i;
}
public complex complexAdd (complex a){
complex temp = new complex();
temp.realPart = this.realPart + a.realPart;
temp.imaginePart = this.imaginePart + a.imaginePart;
return temp;
}
public String ToString (){
return this.realPart + " + " + this.imaginePart + "i";
}
public static void main (String[] args){
complex c_1 = new complex(1,2);
complex c_2 = new complex(2,3);
complex c_out = c_1.complexAdd(c_2);
System.out.println(c_out.ToString());
}
}

View File

@ -0,0 +1,89 @@
/*
* Function: 学生类
* Date: 2024 04 18
* Code by: JRNitre
* */
package javaAssignment_20240418;
import java.util.Objects;
public class student {
private int studentID;
private String name;
private boolean gender;
private int age;
private int math;
private int english;
private int chinese;
public void addStudent_ID (int id){
this.studentID = id;
}
public void addStudent_name (String name){
this.name = name;
}
public void addStudent_gender (String Uin){
if (Objects.equals(Uin, "")){
this.gender = true;
}
if (Objects.equals(Uin, "")){
this.gender = false;
}
}
public void addStudent_age (int a){
this.age = a;
}
public void addStudent_math (int a){
this.math = a;
}
public void addStudent_english (int a){
this.english = a;
}
public void addStudent_chinese (int a){
this.chinese = a;
}
public int getStudent_sum (){
return this.math + this.english + this.chinese;
}
public double getStudent_average (){
return (double) getStudent_sum() / 3;
}
public void getStudentInfo (){
System.out.println("Student ID: " + this.studentID);
System.out.println("Student Name: " + this.name);
System.out.print("Student Gender: ");
if (Objects.equals(this.gender, true)){
System.out.println("");
} else{
System.out.println("");
}
System.out.println("Student Age: " + this.age);
System.out.println("Student Sum: " + getStudent_sum());
System.out.println("Student Average: " + getStudent_average());
}
public static void main (String[] args){
student s1 = new student();
s1.addStudent_ID(1234);
s1.addStudent_name("dog meat");
s1.addStudent_gender("");
s1.addStudent_age(15);
s1.addStudent_chinese(114);
s1.addStudent_english(5);
s1.addStudent_math(14);
s1.getStudentInfo();
}
}

View File

@ -0,0 +1,50 @@
/*
* Function: 二维数组和
* Date: 2024 04 18
* Code by: JRNitre
* */
package javaAssignment_20240418;
public class sumNum {
//
private int m;
//
private int n;
private int sum;
// 带参构造方法
public sumNum(int[][] array) {
this.m = array.length;
this.n = array[0].length;
int i, j;
for (i = 0; i < this.n; i++){
for (j = 0; j < this.m; j++){
this.sum += array[i][j];
}
}
}
public int getSum (){
return this.sum;
}
public int get_m (){
return this.m;
}
public int get_n (){
return this.n;
}
public static void main (String[] args){
int[][] s_array = {{1,2,3},{4,5,6},{7,8,9}};
sumNum s1 = new sumNum(s_array);
System.out.println("in " + s1.get_m() + " row and " + s1.get_n() + " column sum: ");
System.out.println(s1.getSum());
}
}