java输入学生成绩

public class Card {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int stu[] = new int[3];
try{
for(int i=0; i<stu.length;i++) {
Student s = new Student();
s.getStudent();
s.showStudent();
s.averStudent();
}
}catch (Exception e){
System.out.println("输入有误:");
}
}
}

class Student {
int id;
String name;
double a,b,c;
double avg;
Object e=null;

public void getStudent(){
Scanner keyboard=new Scanner(System.in);
System.out.println("请输入学号:");
id=keyboard.nextInt();
System.out.println("请输入姓名:");
name=keyboard.next();
System.out.println("请输入语文课成绩:");
a=keyboard.nextInt();
System.out.println("请输入数学课成绩:");
b=keyboard.nextInt();
System.out.println("请输入英语课成绩:");
c=keyboard.nextInt();
}
public void showStudent() {
System.out.println("学号:"+id+" "+"姓名:"+ name+" "+"语文课成绩:"+a+" "+"数学课成绩:"+b+" "+"英语课成绩:"+c);
}
public void averStudent() {
avg=(a+b+c)/3;
System.out.println("三门课的平均成绩是:"+avg);
}

}

posted @ 2016-04-14 21:42  风。  阅读(550)  评论(0编辑  收藏  举报