JAVA之学生信息

定义一个Student数组,其中保存学生的基本信息,包括姓名,学号,性别,还分别保存三门课程的成绩和对应学分。试编程计算这三门课程的学分积,并按学分积的降幂进行排序,输出排序后的结果。

public class Student { 
    /**成员变量:姓名,学号,性别,数学,英语,语文,数学学分,英语学分,语文学分,三门课程学分积
                   附加:按学分积降幂进行排序,输出结果
     */
   public float Math;//数学
   public float English;//英语
   public float Chinese;//语文
   public int MathCredit;//数学学分
   public int EnglishCredit;//英语学分
   public int ChineseCredit;//语文学分
   public float product;//学分积
   public String name;
   public String Id;
   public String sex;
 

    public static void main(String[] args) {//初始化数组  

        Student stu1=new Student(); {

            stu1.name="**";
            stu1.Id="***";
            stu1.sex="男";
            stu1.Math=70;
            stu1.MathCredit=5;
            stu1.English=73;
            stu1.EnglishCredit=4;
            stu1.Chinese=83;
            stu1.ChineseCredit=3;
            stu1.product=stu1.Math*stu1.MathCredit+stu1.English*stu1.EnglishCredit+stu1.Chinese*stu1.ChineseCredit;
            System.out.println("姓名 "+stu1.name);
            System.out.println("学号 "+stu1.Id);
            System.out.println("性别 "+stu1.sex);
            System.out.println("数学成绩 "+stu1.Math);
            System.out.println("数学学分 "+stu1.MathCredit);
            System.out.println("英语成绩 "+stu1.English);
            System.out.println("英语学分 "+stu1.EnglishCredit);
            System.out.println("物理成绩 "+stu1.Chinese);
            System.out.println("物理学分 "+stu1.ChineseCredit);
            System.out.println("学分积 "+stu1.product);

        }

  

        Student stu2=new Student();{

            stu2.name="***";
            stu2.Id="201730134002";
            stu2.sex="男";
            stu2.Math=73;
            stu2.MathCredit=5;
            stu2.English=72;
            stu2.EnglishCredit=4;
            stu2.Chinese=78;
            stu2.ChineseCredit=3;
            stu2.product=stu2.Math*stu2.MathCredit+stu2.English*stu2.EnglishCredit+stu2.Chinese*stu2.ChineseCredit;
            System.out.println("姓名 "+stu2.name);
            System.out.println("学号 "+stu2.Id);
            System.out.println("性别 "+stu2.sex);
            System.out.println("数学成绩 "+stu2.Math);
            System.out.println("数学学分 "+stu2.MathCredit);
            System.out.println("英语成绩 "+stu2.English);
            System.out.println("英语学分 "+stu2.EnglishCredit);
            System.out.println("物理成绩 "+stu2.Chinese);
            System.out.println("物理学分 "+stu2.ChineseCredit);
            System.out.println("学分积 "+stu2.product);
        }
  

        Student stu3=new Student();{

            stu3.name=***";

            stu3.Id="201730134031";
            stu3.sex="女";
            stu3.Math=75;
            stu3.MathCredit=5;
            stu3.English=85;
            stu3.EnglishCredit=4;
            stu3.Chinese=86;
            stu3.ChineseCredit=3;
            stu3.product=stu3.Math*stu3.MathCredit+stu3.English*stu3.EnglishCredit+stu3.Chinese*stu3.ChineseCredit;
            System.out.println("姓名 "+stu3.name);
            System.out.println("学号 "+stu3.Id);
            System.out.println("性别 "+stu3.sex);
            System.out.println("数学成绩 "+stu3.Math);
            System.out.println("数学学分 "+stu3.MathCredit);
            System.out.println("英语成绩 "+stu3.English);
            System.out.println("英语学分 "+stu3.EnglishCredit);
            System.out.println("物理成绩 "+stu3.Chinese);
            System.out.println("物理学分 "+stu3.ChineseCredit);
            System.out.println("学分积 "+stu3.product);

        }



        Student stu4=new Student();{

            stu4.name="***";
            stu4.Id="201730134047";
            stu4.sex="男";
            stu4.Math=90;
            stu4.MathCredit=5;
            stu4.English=90;
            stu4.EnglishCredit=4;
            stu4.Chinese=86;
            stu4.ChineseCredit=3;
            stu4.product=stu4.Math*stu4.MathCredit+stu4.English*stu4.EnglishCredit+stu4.Chinese*stu4.ChineseCredit;
            System.out.println("姓名 "+stu4.name);
            System.out.println("学号 "+stu4.Id);
            System.out.println("性别 "+stu4.sex);
            System.out.println("数学成绩 "+stu4.Math);
            System.out.println("数学学分 "+stu4.MathCredit);
            System.out.println("英语成绩 "+stu4.English);
            System.out.println("英语学分 "+stu4.EnglishCredit);
            System.out.println("物理成绩 "+stu4.Chinese);
            System.out.println("物理学分 "+stu4.ChineseCredit);
            System.out.println("学分积 "+stu4.product);

         }

        System.out.print("学分积依次为:"+stu1.product+"  "+stu2.product+"  "+stu3.product+"  "+stu4.product);

  

        Student students[]=new Student[4];{

        students[0]=stu1;
        students[1]=stu2;
        students[2]=stu3;
        students[3]=stu4;

        }

        System.out.println("学分积降幂排序为:"+"\n");
  
        for(int i=0;i<students.length;i++) {

            for(int j=i;j<students.length;j++) {

                if(students[i].product<students[j].product){

                    float temp=0;

                    temp=students[i].product;
                    students[i].product=students[j].product;
                    students[j].product=temp;
                } 
            }
            System.out.println("学分积降幂排序的结果为:"+students[i].product);

        }

    } 

  }

  • 3
    点赞
  • 44
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq-120

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值