/*1.定义一个学生类型
1)有姓名,年龄,所在班级,c成绩,html成绩,java成绩这几个属性
2)有一个输出自己信息的方法
3)有一个输出总成绩的方法
要求:用该学生类型定义两个学生变量,并测试。
*/
/**
* 功能:封装学生类
* 类名:Students
* 作者:******
* 时间:2018年7月31日下午9:22:18
*/
public class Students {
private String name;
private int age;
private String _class;
private double sc_c;
private double sc_html;
private double sc_java;
public Students(String name, int age, String _class, double sc_c, double sc_html, double sc_java) {
super();
this.name = name;
this.age = age;
this._class = _class;
this.sc_c = sc_c;
this.sc_html = sc_html;
this.sc_java = sc_java;
}
/**
* 功能:学生学生信息
* author:******
* time:2018年7月31日下午9:23:04
*/
public void showInfo() {
System.out.println("姓名:" + name + "\n年龄:" + age + "\n班级:" + _class);
}
/**
* 功能:学生学生总成绩
* author:******
* time:2018年7月31日下午9:23:04
*/
public void showTotal() {
System.out.println("总成绩:" + (sc_c + sc_html + sc_java));
}
}
/**
* 功能:测试封装的学生类
* 类名:TestStudents
* 作者:wangpeng
* 时间:2018年7月31日下午9:26:34
*/
public class TestStudents {
public static void main(String[] args) {
// TODO Auto-generated method stub
Students_1 stu1 = new Students("张三", 20, "一班", 80, 85, 99);
stu1.showInfo();
stu1.showTotal();
Students_1 stu2 = new Students("李四", 21, "二班", 90, 95, 99);
stu2.showInfo();
stu2.showTotal();
}
}