按照题目要求编写的Java程序如下(注意 以下程序全部放在Mainjava文件中)
class student{
String name;
int score;
public student(String name,int score){
thisname=name;
thisscore=score;
}
String studentInfo(){
return "name="+thisname+",score="+thisscore;
}
}
public class Main{
public static void main(String[] args){
student sty[]=new student[5];
sty[0]=new student("zhangsan",67);
sty[1]=new student("lisi",75);
sty[2]=new student("wangwu",57);
sty[3]=new student("zhaoliu",88);
sty[4]=new student("ruanqi",93);
student stu[]=new student[5];
for(int i=0;i<stylength;i++){
stu[i]=sty[i];
}
for(int i=0;i<stulength-1;i++){
for(int j=0;j<stulength-i-1;j++){
if(stu[j]score<stu[j+1]score){
student temp=stu[j];
stu[j]=stu[j+1];
stu[j+1]=temp;
}
}
}
for(int i=0;i<stulength;i++){
Systemoutprintln(stu[i]studentInfo());
}
}
}
public class Student { //定义一个学生类
private int StuNum; //学号
private int Class; //班级
private char Gender; //性别
private int Age; //年龄
public Student(int StuNum, int Class, char Gender, int Age){//构造函数
thisstuNum = StuNum;
thisclass = Class;
thisgender = Gender;
thisage = Age;
}
public int getStuNum() { //获得学号
return StuNum;
}
public int getClass() { //获得班级号
return Class;
}
public char getGender() { //获得性别
return Gender;
}
public void setGender(char Gender) { //修改性别
thisGender = Gender;
}
public int getAge() { //获得年龄
return Age;
}
public void setAge(int Age) { //修改年龄
thisAge = Age;
}
public class Pupil extends Student //小学生
{
//(由于没说派生后要新加什么东西,所以这里写了省略号,如果想在
// 新派生出来的类里加点什么特殊的东西,直接在省略号位置加就行了
// 下同)
}
public class MidSchoolStu extends Student //中学生
{
//
}
public class UnderGraduate extends Student //大学生
{
//
}
public class PostGraduate extends Student //研究生
{
//
}
public class FreshStudent extends UnderGraduate //一年级学生
{
//
}
public class Sophomore extends UnderGraduate //二年级学生
{
//
}
public class Junior extends UnderGraduate //三年级学生
{
//
}
public class Senior extends UnderGraduate //四年级学生
{
//
}
public class Master extends PostGraduate //硕士生
{
//
}
public class Doctor extends PostGraduate //博士生
{
//
}
#include<iostream>
#include<string>
using namespace std;
class student
{
private:
int school_Number;
string name;
double grade;
public:
student(int school_Number,string name,double grade)
{
this->school_Number=school_Number;
this->name=name;
this->grade=grade;
}
void showall()
{
cout<<"the school_Number is "<<school_Number<<endl;
cout<<"the name is "<<name<<endl;
cout<<"the grade is "<<grade<<endl;
}
void change_schoolnumber()
{
cout<<"please input the new schoolNumber"<<endl;
cin>>school_Number;
}
void change_name()
{
cout<<"please input the new name"<<endl;
cin>>name;
}
void change_grade()
{
cout<<"please input the new grade"<<endl;
cin>>grade;
}
};
int main()
{
student man(100,"xiaoming",98);
manshowall();
manchange_schoolnumber();
manchange_name();
manchange_grade();
manshowall();
return 0;
}
实在不知道你的验证访问权限是啥,用C++写的额
return "name = " + name + " stuNum = " + stuNum + " chineseScore = " + chineseScore + " mathScore = " + mathScore + " englishScore = " + englishScore;}//设置姓名public void setName(String name){thisname = name;}//设置学号public void setStuNum(String stuNum){thisstuNum = stuNum;}//设置语文成绩public void setChineseScore(double chineseScore){thischineseScore = chineseScore;}//设置数学成绩public void setMathScore(double mathScore){thismathScore = mathScore;}//设置英语成绩public void setEnglishScore(double englishScore){thisenglishScore = englishScore;}//求总成绩public double getTotalScore(){return chineseScore + mathScore + englishScore;}//求平均成绩
代码已经编译通过
import javautil;
public class MainClass_StudentInfor{
public static void main(String args[]){
boolean e=true;
Student stu=new Student();
Scanner sc=new Scanner(Systemin);
while(e){
Systemoutprintln("\t\t\t\t\t欢迎进入学生信息系统\t\t\t\t\t");
Systemoutprintln("\t\t\t\t\t 1:录入学生的信息\t\t\t\t\t");
Systemoutprintln("\t\t\t\t\t2:输出信息\t\t\t\t\t");
Systemoutprintln("\t\t\t\t\t3:求总分\t\t\t\t\t");
Systemoutprintln("\t\t\t\t\t4求均分\t\t\t\t\t");
Systemoutprintln("\t\t\t\t\t5:成绩排序\t\t\t\t\t");
Systemoutprintln("\t\t\t\t\t6:检索成绩\t\t\t\t\t");
Systemoutprintln("\t\t\t\t\t7:求最大值和最小值\t\t\t\t\t");
Systemoutprintln("\t\t\t\t\t8:结束程序 \t\t\t\t\t");
try{
byte b=scnextByte();
switch(b){
case 1:
stuinputInfo();break;
case 3:
stugetSum();break;
case 4:
stugetAver();break;
case 2:
stuprintInfo();break;
case 5:
stusort();break;
case 6:
stuindex();break;
case 7:
stuindexBL();break;
case 8:
e=false;
}
}
catch(NullPointerException f){
fprintStackTrace();
Systemoutprintln("请正确 *** 作");
}
}
}
}
enum Sex{
男,女
}
class Student{
int number;
Sex a;
String name;
float sum=0;
float average;
float score[];
String subject[]={"高数","英语","C语言"};
void inputInfo(){//录入学生基本信息
Scanner sc=new Scanner(Systemin);
Systemoutprintln("请输入学号 :");
number=scnextInt();
Systemoutprintln("请输入姓名 :");
name=scnext();
Systemoutprintln(" 请输入性别 1:男,2:女");
int x=scnextInt();
if(x==1)
{
a=Sex男;
}
else
{
a=Sex女;
}
Systemoutprintln("请输入高数,英语,c语言的成绩:");
score=new float[3];
for(int i=0;i<=2;i++)
{
score[i]=scnextFloat();
Systemoutprintln(subject[i]+":"+score[i]);
}
}
void printInfo(){//输出学生基本信息
Systemoutprintln("学号:"+number);
Systemoutprintln("姓名:"+name);
Systemoutprintln("性别:"+a);
for(int i=0;i<3;i++){
Systemoutprintln(subject[i]+":"+score[i]);
}
}
void getSum(){
for(int i=0;i<=2;i++)
{
sum=sum+score[i];
}
Systemoutprintln(" 学生的总分:"+sum);
}
void getAver(){
for(int i=0;i<=2;i++){
sum=sum+score[i];
}
average=sum/3;
Systemoutprintln(" 学生的平均成绩:"+average);
}
void sort(){//排序
Arrayssort(score);
Systemoutprintln("学生的成绩排序为:"+ArraystoString(score));
}
void index(){//查询成绩
boolean n=true;
while(n){
Scanner sc=new Scanner(Systemin);
Systemoutprintln("请输入,1检索开始,2检索结束");
int m=scnextInt();
switch(m){
case 1:
Systemoutprintln("请输入您要查找那门课的成绩0:高数;1:英语:2:C语言");
Scanner sc1=new Scanner(Systemin);
int c=sc1nextInt();
Systemoutprintln(subject[c]+score[c]);
Systemoutprintln("您是否还要查找其他科目的成绩");
break;
case 2:
n=false;
}
}
}
void indexBL(){
float biggest=0;
float lowest=100;
for(int i=0;i<3;i++){
if(biggest<=score[i]){
biggest=score[i];
}
if(lowest>=score[i]){
lowest=score[i];
}
}
Systemoutprintln("该生的最高成绩是"+biggest);
Systemoutprintln("该生的最低成绩是"+lowest);
}
}
以上就是关于设计一个给班级学生成绩排序的java程序,具体要求如下全部的内容,包括:设计一个给班级学生成绩排序的java程序,具体要求如下、Java程序设计,定义一个表示学生的类Student、急求c++程序编程定义学生类的程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)