求java代码!!
练习1:1.编写一个Student类,包含name、gender、age、id、score属性,分别为String、String、int、int、double类型。2.类...
练习1:
1.编写一个Student类,包含name、gender、age、id、score属性,分别为String、String、int、int、double类型。
2.类中声明一个say方法,返回String类型,方法返回信息中包含所有属性值。
3.在另一个TestStudent类中的main方法中,创建Student对象,并访问say方法和所有属性,并将调用结果打印输出。 展开
1.编写一个Student类,包含name、gender、age、id、score属性,分别为String、String、int、int、double类型。
2.类中声明一个say方法,返回String类型,方法返回信息中包含所有属性值。
3.在另一个TestStudent类中的main方法中,创建Student对象,并访问say方法和所有属性,并将调用结果打印输出。 展开
3个回答
展开全部
学生类。
/**
* <p>学生类</p>
* @author z_y
*
*/
public class Student {
/**
* propertys
*/
private int id;
private int age;
private String name;
private String gender;
private double score;
//empty constructor
public Student(){}
//full constructor
public Student(int id, int age, String name, String gender, double score) {
super();
this.id = id;
this.age = age;
this.name = name;
this.gender = gender;
this.score = score;
}
//getter and setter
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
/**
* <p>say方法</p>
* @return key:value 返回所有的属性及其对应的值
*/
public String say(){
return "id:" + this.id + ",age:"+ this.age + ",name:"+this.name + ",gender:" + this.gender + ",score:" + this.score;
}
}
2.测试类
/**
* <p>学生测试类</p>
* @author z_y
*
*/
public class TestStudent {
/**
* @param args
*/
public static void main(String[] args) {
//new Student
Student stu = new Student();
//setter
stu.setId(1);
stu.setAge(20);
stu.setName("张三");
stu.setGender("男");
stu.setScore(75.63);
//execute say
System.out.println("学生信息:" + stu.say());
}
}
追问
第一个编译成了,但是运行时候说缺少main方法,怎么处理啊,谢谢
展开全部
public class Student {
/**
* propertys
*/
private int id;
private int age;
private String name;
private String gender;
private double score;
//empty constructor
public Student(){}
//full constructor
public Student(int id, int age, String name, String gender, double score) {
super();
this.id = id;
this.age = age;
this.name = name;
this.gender = gender;
this.score = score;
}
//getter and setter
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
/**
* <p>say方法</p>
* @return key:value 返回所有的属性及其对应的值
*/
public String say(){
return "id:" + this.id + ",age:"+ this.age + ",name:"+this.name + ",gender:" + this.gender + ",score:" + this.score;
}
}
/**
* propertys
*/
private int id;
private int age;
private String name;
private String gender;
private double score;
//empty constructor
public Student(){}
//full constructor
public Student(int id, int age, String name, String gender, double score) {
super();
this.id = id;
this.age = age;
this.name = name;
this.gender = gender;
this.score = score;
}
//getter and setter
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
/**
* <p>say方法</p>
* @return key:value 返回所有的属性及其对应的值
*/
public String say(){
return "id:" + this.id + ",age:"+ this.age + ",name:"+this.name + ",gender:" + this.gender + ",score:" + this.score;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2017-09-28
展开全部
你好无聊啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询