package?com.imooc.collection;
/**
?*?課程類(lèi)
?*?
?*?@author?sama
?*
?*/
public?class?Course
{
private?String?id;
private?String?name;
public?Course(String?id,?String?name)
{
this.setId(id);
this.setName(name);
}
public?Course()
{
}
public?String?getId()
{
return?id;
}
public?void?setId(String?id)
{
this.id?=?id;
}
public?String?getName()
{
return?name;
}
public?void?setName(String?name)
{
this.name?=?name;
}
@Override
public?boolean?equals(Object?object)
{
if?(this?==?object)
{
return?true;
}
if?(object?==?null)
{
return?false;
}
if?(!(object?instanceof?Course))
{
return?false;
}
Course?course?=?(Course)?object;
if?(this.getName()?==?null)
{
if?(course.getName()?==?null)
{
return?true;
}?else
{
return?false;
}
}?else
{
if?(this.getName().equals(course.getName()))
{
return?true;
}?else
{
return?false;
}
}
}
}
public?void?testListContains()
{
//?取得備選課程序列的第0個(gè)元素
Course?course?=?coursesToSelect.get(0);
//?打印輸出coursesToSelected是否包含course對(duì)象
System.out.println("取得課程:"?+?course.getName());
System.out.println("備選課程中是否包含課程:"?+?course.getName()?+?","?+?coursesToSelect.contains(course));
System.out.println("請(qǐng)輸入課程名稱(chēng):");
String?name?=?console.next();
System.out.println("!@!!!!!!@#!@");
//?創(chuàng)建一個(gè)新的課程對(duì)象
Course?course2?=?new?Course();
course2.setName(name);
System.out.println("新創(chuàng)建課程:"?+?course2.getName());
System.out.println("備選課程中是否包含課程:"?+?course2.getName()?+?","?+?coursesToSelect.contains(course2));
}
2017-01-17
沒(méi)有main方法呀!
2016-12-31
Debug的時(shí)候運(yùn)行結(jié)果沒(méi)錯(cuò)