//手機的音樂存儲器?
private?List<Music>?sounds?=?new?ArrayList<Music>();
//手機播放音樂的方法?
public?void?play(){
for(Music?m:sounds){ m.play();//調用音樂的播放方法 }?}
//手機下載音樂的方法
public?void?download(Music?m){
sounds.add(m);}?
//手機充電的方法
public?void?charge(Cell?c){
c.charge();//調用插入電池的充電方法}?
}
class?Cell{
private?String?brand;//電池的品牌
Cell(String?brand){
this.brand=brand;}?
//提供查看電池品牌的方法,不提供修改品牌的方法
public?String?getBrand(){
return?brand;}?
//電池的續電方法
public?void?charge(){
System.out.println(brand+"品牌的電池正在為手機充電");}?
}
//附送給妳的音樂類
class?Music{
private?String?name;//歌名?
private?String?lyric;//歌詞?
private?String?player;//演唱者
Music(String?lyric,String?player,String?name){
this.lyric=lyric; this.player=player;? this.name=name;?}
//該音樂的播放方法?
public?void?play(){
System.out.println(name);? System.out.println(player); System.out.println(lyric);?}
}
public?class?Test{
public?static?void?main(String...?args){
Phone?iphone?=?new?Phone();//壹只蘋果get! //臥槽手機沒有電池TAT趕快買塊電池壓壓驚 Cell?cell?=?new?Cell("三星");? //看看電池什麽牌子 System.out.println(cell.getBrand()); //把電池插上iphone.charge(cell);
//下載首歌iphone.download(new?Music("妳在南方的艷陽裏...","張磊","<南山南>"));
//聽聽看吧balabalaiphone.play();?
}?
}