import javax.swing.JOptionPane;
public class Student {
String xh,name;
int yy,math,yw,total;
Student(String xh1,String name1){
xh=xh1;
name=name1;
}
Student(String xh1,String name1,int yy1,int math1,int yw1){
xh=xh1;
name=name1;
yy=yy1;
math=math1;
yw=yw1;
}
void display(){
String str=JOptionPane.showInputDialog("请输入英语成绩:");
yy=Integer.parseInt(str);
str=JOptionPane.showInputDialog("请输入数学成绩:");
math=Integer.parseInt(str);
str=JOptionPane.showInputDialog("请输入语文成绩:");
yw=Integer.parseInt(str);
total=yy+yw+math;
JOptionPane.showMessageDialog(null,"学号:"+xh+"\n姓名:"+name+"\n数学:"+math+"\n英语:"+yy+"\n语文:"+yw+"\n总成绩"+total);
}
void sum(){
total=yy+yw+math;
}
public static void main(String[] args) {
Student t1=new Student("2015001", "张三");
t1.display();
}
}
你自己改一下数据,添一个平均值吧。