八字汽车坐垫批发价格:JAVA程序编写一个学生类Student

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/29 16:57:21
1)学生类Student属性有:
id;long型,代表学号
name;String类对象,代表姓名
age;int型,代表年龄
sex;boolen型,代表性别
(其中:true表示男,false表示女)
phone;String类对象,代表联系电话
(2)学生类方法有:
Student(long i,String n,int a,boolean s,long p):有参构造函数,形参表中的参数分别初始化学号、年龄、性别和联系电话。
int getAge()( ):获取年龄作为方法的返回值。
long getphone( ):获取联系电话作为方法的返回值。
public String toString( ):以姓名:联系电话的形式作为方法的返回值。

Public Class Student{
Public long id;
Public String name;
Public int age;
Public boolean sex;
Public long phone;
Public Student(long i,String n,int a,boolean s,long p){
this.id = i;
this.name = n;
this.age = a;
this.sex = s;
this.phone = p;
}
Public int getage(){
return this.age;
}
Public long getphone(){
return this.phone;
}
Public String toString(){
return this.name;
}
Public static void main(String[]args){
Student student = new Student(01,"李明",20,true,13xxx);
System.out.println(student.age());
System.out.println(student.getphone());
System.out.println(student.toString());
}
}

咋不自己写呢

//以下是程序段在自己机子上已经编译运行过了你自己试下
public class Student{
public long id;
public String name;
public int age;
public boolean sex;
public long phone;
public Student(long i,String n,int a,boolean s,long p){
this.id = i;
this.name = n;
this.age = a;
this.sex = s;
this.phone = p;
}
public int getage(){
return this.age;
}
public long getphone(){
return this.phone;
}
public String toString(){
return this.name;
}
public static void main(String[]args){
Student student = new Student(01,"李明",20,true,8888);
System.out.println(student.getage());
System.out.println(student.getphone());
System.out.println(student.toString());
}
}

no