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

Implement a class called Song that represents a song that is available
at the Music Exchange Center. The class should have these attributes:

title - a String indicating the title of the song
artist - a String indicating the artist(s) or band that recorded the song
duration – an int indicating the number of seconds that the song lasts when played

Implement the following instance methods:

• A zero-parameter constructor.

• A constructor that accepts as parameters the song's title, artist, number of minutes and number of
seconds. (e.g., new Song("Angels Crying", "E-Type", 4, 35))

• A toString() method that returns a string representation of the song showing the title (within
double quotes), the artist and the duration (broken down in minutes and seconds).

For example: "Angels Crying" by E-Type 4:35

Test your code before continuing using this program:

class SongTestProgram {
      public static void main(String args[]) {
           Song song1, song2, song3;

           song1 = new Song();
           song2 = new Song("Hey Jude", "The Beatles", 4, 35);
           song3 = new Song("Barbie Girl", "Aqua", 3, 54);
           System.out.println(song1); // should display "" by 0:0
           System.out.println(song2); // should display "Hey Jude" by The Beatles 4:35
           System.out.println(song3); // should display "Barbie Girl" by Aqua 3:54
           System.out.println(song2.duration); // should display 275
           System.out.println(song3.duration); // should display 234
     }
}
搜索更多相关主题的帖子: class song The 
2009-11-02 08:51
快速回复:(求助)The song class
数据加载中...
 
   



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

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