java定义一个Student类,包含内容如下

成员变量:学号、姓名、性别、班干部否、数学、语文、外语
成员方法:输入、总分、平均分
编程实现这个类,并调用相应的方法输入数据,计算某个人总分和平均成绩
附加要求:计算所有输入学员的各科平均成绩

public class Student {
    /**
     * 成员变量:学号、姓名、性别、班干部否、数学、语文、外语
成员方法:输入、总分、平均分
编程实现这个类,并调用相应的方法输入数据,计算某个人总分和平均成绩
附加要求:计算所有输入学员的各科平均成绩
     */
public int idNum;
public String name;
public String sex;
public String classLeader;
public float math;
public float chinese;
public float english;
public Student(int idNum,String name,String sex,String classLeader,
float math,float chinese,float english ) {
// TODO Auto-generated constructor stub
this.idNum=idNum;
this.name=name;
this.sex=sex;
this.classLeader=classLeader;
this.math=math;
this.chinese=chinese;
this.english=english;
}
public float TotalFraction(){
float total;
total=math+chinese+english;
return total;

}
public float Average(){
float average;
average=(math+chinese+english)/3;
return average;
}


}



import java.util.*;


public class Main {


public static void main(String[] args) {

// TODO Auto-generated method stub


//成员变量:学号、姓名、性别、班干部否、数学、语文、外语

Scanner scanner=new Scanner(System.in);

System.out.println("输入学号");

int id=scanner.nextInt();

System.out.println("姓名");

String name=scanner.next();

System.out.println("性别");

String sex=scanner.next();

System.out.println("班干部");

String classLeader=scanner.next();

System.out.println("数学");

float math=scanner.nextFloat();

System.out.println("语文");

float chinese=scanner.nextFloat();

System.out.println("英语");

float english=scanner.nextFloat();

Student stu=new Student(id, name, sex, classLeader, math, chinese, english);

System.out.println("总分"+stu.TotalFraction());

System.out.println("平均分"+stu.Average());

}


}



如果要保存多个人的话Student[] student保存对象

追问

如果算各科的平均成绩如何所有人这科的成绩?利用一维数组吗?

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-06-14
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());
}
}
第2个回答  2015-05-27
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());
}
}
第3个回答  2018-06-14
import java.util.Scanner; public class Student { public static void main(String[] args) { Student student = new Student(); student.input(); float sum = student.sum(); float avg = student.avg(); System.out.println("The "+student.getName()+"'s"+" sum is :" + sum); System.out.println("The "+student.getName()+"'s"+" avg is :"+ avg); } private int id; private String name; private String sex; private boolean leader; private float math; private float chinese; private float english; public void input(){ Scanner scanner = new Scanner(System.in); System.out.println("Pleace input the id:"); setId(scanner.nextInt()); System.out.println("Pleace input the name:"); setName(scanner.next()); System.out.println("Pleace input the sex:"); setSex(scanner.next()); System.out.println("Pleace input the weather leader:true or false"); setLeader(scanner.nextBoolean()); System.out.println("Pleace input the grade of math:"); setMath(scanner.nextFloat()); System.out.println("Pleace input the grade of chinese:"); setChinese(scanner.nextFloat()); System.out.println("Pleace input the grade of chinese:"); setEnglish(scanner.nextFloat()); } public float sum(){ float sum = this.math+this.chinese+this.english; return sum; } public float avg(){ return sum()/3; } public int getId() { return id; } public void setId(int id) { this.id = id; } 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 boolean isLeader() { return leader; } public void setLeader(boolean leader) { this.leader = leader; } public float getMath() { return math; } public void setMath(float math) { this.math = math; } public float getChinese() { return chinese; } public void setChinese(float chinese) { this.chinese = chinese; } public float getEnglish() { return english; } public void setEnglish(float english) { this.english = english; }}
第4个回答  2015-08-15
这题 你自己编的?

相似回答