其他分享
首页 > 其他分享> > 第七周总结

第七周总结

作者:互联网

本周依旧是主要学习Java的方法问题练习了一些基础题目,如学生类

//学生类
class Student
{
private String sno;
private String classno;
private String name;
private char sex;
private int age;

//有参数的构造函数
public Student(String sno,String classno,String name,char sex, int age)
{
this.sno = sno;
this.classno = classno;
this.name = name;
this.sex = sex;
this.age = age;
}
//无参数的构造函数
public Student()
{}
//获取学生的学号
String getSno()
{
return sno;
}
//获取学生的班号
String getClassno()
{
return classno;
}
//获取学生的性别
char getSex()
{
return sex;
}
//获取学生年龄
int getAge()
{
return age;
}
//更新学生的年龄信息
void updateAge(int age)
{
this.age = age;
}
//输出学生信息
void print()
{
System.out.println("学生信息:" + '\n');
System.out.println(" " + "学号" + " " + "班号" + " " + "姓名" + " " + "性别" + " " + "年龄" + '\n');
System.out.println(this.sno + " " + this.classno + " " + this.name + " " + this.sex + " " + this.age + '\n');
}
}

public class Student_Information {

public static void main(String[] args)
{
char i;
Student student[] = new Student[6];//定义一个数组
//对数组里面的元素进行初始化
student[0] = new Student("201704166051","电信1702班","Boly",'Y',18);
student[1] = new Student("201704166052","电信1702班","Lily",'X',18);
student[2] = new Student("201704166053","电信1702班","Jasy",'X',19);
student[3] = new Student("201704166054","电信1702班","Tom",'Y',19);
student[4] = new Student("201704166055","电信1702班","Jack",'Y',18);
student[5] = new Student("201704166056","电信1702班","Bob",'Y',19);
//显示各学生信息
for(i = 0;i < 6;i++)
{
student[i].print();
}
}
}

标签:总结,第七,age,sex,student,Student,new,String
来源: https://www.cnblogs.com/ysl666/p/16584698.html