[java]代码库
package com.student.www;
import java.util.Scanner;
public class StudentCJInput {
String[][] studentcjs = null;// 所有学生的成绩数组对应每个学生
String studentNames[] = null;// 所有学生数组
String[] cjs = null;// 科目数组
int studentNum = 0;// 学生数
int keNum = 0;// 学生科目数
Scanner scanner;// 监听系统输入
public StudentCJInput(int sNum, int keNum) {
scanner = new Scanner(System.in);
this.studentNum = sNum;
this.keNum = keNum;
showCJ();
}
/**
* 输入成绩
*
*/
void showCJ() {
studentNames = new String[studentNum];
studentcjs = new String[studentNum][keNum];
cjs = new String[keNum];
System.out.println("请依次输入所有学科:");
for (int xk = 0; xk < cjs.length; xk++) {
System.out.println("请输入第" + (xk + 1) + "门学科名:");
String xkName = scanner.next();
cjs[xk] = xkName;
}
for (int name = 0; name < studentNames.length; name++) {
System.out.println("请输入第" + (name + 1) + "个学生的姓名:");
String sName = scanner.next();
studentNames[name] = sName;
String[] scjNum = studentcjs[name];
for (int yxk = 0; yxk < cjs.length; yxk++) {
System.out.println("请输入" + cjs[yxk] + "的成绩:");
String cNum = scanner.next();
scjNum[yxk] = cNum;
}
}
print();
}
/**
* 打印
*/
private void print() {
System.out.println("所有学生的成绩单:");
System.out.print("\t");
printStudentName();
printCJNUM();
printZCJ();
printPJCJ();
printJB();
}
/**
* 打印学生姓名
*/
private void printStudentName() {
for (int i = 0; i < studentNames.length; i++) {
System.out.print(studentNames[i] + "\t");
}
}
/**
* 打印成绩分数
*/
private void printCJNUM() {
for (int i = 0; i < cjs.length; i++) {
System.out.print("\n" + cjs[i] + "\t");
for (int j = 0; j < studentNames.length; j++) {
String[] cj = studentcjs[j];
for (int l = 0; l < cj.length; l++) {
if (l == i) {
System.out.print(cj[l] + "\t");
}
}
}
}
}
/**
* 打印总成绩
*/
private void printZCJ() {
System.out.println();
System.out.print("总成绩\t");
for (int i = 0; i < studentNames.length; i++) {
String cj[] = studentcjs[i];
int cjNum = 0;
for (int j = 0; j < cj.length; j++) {
cjNum += Integer.parseInt(cj[j]);
}
System.out.print((cjNum) + "\t");
}
}
/**
* 平均成绩打印
*/
private void printPJCJ() {
System.out.println();
System.out.print("平均成绩\t");
for (int i = 0; i < studentNames.length; i++) {
String cj[] = studentcjs[i];
int cjNum = 0;
for (int j = 0; j < cj.length; j++) {
cjNum += Integer.parseInt(cj[j]);
}
System.out.print((cjNum / cj.length) + "\t");
}
}
/**
* 打印级别
*/
public void printJB() {
System.out.println();
System.out.print("评级\t");
for (int i = 0; i < studentNames.length; i++) {
String cj[] = studentcjs[i];
int cjNum = 0;
for (int j = 0; j < cj.length; j++) {
cjNum += Integer.parseInt(cj[j]);
}
String ylc = getJi(cjNum / cj.length);
System.out.print(ylc + "\t");
}
}
/**
* 获得级别差
*
* @param i
* @return
*/
public final static String Y = "优";
public final static String L = "良";
public final static String C = "差";
public final static String BJG = "不及格";
private String getJi(int ylc) {
if (ylc < 60) {
return BJG;
} else if (ylc >= 60 && ylc < 70) {
return C;
} else if (ylc >= 70 && ylc < 90) {
return L;
} else if (ylc >= 90 && ylc <= 100) {
return Y;
}
return BJG;
}
}
package com.student.www;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入学生数:");
int snum = scanner.nextInt();
System.out.println("请输入科目数:");
int knum = scanner.nextInt();
StudentCJInput studentCJInput = new StudentCJInput(snum, knum);
}
}
中级程序员
by: 隆隆0001 发表于:2016-12-22 17:25:02 顶(1) | 踩(0) 回复
挺简单的
回复评论