创建student类,包括(学号,班号,姓名,性别,年龄)和方法

来源:百度知道 编辑:UC知道 时间:2024/07/03 03:27:00
方法要实现获得学号,班号,姓名,性别,设置学号,班号,姓名,性别的功能
在上题的类中增加一个构造方法,初始化所以的属性,并增加一个say()方法,把该类中的所有属性信息输出。创建对象s1,调用say 方法输出所有的信息。
创建两个student类的对象,比较二者的年龄,输出其中年龄最大的学生的姓名。

class Student
{
String no;
String classno;
String name;
String sex;
int age;
Student(String no,String classno,String name,String sex,int age)
{
this.no=no;
this.classno=no;
this.name=name;
this.sex=sex;
this.age=age;
}
void say()
{
System.out.println("学号:"+no);
System.out.println("班号:"+classno);
System.out.println("姓名:"+name);
System.out.println("性别:"+sex);
System.out.println("年龄:"+age);
}

public static void main(String args[])
{
Student stu=new Student("1","22","李荣","男",20);
stu.say();

}
}

比较二者的年龄,输出其中年龄最大的方法
void compared(Student a,Student b){
if(a.age>b.age)
System.out.println(a.name)
else
System.out.println(b.name)

}
剩下的太简单了 自己搞定吧 要不你就不会学习