java定义Student类(包括name,number等属性),定义一个List类型的容器,往容器中添加
5个回答
展开全部
定义Student类:
package com.tip.app.common.test;
public class Student {
private String name;
private int number;
private String age;
private String sex;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
-------------------------------------------------------------------------
定义一个List类型的容器,往容器中添加:
package com.tip.app.common.test;
import java.util.ArrayList;
import java.util.List;
public class Stest {
public static void main(String[] args) {
//创建Student类,填写属性
Student student = new Student();
student.setAge("age");
student.setName("name");
student.setNumber(18);
student.setSex("sex");
//创建list 往list添加student
List<Student> students = new ArrayList<Student>();
students.add(student);
}
}
package com.tip.app.common.test;
public class Student {
private String name;
private int number;
private String age;
private String sex;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
-------------------------------------------------------------------------
定义一个List类型的容器,往容器中添加:
package com.tip.app.common.test;
import java.util.ArrayList;
import java.util.List;
public class Stest {
public static void main(String[] args) {
//创建Student类,填写属性
Student student = new Student();
student.setAge("age");
student.setName("name");
student.setNumber(18);
student.setSex("sex");
//创建list 往list添加student
List<Student> students = new ArrayList<Student>();
students.add(student);
}
}
展开全部
package com.name;
import java.util.ArrayList;
import java.util.List;
public class Student {
private String xh;
private String xm;
private String bh;
private int yw;
private int sx;
private int yy;
private int zf;
private String id;
public String getXh() {
return xh;
}
public void setXh(String xh) {
this.xh = xh;
}
public String getXm() {
return xm;
}
public void setXm(String xm) {
this.xm = xm;
}
public String getBh() {
return bh;
}
public void setBh(String bh) {
this.bh = bh;
}
public int getYw() {
return yw;
}
public void setYw(int yw) {
this.yw = yw;
}
public int getSx() {
return sx;
}
public void setSx(int sx) {
this.sx = sx;
}
public int getYy() {
return yy;
}
public void setYy(int yy) {
this.yy = yy;
}
public int getZf() {
return yw+sx+yy;
}
public void setZf(int zf) {
this.zf = zf;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Student() {
super();
}
public Student(String xh, String xm, String bh, int yw, int sx, int yy) {
super();
this.xh = xh;
this.xm = xm;
this.bh = bh;
this.yw = yw;
this.sx = sx;
this.yy = yy;
this.zf = yw + sx + yy;
}
public Student(String id){
this.id=id;
}
public static void main(String[] args) {
List<Student> list=new ArrayList<Student>();
Student s=new Student("001","小p孩","002",1,2,3);
list.add(s);
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Student
{
private String name;
private int number;
public Student(String name,int no)
{
this.name = name;
this.number = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public static void main(String[] args)
{
List<Student> list = new ArrayList<Student>();
list.add(new Student("张三",01));
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2017-12-14
展开全部
List list=new ArrayList();
list.add(new Student("姓名张三","number5"));
注:Student类得有构造方法
list.add(new Student("姓名张三","number5"));
注:Student类得有构造方法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
List list = new ArrayList<Student>();
list.add(student);
list.add(student);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询