首页 > 电脑 > 设计学生类Student,学生有姓名name、学号sno、成绩score

设计学生类Student,学生有姓名name、学号sno、成绩score

电脑 2023-10-05

创建学生信息类Student,含学号(no)、姓名(name)、成绩(score)3个属性

select avg(sum(score))from Student;平均分 select name,score from Stusent where score>avg(sum(score));成绩不低于平均分

java:定义学生类Student, 其中属性有 name, id, score ,分别表示姓名,学好,成绩.....

定义一个表示学生信息的类Student,要求如下:

(1)类Student的成员变量:

sNO 表示学号;sName表示姓名;sSex表示性别;sAge表示年龄;sJava:表示Java课程成绩。

(2)类Student带参数的构造方法:

在构造方法中通过形参完成对成员变量的赋值操作。

(3)类Student的方法成员:

getNo():获得学号;

getName():获得姓名;

getSex():获得性别;

getAge()获得年龄;

getJava():获得Java课程成绩

(4)根据类Student的定义,创建五个该类的对象,输出每个学生的信息,计算并输出这五个学生Java语言成绩的平均值,以及计算并输出他们Java语言成绩的最大值和最小值。*/

class student{

String sNO,sName,sSex;

int sAge;

double sJava;

public student(String a,String b,String c,int d ,double e){

sNO=a;

sName=b;

sSex=c;

sAge=d;

sJava=e;}

String getNo(){

return sNO;}

String getName(){

return sName;}

String getSex(){

return sSex;}

int getAge(){

return sAge;}

double getJava(){

return sJava;}

void show(){

System.out.println("姓名:"+getName());

System.out.println("学号:"+getNo());

System.out.println("性别:"+getSex());

System.out.println("年龄:"+getAge());

System.out.println("Java成绩:"+getJava());}

}

public class chengji{

public static void main(String[] args){

double avrage,K1,K2,K3,K4,K5;

student A1=new student("13190310","李一","男",18,80);

student A2=new student("13190311","刘二","女",19,83);

student A3=new student("13190312","张三","男",19,82);

student A4=new student("13190313","杨四","女",20,88);

student A5=new student("13190314","韩舞","女",20,90);

A1.show();

System.out.println();

A2.show();

System.out.println();

A3.show();

System.out.println();

A4.show();

System.out.println();

A5.show();

System.out.println();

K1=A1.getJava();

K2=A2.getJava();

K3=A3.getJava();

K4=A4.getJava();

K5=A5.getJava();

avrage=(K1+K2+K4+K3+K5)/5;

System.out.println("Java平均成绩:"+avrage);

double a[]={K1,K2,K3,K4,K5};

double max=0,min=0,ck;

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

max=K1;

if(max

ck=max;

max=a[i+1];

a[i+1]=ck;} }

System.out.println("Java的最高分为:"+max);

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

max=K1;

if(min>a[i+1]){

ck=min;

min=a[i+1];

a[i+1]=ck;}

}

System.out.println("Java的最低分为:"+max);

}

}

使用面向对象思想,定义一个学生类Student,该类包括以下字段:姓名name,学号stuNo和成绩score。

packagecom.test;
publicclassStudent{
publicStringname;
publicStringstuNo;
publicfloatscore;
publicStudent(Stringname,StringstuNo,floatscore){
this.name=name;
this.stuNo=stuNo;
this.score=score;
}
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicStringgetStuNo(){
returnstuNo;
}
publicvoidsetStuNo(StringstuNo){
this.stuNo=stuNo;
}
publicfloatgetScore(){
returnscore;
}
publicvoidsetScore(floatscore){
this.score=score;
}
}
publicclassTestStudent{
publicstaticvoidmain(String[]args){
//TODOAuto-generatedmethodstub
Students1=newStudent("Jack","1001",67);
Students2=newStudent("Rose","1002",89);
Students3=newStudent("James","1003",45);
Students4=newStudent("Lucy","1004",95);
Students5=newStudent("Anna","1005",80);

Student[]sArr={s1,s2,s3,s4,s5};
System.out.println("姓名"+"\t"+"学号"+"\t"+"成绩");
for(inti=0;i{
Students=sArr[i];

System.out.println(s.getName()+"\t"+s.stuNo+"\t"+s.score);
}
}
}

设计一个类Student,该类包括姓名,学号和成绩。设计一个方法,按照成绩从高到低顺序输出姓名,学

publicclassStudent{
privateintid;//学号
privateStringname;//姓名
privateintscore;//成绩
publicStudent(intid,Stringname,intscore){
super();
this.id=id;
this.name=name;
this.score=score;
}

publicintgetId(){
returnid;
}
publicvoidsetId(intid){
this.id=id;
}
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicintgetScore(){
returnscore;
}
publicvoidsetScore(intscore){
this.score=score;
}
@Override
publicStringtoString(){
return(id+""+name+""+score);
}

}
importjava.util.Arrays;
publicclassTestStudent{
staticStudent[]stus;
publicstaticvoidsort(Student[]stus){
intlen=stus.length;//学生个数
int[]a=newint[len];
//记录分数
for(inti=0;ia[i]=stus[i].getScore();
}

Arrays.sort(a);//升序排序

for(inti=a.length-1;i>=0;i--){
for(intj=0;jif(stus[j].getScore()==a[i]){
System.out.println(stus[j]);
}
}
}
}
publicstaticvoidmain(String[]args){
stus=newStudent[3];
stus[0]=newStudent(1,"a",87);
stus[1]=newStudent(2,"b",78);
stus[2]=newStudent(3,"c",99);
System.out.println("按分数从高到低排序:");
sort(stus);
}
}

按分数从高到低排序:
3 c 99
1 a 87
2 b 78

望采纳哦,亲!

.设计一个学生成绩管理系统,能输入学生的学号、姓名和成绩等数据,能按成绩从高到低进行排序,并能将排序

#include #include #include #include #include #include class student; class student { public: student(){name[10]=NULL;} float num; int age; float score; char name[10]; }; /////////////////////////////////////////////////////// int i

标签:编程 姓名 学号 信息技术 score

大明白知识网 Copyright © 2020-2022 www.wangpan131.com. Some Rights Reserved. 京ICP备11019930号-18