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;
}
}
點(diǎn)擊查看更多內(nèi)容
為 TA 點(diǎn)贊
評論
評論
共同學(xué)習(xí),寫下你的評論
評論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦