import java.io.*;
class Grade {
private String name;
private int chGde;
private int enGde;
private int total;
private float avg;
private int grant;
private String lvl;
public Grade(String s) {
name = s;
}
public Grade(String s, int x, int y) {
name = s;
chGde = x;
enGde = y;
}
public void setGrade(int x, int y) {
chGde = x;
enGde = y;
}
public void setGrant(int x) {
grant = x;
}
public void printGrade() {
System.out.println(name +"\t" +chGde +"\t" +enGde +"\t"+ total +"\t"+ avg +"\t"+ lvl);
}
private void cal() {
total = chGde + enGde;
avg = (float)total / 2.0F;
avg += grant;
if (avg >= 80) lvl = "甲";
else if (avg < 60) lvl = "丙";
else lvl = "乙";
}
}
public class s933940_1
{
public static void main(String[] args)
{
Grade g1 = new Grade("我是誰");
Grade g2 = new Grade("YSP", 60, 70);
g1.setGrade(50, 89);
g1.setGrant(1);
g2.setGrant(2);
g1.cal();
g2.cal();
System.out.println("\n姓名 國文 英文 總分 平均 等級");
g1.printGrade();
g2.printGrade();
}
}
這是參考老師的範例下去改的...
不過編譯時有錯誤..
但不知道是哪邊有錯...
請大大幫我看一下吧...
感謝您~~~
|