用java定义一个Student类,如何操作?

2024-11-27 09:53:45
推荐回答(1个)
回答1:

package com.tgyt.nzft.core.listview;

public class Student {

private String s_no;//学号
private String s_name;//姓名
private boolean isLeader;//班干部否
private String s_sex;//性别
private double s_shuxue;//数学
private double s_yuwen;//语文
private double s_waiyu;//外语

//学生信息录入
public void addStudentInfo(String s_no, String s_name, boolean isLeader, String s_sex,
double s_shuxue, double s_yuwen, double s_waiyu) {
this.s_no = s_no;
this.s_name = s_name;
this.isLeader = isLeader;
this.s_sex = s_sex;
this.s_shuxue = s_shuxue;
this.s_yuwen = s_yuwen;
this.s_waiyu = s_waiyu;
}

//获得总分
public double getTotal(){
return s_shuxue + s_yuwen + s_waiyu;
}

//平均分
public double getV(){
return getTotal() / 3;
}

public static void main(String[] args) {
Student student = new Student();
student.addStudentInfo("no_101", "女霸王", false, "女", 100, 35, 55);
System.out.println("总分:" + student.getTotal());
System.out.println("平局分:" + student.getTotal());
}
}