当前位置: 代码迷 >> Java相关 >> 求啊编撰一个Student类
  详细解决方案

求啊编撰一个Student类

热度:2060   发布时间:2013-02-25 21:45:29.0
求啊:编写一个Student类
            类名:Student,该类为public,表示学生信息
          该类包含String类型的实例变量:   Name(表示姓名),以及double类型的实例变量:English、Math(分别表示英语、数学的成绩),以上成员变量均为private权限。
          定义无参数的构造方法。
          定义包含3个参数的构造方法,通过3个参数设置对象的学号、姓名以及2门课的成绩。

------解决方案--------------------------------------------------------
Java code
public class Student {private String Name;private double English;private double Math;public Student(){}public Student(String Name,double English,double Math){this.Name=name;this.English=English;this.Math=Math;}}
------解决方案--------------------------------------------------------
Java code
public class Student{    private String name;    private double english;    private double math;        //封装变量    public String getName()    {        return name;    }    public void setName(String name)    {        this.name = name;    }    public double getEnglish()    {        return english;    }    public void setEnglish(double english)    {        this.english = english;    }    public double getMath()    {        return math;    }    public void setMath(double math)    {        this.math = math;    }    //无参构造函数    public Student(){}        //重载构造函数    public Student(String name , double english , double math){        this.name= name;        this.english =english;        this.math   = math;            }        }
------解决方案--------------------------------------------------------
Java code
public class Student {    private String name; //姓名    private double english;//英语成绩    private double math;//数学成绩    //getter and setter 方法    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public double getEnglish() {        return english;    }    public void setEnglish(double english) {        this.english = english;    }    public double getMath() {        return math;    }    public void setMath(double math) {        this.math = math;    }    /**     * 默认构造函数     */    public Student() {    }    /**     * 3个参数构造函数     * @param name     * @param english     * @param math     */    public Student(String name, double english, double math) {        this.name = name;        this.english = english;        this.math = math;    }    /**     * 重写toString方法     */    @Override    public String toString() {        return "Student [name=" + name + ", english=" + english + ", math="                + math + "]";    }        /**     * 测试main方法      * @param args     */    public static void main(String[] args) {        System.out.println(new Student("张三 " ,85.5, 90).toString()) ;    }}
  相关解决方案