| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 959 人关注过本帖
标题:(求助)The User class
取消只看楼主 加入收藏
lyf3368
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2009-10-6
结帖率:25%
收藏
已结贴  问题点数:10 回复次数:2 
(求助)The User class
(2) The User Class

Implement a class called User that represents a user of the Music Exchange Center
that logs in to download music. The class must have the following attributes:

userName - a String indicating the user's name when on the system.

online - a boolean indicating whether or not the user is on-line at the moment.
(An on-line user is able to download music and this user’s music is also made available to
other users who are logged on.)

songList - an ArrayList<Song> containing all of the songs that this user has on his/her hard drive
to be made available to the Music Exchange Center community.


Create the following methods:

• A constructor that takes no parameters, and another constructor that takes the user name as a
parameter. When created, users are considered NOT to be online.

• A toString() method that shows the user's name, the number of files available in his/her song list
and whether or not he/she is currently on-line (e.g., BoppinBob: 14 songs (not online)).

• A method called addSong() which adds a given song to the user’s songList.

• A method called totalSongTime() that returns an integer indicating the total amount of time (in
seconds) that all of the user’s songs would require if played.

Test your code before continuing using this test program:

class UserTestProgram {
    public static void main(String args[]) {
      User    discoStew, noNameFred, peterPunk;

// Create some users and give them some songs
discoStew = new User("Disco Stew");
discoStew.addSong(new Song("Hey Jude", "The Beatles", 4, 35));
discoStew.addSong(new Song("Barbie Girl", "Aqua", 3, 54));
discoStew.addSong(new Song("Only You Can Rock Me", "UFO", 4, 59));
System.out.println(discoStew); // should display Disco Stew: 3 songs (not online)
System.out.println(discoStew.totalSongTime()); // should display 808

noNameFred = new User();
System.out.println(noNameFred); // should display : 0 songs (not online)
System.out.println(noNameFred.totalSongTime()); // should display 0

peterPunk = new User("Peter Punk");
peterPunk.addSong(new Song("Bite My Arms Off", "Jaw", 4, 12));
peterPunk.addSong(new Song("Where's My Sweater", "The Knitters", 3, 41));
peterPunk.addSong(new Song("Is that My Toenail ?", "Clip", 4, 47));
peterPunk.addSong(new Song("Anvil Headache", "Clip", 4, 34));
peterPunk.addSong(new Song("My Hair is on Fire", "Jaw", 3, 55));
System.out.println(peterPunk); // should display Peter Punk: 5 songs (not online)
System.out.println(peterPunk.totalSongTime()); // should display 1269

peterPunk.online = true;
System.out.println(peterPunk); // should display Peter Punk: 5 songs (online)
   }
}
搜索更多相关主题的帖子: User class The 
2009-11-02 09:03
lyf3368
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2009-10-6
收藏
得分:0 
以下是引用流星雨在2009-11-2 17:50:47的发言:


简单的给你写了下,大概就这么些东西,不过你这个按道理说是要考虑总时间的进位的。不应该用string和int 去记录时间。还有,我没时间给你测,你自己拿了代码测测,有错自己改下,不懂再问。
import java.util.Array ...
非常感谢,我先测一下
2009-11-02 22:45
lyf3368
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2009-10-6
收藏
得分:0 
最关键的那2个toString method我不会写啊,你帮我可以写一下吗


还有你的totalSongTime Method 我看不懂啊,也运行不了,我们是应该要return一个int数值才对

[ 本帖最后由 lyf3368 于 2009-11-7 05:20 编辑 ]
2009-11-07 05:05
快速回复:(求助)The User class
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012484 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved