java基础题求助,要代码,在线等

2024-11-27 15:26:48
推荐回答(5个)
回答(1):

//==========================第一题:Lab10Q6.java=======================//
/**
第一题:
写一段程序统计学生考试单选题的正确率。
1.8个学生。10道单选题。
2.学生答案是存储在一个二维数组的。
3。每一行记录一个学生的答案。
4.正确答案存储在一个一位数组里如下
0 1 2 3 4 5 6 7 8 9
key D B D C C D A E A D
5.学生答案如下
Student0 A B A C C D E E A D
Student1 D B A B C A E E A D
Student2 E D D A C B E E A D
Student3 C B A E D C E E A D
Student4 A B D C C D E E A D
Student5 B B E C C D E E A D
Student6 B B A C C D E E A D
Student7 E B E C C D E E A D
*/
public class Lab10Q6 {
public static void main(String[] args) {
int amou = 8;
int len = 10;
char[][] ans = new char[amou][len];
ans[0] = toArray("Student0 A B A C C D E E A D",8);
ans[1] = toArray("Student1 D B A B C A E E A D",8);
ans[2] = toArray("Student2 E D D A C B E E A D",8);
ans[3] = toArray("Student3 C B A E D C E E A D",8);
ans[4] = toArray("Student4 A B D C C D E E A D",8);
ans[5] = toArray("Student5 B B E C C D E E A D",8);
ans[6] = toArray("Student6 B B A C C D E E A D",8);
ans[7] = toArray("Student7 E B E C C D E E A D",8);

char[] keys = toArray("key D B D C C D A E A D",3);

for(int i=0; i int c = cre(ans[i],keys);
System.out.println("Student "+i+"'s correct count is "+c+".");
}
}
private static int cre(char[] s,char[] k){
int c =0;
for(int i=0; i if(s[i]==k[i])++c;
return c;
}
private static char[] toArray(String s,int off){
return s.replaceAll(" ","").substring(off).toCharArray();
}
}
//===========================第二题:TestStudent.java=========================//
/**
第二题:
设计一个student class 包含四个参数
int regno(编号), total;
int mark[];
String name;
total是总分,mark是分数。
在五十分以下的分数计算入总分时算为零分。
需要有public student(int r,String n,int m[]) {. . .}这个东西

test class如下
class TestStudent {
public static void main(String args[]) {
int mk1[]={73,85,95};
int mk2[]={71,85,55};
int mk3[]={51,65,45};
student st[]=new student[3];
st[0]=new student(1,"张三",mk1);
st[1]=new student(2,"李四",mk2);
st[2]=new student(3,"二麻",mk3);
// some display here
}
* */
public class TestStudent {
public static void main(String[] args) {
int mk1[]={73,85,95};
int mk2[]={71,85,55};
int mk3[]={51,65,45};
student st[]=new student[3];
st[0]=new student(1,"张三",mk1);
st[1]=new student(2,"李四",mk2);
st[2]=new student(3,"二麻",mk3);
for(int i=0; i st[i].print();
}

}
class student{
private int[] mark;
private String name;
private int r;
public student(int r,String n,int m[]) {
this.r=r;this.name=n;this.mark=m;
}
public int total(){
int t = 0;
for(int i=0; i if(mark[i]>=50)t+=mark[i];
return t;
}
public void print(){
System.out.println("学号:"+r+"\t姓名:"+name+"\t总分:"+total());
}
}

回答(2):

代笔,容易产生依赖.

回答(3):

给分少了点

回答(4):

关注

回答(5):

给分QUESHI确实少了点