student

package Zuoye;
public class Student {//定义一个学生类,包括学号,姓名,三科成绩
/**

@author 许先漂
*/
//属性和方法
private String number;
private String name;
private int englishScore;
private int mathScore;
private int sportsScore;
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getEnglishScore() {
return englishScore;
}
public void setEnglishScore(int englishScore) {
this.englishScore = englishScore;
}
public int getMathScore() {
return mathScore;
}
public void setMathScore(int mathScore) {
this.mathScore = mathScore;
}
public int getSportsScore() {
return sportsScore;
}
public void setSportsScore(int sportsScore) {
this.sportsScore = sportsScore;
}
public Student(String number, String name, int englishScore, int mathScore, int sportsScore) {
super();
this.number = number;
this.name = name;
this.englishScore = englishScore;
this.mathScore = mathScore;
this.sportsScore = sportsScore;
}
@Override
public String toString() {
return “Student [number=” + number + “, name=” + name + “, englishScore=” + englishScore + “, mathScore=”
+ mathScore + “, sportsScore=” + sportsScore + “]”;
}

}

package Zuoye;

public class TestStudent {
private static Student[] stu;//声明对象数组
public static void main(String[] args) {
stu=new Student[5];//实例化对象数组
stu[0]=new Student(“111”,“李四”,30,80,70);
stu[1]=new Student(“222”,“张三丰”,60,80,20);
stu[2]=new Student(“333”,“王五”,40,80,70);
stu[3]=new Student(“444”,“张三”,30,30,70);
stu[4]=new Student(“555”,“张无忌”,30,80,20);
search(“a”);
searchfail();
}
/*
* 根据姓名查找成绩
*/
public static void search(String name) {
for(int i=0;i<stu.length;i++){
//哪个学生的姓名中包括…
if(stu[i].getName().contains(name)){
System.out.println(stu[i]);
}
}

}
/*
 * 查找成绩不及格的人数
 */
public static void searchfail() {
	System.out.println("英语的不及格有:");
	int a=0;
	for(int i=0;i<stu.length;i++){
		if(stu[i].getEnglishScore()<60){
			System.out.print(stu[i].getName()+",");
			a++;
		}
		
	}
	System.out.print(a);
	System.out.println();
	System.out.println("数学的不及格有:");
	int b=0;
	for(int i=0;i<stu.length;i++){
		if(stu[i].getMathScore()<60){
			System.out.print(stu[i].getName()+",");
			b++;
		}
	
	}
	System.out.print(b);
	System.out.println();
	
	System.out.println("体育的不及格有:");
	int c=0;
	for(int i=0;i<stu.length;i++){
		if(stu[i].getSportsScore()<60){
			System.out.print(stu[i].getName()+",");
			c++;
		}
		
	}
	System.out.print(c);
	System.out.println();
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值