17 soft work 2 shifts Ningyi Jian Student Management JAVA second job

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/xixihahah574/article/details/101634764

(1) the value transfer

package com.nyj;
/**
 * 值传递
 * @author 宁一健
 *
 */

public class Chuandi {

	public static void main(String[] args) {
		int[] a = new int[]{3,5};
		System.out.println(a[0] + "+" + a[1]);
		swap(a);
		System.out.println(a[0] + "+" + a[1]);
	}
	private static void swap(int[] a) {
		int temp = a[0];
		a[0] = a[1];
		a[1] = temp;
	}

}

(2) Student Management Code

package com.nyj;
/**
 * 
 * @author 宁一健
 *
 */

public class Student {
	private int number;
	private String name;
	private double English;
	private double mathematics;
	private double sports;
	public Student(){
		
	}
	public Student(int number,String name,double English,double mathematics,double sports){
		this.number=number;
		this.name=name;
		this.English=English;
		this.mathematics=mathematics;
		this.sports=sports;
		
	}
	public void setNumber(int number){
		this.number=number;
	}
	public int getNumber(){
		return number;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public double getEnglish() {
		return English;
	}
	public void setEnglish(double english) {
		English = english;
	}
	public double getMathematics() {
		return mathematics;
	}
	public void setMathematics(double mathematics) {
		this.mathematics = mathematics;
	}
	public double getSports() {
		return sports;
	}
	public void setSports(double sports) {
		this.sports = sports;
	}
	@Override
	public String toString() {
		return "Student [number=" + number + ", name=" + name + ", English=" + English + ", mathematics=" + mathematics
				+ ", sports=" + sports + "]";
	}
	


}

package com.nyj;
/**
 * 
 * @author 宁一健
 *
 */

public class StudentManager {
	public void findName(String n,Student[] st){
		for(int i=0;i<st.length;i++){
			if((st[i].getName()).contains(n)){
				System.out.println("查询到的人有"+st[i].toString());
			}
		}
	}
	public void findFail(Student[] st){
		int num = 0,num2 = 0,num3 = 0;
		System.out.print("英语不及格的有 :");
		for(int i=0;i<st.length;i++){
			if(st[i].getEnglish()<60){
				num++;
				System.out.print(st[i].getName()+"、");
			}
		}
		System.out.println("总共有"+num+"人");
		System.out.print("数学不及格的有 :");
		for(int i=0;i<st.length;i++){
			if(st[i].getMathematics()<60){
				num2++;
				System.out.print(st[i].getName()+"、");
			}
		}
		System.out.println("总共有"+num2+"人");
		System.out.print("体育不及格的有 :");
		for(int i=0;i<st.length;i++){
			if(st[i].getSports()<60){
				num3++;
				System.out.print(st[i].getName()+"、");
			}
		}
		System.out.println("总共有"+num3+"人");
	}
	

}

package com.nyj;
/**
 * 
 * @author 宁一健
 *
 */

public class StudentTest {
	public static void main(String[] args) {
		Student[] st = new Student[5];
		StudentManager student= new StudentManager();
		Student s1 = new Student(1, "黄一", 50, 60, 75);
		Student s2 = new Student(2, "赵二", 65, 77, 20);
		Student s3 = new Student(3, "张三", 55, 78, 67);
		Student s4 = new Student(4, "李四", 84, 42, 47);
		Student s5 = new Student(5, "王五", 26, 59, 76);
		st[0] = s1;
		st[1] = s2;
		st[2] = s3;
		st[3] = s4;
		st[4] = s5;
		student.findName("一", st);
		student.findFail(st);
	}

}

Guess you like

Origin blog.csdn.net/xixihahah574/article/details/101634764