| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 525 人关注过本帖
标题:(求助)The song class
只看楼主 加入收藏
lyf3368
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2009-10-6
结帖率:25%
收藏
已结贴  问题点数:10 回复次数:1 
(求助)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
流星雨
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:JAVA风暴
等 级:版主
威 望:43
帖 子:1854
专家分:1868
注 册:2004-5-30
收藏
得分:10 
public class Song {
    private String title ="";
    private String artist = "";
    private String duration ="";//我比较懒,就暂时定义成string用的时候截取转化一下好了
    public Song(String title,String artist,String duration){
        this.title = title;
        this.artist = artist;
        this.duration = duration;
    }
    public Song(){}
}
其实就这么简单,不要被外语搞蒙了。

感谢你们带我找到星空下美丽神话,无论经历多少苦痛也不放弃的梦;插上希望翅膀乘风我和你们飞翔,飞过海天尽头携手把梦想实现.....
2009-11-02 17:03
快速回复:(求助)The song class
数据加载中...
 
   



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

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