• /  6
  • 下載費用: 9.9積分  

《斯坦福大學開放課程:編程方法》講義#43

'《斯坦福大學開放課程:編程方法》講義#43'
?Mehran Sahami Handout #43CS 106A November 28, 2007FlyTunes Program (Data Structures Example)File: Song.java7** File: Song.java* Keeps track of the information for one song* in the music shop, including its namer the band* that it is by, and its price.*/public class Song {/** Constructor* Note that the song name and band name are immutable* once the song is created?*/public Song(String songName, String bandName, double songPrice) { title = songName;band = bandName; price = songPrice;}public String getSongName() {ret urn t if;}public String getBandName() {return band;}public void setPrice(double songPrice) { price = songPrice;}public double getPrice() {return price;}/** Returns a string representation of a songr listing* the song name, the band name, and its price.*/public String toString() { return (M\11M + title + M\w by 11 + band+ n costs $n + price);}/* private instance variables */private String title;private String band;private double price;File: Albumjava/** File: Album.java* Keeps track of all the information for one album* in the music shop, including its name/ the band that* its by, and the list of songs it contains? */import java?util?*;public class Album {/** Constructor* Note that the album name and band name are immutable* once the album is created?*/public Album(String albumName, String bandName) { title = albumName;band = bandName;}public String getAlbumN-省略部分- album in the inventory? */private void listSongsOnAlbum() {String name = readLine("Album name: if (albums?containsKey(name)) {Iterator it = albums?get(name)?getSongs();printin(name + M contains the following songs:w); while (it.hasNext()) {Song song = it?next();printin(song.toString());}} else {printin(MNo album by that name in the store.n); }/** Updates the price of a song in the store?s inventory?* Note that this price update will also affect all albums* that contain this song> */private void updateSongPrice() {String name = readLine (11 Song name: 11);St ring band = readLine (wBand name: 11);int songindex = findSong(namer band);if (songindex == -1) { printin (HThat song is not in the store.11);} else { double price = readDouble ( nNew price : 11);songs.get(songindex).setPrice(price); printin (nPrice for n + name + 11 updated. n);/* Constants */privatestaticfinalintQUIT = 0;privatestaticfinalintLIST^SONGS = 1;privatestaticfinalintLIST^ALBUMS = 2;privatestaticfinalintADDSONG = 3;privatestaticfinalintADD_ALBUM = 4;privatestaticfinalintLIST_SONGS_ON_ALBUM = 5;privatestaticfinalintUPDATE_S ONG_P RICE = 6;/* Private instance variables */// Inventory all the albums carried by the store private HashMap<StringzAlbum〉 albums =new HashMap();// Inventory of all the songs carried by the store private ArrayList songs = new ArrayList();}
關 鍵 詞:
斯坦福大學開放課程:編程方法 講義 43
 天天文庫所有資源均是用戶自行上傳分享,僅供網友學習交流,未經上傳用戶書面授權,請勿作他用。
關于本文
本文標題:《斯坦福大學開放課程:編程方法》講義#43
鏈接地址: http://www.476824.live/p-47706496.html
關于我們 - 網站聲明 - 網站地圖 - 資源地圖 - 友情鏈接 - 網站客服點擊這里,給天天文庫發消息,QQ:1290478887 - 聯系我們

本站為“文檔C2C交易模式”,即用戶上傳的文檔直接賣給(下載)用戶,本站只是中間服務平臺,本站所有文檔下載所得的收益歸上傳人(含作者)所有【成交的100%(原創)】。本站是網絡服務平臺方,若您的權利被侵害,侵權客服QQ:1290478887 歡迎舉報。

[email protected] 2017-2027 http://www.476824.live 網站版權所有

粵ICP備19057495號 

收起
展開
球探网即时蓝球比分 好运彩票下载app最新 大乐i透开奖结果l 体彩七星彩 什么方法买平特肖最准 极速赛车开奖结果 极速赛车大小单双技巧 贵州快3开奖历史 陕西体彩11选5电子图 青海十一选五台子 拉伯配资