学生类:
public class Student
{
private String stuId;
private String name;
private String gender;
private float javaScore;
private float sqlScore;
private float cScore;
private float htmlScore;
private float avgScore;
private float sumScore;
public Student(){};
public Student(String stuId, String name, String gender,float javaScore,float sqlScore,
float cScore, float htmlScore)
{
this.stuId = stuId;
this.name = name;
this.gender = gender;
this.javaScore = javaScore;
this.sqlScore = sqlScore;
this.cScore = cScore;
this.htmlScore = htmlScore;
}
public float getSumScore(float javaScore,float sqlScore,
float cScore, float htmlScore)
{
return javaScore+sqlScore+cScore+htmlScore;
}
public String getStuId() {
return stuId;
}
public void setStuId(String stuId) {
this.stuId = stuId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public float getJavaScore() {
return javaScore;
}
public void setJavaScore(float javaScore) {
this.javaScore = javaScore;
}
public float getSqlScore() {
return sqlScore;
}
public void setSqlScore(float sqlScore) {
this.sqlScore = sqlScore;
}
public float getcScore() {
return cScore;
}
public void setcScore(float cScore) {
this.cScore = cScore;
}
public float getHtmlScore() {
return htmlScore;
}
public void setHtmlScore(float htmlScore) {
this.htmlScore = htmlScore;
}
public float getAvgScore() {
return avgScore;
}
}
ps:总分和平均分不需要set,缺少了get平均分部分 ,懒得写了 你仿照总分加上吧,给你个机会
测试类:
public class TestStudent {
public static void main(String[] args) {
Student student=new Student("1", "name", "男", 85, 74, 92, 88);
float sumScore=student.getSumScore(student.getHtmlScore(),
student.getJavaScore(), student.getSqlScore(), student.getcScore());
System.out.println("学生"+student.getName()+"总分为:"+sumScore);
}
}
结果:学生name总分为:339.0
注意确保2个类在一个包下。
//学生类
public class Student{
private int code;
private String name;
private String sex;
private int java;
private int sql;
private int C;
private int html;
public Student(){}
public Student(int code,String name,String sex,int java,int sql,int C,int html){
this.code=code;
this.name=name;
this.sex=sex;
this.java=java;
this.sql=sql;
this.C=C;
this.html=html;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getJava() {
return java;
}
public void setJava(int java) {
this.java = java;
}
public int getSql() {
return sql;
}
public void setSql(int sql) {
this.sql = sql;
}
public int getC() {
return C;
}
public void setC(int c) {
C = c;
}
public int getHtml() {
return html;
}
public void setHtml(int html) {
this.html = html;
}
@Override
public String toString() {
return "Student [code=" + code + ", name=" + name + ", sex=" + sex + ", java=" + java + ", sql=" + sql + ", C="
+ C + ", html=" + html + "]";
}
}
//测试类
public class StudentMain {
public static void main(String[] args) {
// TODO Auto-generated method stub
Student stu=new Student(0001, "张三", "男", 80, 60, 40, 70);
System.out.println(stu.toString());
}
}
什么语言呢?Java?C++?C#?