编写一个学生类,包含属性有学号姓名年龄,将所有学生存入一个数组,自拟数据,用数组的初始化方法给数组
package BaiDuZhiDao;
import java.util.ArrayList;
import java.util.List;
public class Student {
public static void main(String args[]){
StudentDto studentDto = null;
List<StudentDto> students = new ArrayList<StudentDto>();
//students information
System.out.println("初始学生信息:\n");
for (int i = 0; i < 5; i++){
studentDto = new StudentDto();
studentDto.setNumber(i);
studentDto.setName("student" + i);
studentDto.setAge(18 + i);
System.out.println("学号: " + studentDto.getNumber() + "; 姓名: " + studentDto.getName() + "; 年龄: " + studentDto.getAge() + "\n");
students.add(studentDto);
}
//age + 1
for (StudentDto student : students) {
student.setAge(student.getAge() + 1);
}
System.out.println("修改后学生信息:\n");
for (int i = 0; i < students.size(); i++){
System.out.println("学号: " + students.get(i).getNumber() + "; 姓名: " + students.get(i).getName() + "; 年龄: " + students.get(i).getAge() + "\n");
}
System.out.println("年龄大于20的学生:\n");
for (int i = 0; i < students.size(); i++){
if(students.get(i).getAge() > 20){
System.out.println(students.get(i).getName() + "\n");
}
}
}
}
/**
* student model
*/
class StudentDto{
private int number;
private String name;
private int age;
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
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;
}
}
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data\零配件.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from 供应商"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Columns(0).Width = 400
DataGrid1.Columns(1).Width = 1500
DataGrid1.Columns(2).Width = 900
DataGrid1.Columns(3).Width = 1000
DataGrid1.Columns(3).Alignment = 2 '设置对齐方式为居中
DataGrid1.Columns(0).Alignment = 2 '设置对齐方式为居中
DataGrid1.Columns(2).Alignment = 2 '设置对齐方式为居中