java作业求解,在线等。
定义一个Student数组,其中保存学生的基本信息,包括姓名、学号、性别,还分别保存三门课程及三门课程对应的学分,试编程计算着三门课程的学分积,并按学分积的降幂进行排序,...
定义一个Student数组,其中保存学生的基本信息,包括姓名、学号、性别,还分别保存三门课程及三门课程对应的学分,试编程计算着三门课程的学分积,并按学分积的降幂进行排序,输出排序后的结果。
class StudentClass{
String classid;
int credit;
StudentClass(String classid,int credit){
this.classid=classid;
this.credit=credit;
}
}
public class StudentInfo {
String sid;
String sname;
char sex;
float avgscore;
float[] score = new float[3];
public StudentInfo() {
super();
}
StudentInfo(String id, String name, char sex, float s1, float s2, float s3) {
this.sid = id;
this.sname = name;
this.sex = sex;
this.score[0] = s1;
this.score[1] = s2;
this.score[2] = s3;
}
static class StuScore {
StudentInfo[] st = new StudentInfo[5];
StudentClass[] sc = new StudentClass[3];
public StuScore() {
super();
}
void initStudentClass() {
sc[0] = new StudentClass("语文", 5);
sc[1] = new StudentClass("数学", 3);
sc[2] = new StudentClass("自然科学", 4);
}
void initStudentInfo() {
st[0] = new StudentInfo("20110023001", "王莹", '女', 100, 100, 100);
st[1] = new StudentInfo("20116546045", "杨子青", '男', 67, 71, 80);
st[2] = new StudentInfo("20115641452", "王溪", '女', 91, 93, 90);
st[3] = new StudentInfo("20111421242", "二孩", '男', 57, 76, 74);
st[4] = new StudentInfo("20119751452", "王夏瑾", '女', 76, 85, 80);
}
void accuScore() {
float as = 0;
int cs = 0;
for (int i = 0; i < st.length; i++) {
for (int j = 0; j < sc.length; j++) {
as += sc[j].credit * st[i].score[j];
cs += sc[j].credit;
}
st[i].avgscore = (float) (as / cs);
}
}
void sortScore() {
StudentInfo tmp = new StudentInfo();
for (int i = 0; i < st.length; i++) {
for (int j = i + 1; j < st.length; j++) {
if (st[i].avgscore < st[j].avgscore) {
tmp = st[i];
st[i] = st[j];
st[j] = tmp;
}
}
}
}
void print() {
System.out.println("-------------------------------");
System.out.println("学生信息如下:");
System.out.println("-------------------------------");
for (int i = 0; i < st.length; i++) {
}
}
void print2() {
System.out.println("-------------------------------");
System.out.println("学生成绩排名信息如下:");
System.out.println("-------------------------------");
for (int i = 0; i < st.length; i++) {
}
}
}
public static void main(String[] args) {
StuScore stc = new StuScore();
stc.initStudentClass();
stc.initStudentInfo();
stc.accuScore();
stc.print();
stc.sortScore();
stc.print2();
}
}
输不出答案不知道怎么回事。 展开
class StudentClass{
String classid;
int credit;
StudentClass(String classid,int credit){
this.classid=classid;
this.credit=credit;
}
}
public class StudentInfo {
String sid;
String sname;
char sex;
float avgscore;
float[] score = new float[3];
public StudentInfo() {
super();
}
StudentInfo(String id, String name, char sex, float s1, float s2, float s3) {
this.sid = id;
this.sname = name;
this.sex = sex;
this.score[0] = s1;
this.score[1] = s2;
this.score[2] = s3;
}
static class StuScore {
StudentInfo[] st = new StudentInfo[5];
StudentClass[] sc = new StudentClass[3];
public StuScore() {
super();
}
void initStudentClass() {
sc[0] = new StudentClass("语文", 5);
sc[1] = new StudentClass("数学", 3);
sc[2] = new StudentClass("自然科学", 4);
}
void initStudentInfo() {
st[0] = new StudentInfo("20110023001", "王莹", '女', 100, 100, 100);
st[1] = new StudentInfo("20116546045", "杨子青", '男', 67, 71, 80);
st[2] = new StudentInfo("20115641452", "王溪", '女', 91, 93, 90);
st[3] = new StudentInfo("20111421242", "二孩", '男', 57, 76, 74);
st[4] = new StudentInfo("20119751452", "王夏瑾", '女', 76, 85, 80);
}
void accuScore() {
float as = 0;
int cs = 0;
for (int i = 0; i < st.length; i++) {
for (int j = 0; j < sc.length; j++) {
as += sc[j].credit * st[i].score[j];
cs += sc[j].credit;
}
st[i].avgscore = (float) (as / cs);
}
}
void sortScore() {
StudentInfo tmp = new StudentInfo();
for (int i = 0; i < st.length; i++) {
for (int j = i + 1; j < st.length; j++) {
if (st[i].avgscore < st[j].avgscore) {
tmp = st[i];
st[i] = st[j];
st[j] = tmp;
}
}
}
}
void print() {
System.out.println("-------------------------------");
System.out.println("学生信息如下:");
System.out.println("-------------------------------");
for (int i = 0; i < st.length; i++) {
}
}
void print2() {
System.out.println("-------------------------------");
System.out.println("学生成绩排名信息如下:");
System.out.println("-------------------------------");
for (int i = 0; i < st.length; i++) {
}
}
}
public static void main(String[] args) {
StuScore stc = new StuScore();
stc.initStudentClass();
stc.initStudentInfo();
stc.accuScore();
stc.print();
stc.sortScore();
stc.print2();
}
}
输不出答案不知道怎么回事。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询