小小

1.编写“学生”类及其测试类。

5.1 “学生”类:

²   类名:Student

²   属性:姓名、性别、年龄、学号、5门课程的成绩

²   方法1:在控制台输出各个属性的值、

²   方法2:计算平均成绩

²   方法3:输出各个属性的值和平均成绩

5.2 测试类

²   创建2个对象,调用方法

package 学生;

public class TestStudent {

 public static void main(String[] args) {      

Student p1=new Student();   Student p2=new Student();      

              p1.name="陈独秀";   

              p1.sex="男";        

              p1.age=18;

             p1.num="201801452200";

        System.out.println("姓名:"+p1.name+"性别:"+p1.sex+"年龄:"+p1.age+"学号:"+p1.num+"");        

        System.out.println("\n");                

       int score1[]=new int[]{80,85,90,95,70};        

       int s=0;    

      for(int i=0;i<5;i++){     

      s=s+score1[i];      

       System.out.println("成绩为:"+score1[i]);        

}        

      System.out.println("平均分为:"+s/5);

        p2.name="李斯";     

       p2.sex="男";    

       p2.age=25;     

       p2.num="201801420266";

        System.out.println("姓名:"+p2.name+"性别:"+p2.sex+"年龄:"+p2.age+"学号:"+p2.num+"");      

     int score2[]=new int[]{91,87,62,77,88};        

     float j=0;      

    for(int i=0;i<5;i++){      

    j=j+score2[i];       

   System.out.println("成绩为:"+score2[i]);         }     

   System.out.println("平均分为:"+j/5);                   

     }

}

猜你喜欢

转载自www.cnblogs.com/qq602671387/p/10735020.html