java编程:定义一个student类,包含内容如下
成员变量:学号,姓名,性别,计算机成绩成员方法:输入,总分,平均分编程实现这个类,并调用相应的方法输入三个学生的数据,输出总分个平均分...
成员变量:学号,姓名,性别,计算机成绩
成员方法:输入,总分,平均分
编程实现这个类,并调用相应的方法输入三个学生的数据,输出总分个平均分 展开
成员方法:输入,总分,平均分
编程实现这个类,并调用相应的方法输入三个学生的数据,输出总分个平均分 展开
2个回答
展开全部
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());
}
}
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());
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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; }}
追问
咱能分下段吗……这样看不懂啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询