于运用数组,想给出基础版的,回来继续更新
import javax.swing.JApplet;
import javax.swing.JTextArea;
import java.awt.Container;
import java.awt.Font;
public class DoubeArrayTest extends JApplet {
String output = "学生成绩表\n\n";
String students[] = { "张三", "李四", "王五", "赵六" };
String courses[] = { "英语", "数学", "语文", "体育" };
int grades[][] = { { 77, 68, 86, 73 }, { 96, 87, 89, 81 },
{ 70, 90, 86, 81 }, { 0, 0, 0, 0 } };
JTextArea outputArea;
public void init() {
setSize(600, 600);
outputArea = new JTextArea();
outputArea.setEditable(false); // 不可编辑
Container container = getContentPane();
container.add(outputArea);
buildString();
coursesAverage();
output += "\n\n\n最低分:" + minimum() + "\n最高分:" + maximum() + "\n";
for (int counter = 0; counter < students.length; counter++)
output += "\n" + students[counter] + "的平均成绩是:" + average(counter);
outputArea.setFont(new Font("Monospaced", Font.PLAIN, 14));
outputArea.setText(output);
showStatus("成绩表打印完成!");
}
public void coursesAverage() {
output += "\n平均分\t";
int sum = 0;
for (int i = 0; i < courses.length; i++) {
sum = 0;
{
for (int j = 0; j < students.length; j++)
sum += grades[j][i];
}
output += sum + "\t";
}
}
public double average(int counter) {
double sum = 0;
for (int i = 0; i < courses.length; i++)
sum += grades[counter][i];
return sum / courses.length;
}
public int minimum() {
int min = grades[0][0];
for (int i = 0; i < students.length; i++)
for (int j = 0; j < courses.length; j++) {
if (grades[i][j] < min)
min = grades[i][j]; // 注意在这些方法里面不能更改数组的值
}
return min;
}
public int maximum() {
int max = grades[0][0];
for (int i = 0; i < students.length; i++)
for (int j = 0; j < courses.length; j++) {
if (grades[i][j] > max)
max = grades[i][j];
}
return max;
}
public void buildString() {
output += "\t";
for (int i = 0; i < courses.length; i++)
output += courses[i] + "\t";
output += "总分";
for (int i = 0; i < students.length; i++) {
output += "\n" + students[i] + "\t";
{
for (int j = 0; j < courses.length; j++)
output += grades[i][j] + "\t";
}
coursesSum(i);
}
}
public void coursesSum(int i) {
int sum = 0;
for (int j = 0; j < courses.length; j++)
sum += grades[i][j];
output += sum;
}
}