import java.util.ArrayList;
import java.util.Date;
//公告管理
public class onLoad {
public static void main(String[] args) {
Notice notice1 = new Notice(1, "欢迎来到慕课网", "管理员", new Date());
Notice notice2 = new Notice(2, "欢迎来到慕课网", "管理员", new Date());
Notice notice3 = new Notice(3, "欢迎来到慕课网", "管理员", new Date());
//添加公告
ArrayList list = new ArrayList();
list.add(notice1);
list.add(notice2);
list.add(notice3);
//显示公告
System.out.println("显示公告的内容:");
for (int i = 0; i < list.size(); i++) {
/*
list.get(i) 返回值是一个Object , Notice类的有getTitle()方法, 所以进行强制转换成对象
Object[] objects=(Object[])list.get(0);
return objects[3]
* */
Notice createObj = (Notice) list.get(i);
System.out.println(createObj.getId());
System.out.println(createObj.getTitle());
System.out.println(createObj.getAdmin());
System.out.println(createObj.getCreateTime());
}
}
}
class Notice {
private int id;//id
private String title;//标题
private String admin;//创建人
private Date createTime;//创建时间
public Notice() {
}
public Notice(int id, String title, String admin, Date createTime) {
super();
this.id = id;
this.title = title;
this.admin = admin;
this.createTime = createTime;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAdmin() {
return admin;
}
public void setAdmin(String admin) {
this.admin = admin;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦