package zuoye0924;
public class Student {//定义一个学生类,包括学号,姓名,三科成绩
//属性和方法
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 zuoye0924;
public class TestStudent {
private static Student[] stu;//声明对象数组
public static void main(String[] args) {
stu=new Student[5];//实例化对象数组
stu[0]=new Student("111","aaaa",30,80,70);
stu[1]=new Student("222","aabb",60,80,20);
stu[2]=new Student("333","bbcc",40,80,70);
stu[3]=new Student("444","ddee",30,30,70);
stu[4]=new Student("555","ffgg",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();
}
}
package zuoye0924;
public class Swap {
private int num;
//定义一个变量
//setter,getter方法
public int getNum() {
return num;
}
public Swap(int num) {
super();
this.num = num;
}
public void setNum(int num) {
this.num = num;
}
}
package zuoye0924;
/**
*
* @author Administrator
* 测试两个变量交换,方法传参
*/
public class TestChange {
public static void main(String[] args) {
//实例化两个Swap对象
Swap s1=new Swap(10);
Swap s2=new Swap(100);
swap(s1,s2);
System.out.println(s1.getNum());
System.out.println(s2.getNum());
}
public static void swap(Swap s1, Swap s2) {
/*int temp=s1.getNum();
s1.setNum(s2.getNum());
s2.setNum(temp);*/
Swap temp=s1;
s1=s2;
s2=temp;
}
}
##
作业二