创建一个customer类,类中的属性有姓名,年龄,性别,每个属性分别有get、set方法。然后创建两个customer对象:张立,18,女和王猛,22,男。把这两个对象存储在ArrayList对象中
import java.util.HashSet;
import java.util.Set;
import java.awt.List;
import java.util.ArrayList;
public class Customer {
private String name;
int age;
String sex;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public Customer(String name,int age,String sex) {
this.name=name;
this.age=age;
this.sex=sex;
}
public static void main(String[] args) {
Customer c1 = new Customer("zhangli",18,"女");
Customer c2 = new Customer("wangmeng",22,"男");
ArrayList<Customer> list = new ArrayList<Customer>();
list.add(c1);
list.add(c2);
for(Customer c:list){
System.out.println("姓名"+c.getName());
System.out.println("年龄"+c.getAge());
System.out.println("性别"+c.getSex());
}
}
}