当前位置: > 定义一个学生类(Student),属性包括:学号,班号,姓名,性别,年龄,班级总人数...
题目
定义一个学生类(Student),属性包括:学号,班号,姓名,性别,年龄,班级总人数
方法包括:获得学号,获得班号,获得姓名,获得性别,获得年龄,获得班级总人数,修改学号,修改班号,修改姓名,修改性别,修改年龄以及一个toString()方法将Student类中的所有属性组合成一个字符串.定义一个学生数组对象.设计程序进行测试.

提问时间:2021-03-01

答案
public class Test
{
x09public static void main (String[] args) {
x09x09Student[] students = new Student[] {
x09x09x09x09new Student("123", "456", "abc", "male", 10, 20),
x09x09x09x09new Student("789", "000", "def", "female", 30, 40)
x09x09};
x09x09for (Student s : students) {
x09x09x09System.out.println(s);
x09x09}
x09}

}
class Student {
x09String studentId, classId, name, gender;
x09int age, studentCount;
x09
x09public Student(String studentId, String classId, String name,
x09x09x09String gender, int age, int studentCount) {
x09x09this.studentId = studentId;
x09x09this.classId = classId;
x09x09this.name = name;
x09x09this.gender = gender;
x09x09this.age = age;
x09x09this.studentCount = studentCount;
x09}
x09public String getStudentId() {
x09x09return studentId;
x09}
x09
x09public void setStudentId(String studentId) {
x09x09this.studentId = studentId;
x09}
x09
x09public String getClassId() {
x09x09return classId;
x09}
x09
x09public void setClassId(String classId) {
x09x09this.classId = classId;
x09}
x09
x09public String getName() {
x09x09return name;
x09}
x09
x09public void setName(String name) {
x09x09this.name = name;
x09}
x09
x09public String getGender() {
x09x09return gender;
x09}
x09
x09public void setGender(String gender) {
x09x09this.gender = gender;
x09}
x09
x09public int getAge() {
x09x09return age;
x09}
x09
x09public void setAge(int age) {
x09x09this.age = age;
x09}
x09
x09public int getStudentCount() {
x09x09return studentCount;
x09}
x09
x09public void setStudentCount(int studentCount) {
x09x09this.studentCount = studentCount;
x09}
x09@Override
x09public String toString() {
x09x09return "Student [studentId=" + studentId + ", classId=" + classId
x09x09x09x09+ ", name=" + name + ", gender=" + gender + ", age=" + age
x09x09x09x09+ ", studentCount=" + studentCount + "]";
x09}
}
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
版权所有 CopyRight © 2012-2019 超级试练试题库 All Rights Reserved.