



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




public class Song {
/** Constructor
public String getSongName() { return title; }
public String getBandName() { return band; }
public void setPrice(double songPrice) { price = songPrice; }
public double getPrice() { return price; }
/** Returns a string representation of a song, listing
/* private instance variables */ private String title; private String band; private double price;
import java.util.*;
public class Album {
/** Constructor
public String getAlbumName() { return title; }
public String getBandName() { return band; }
/** Adds a song to this album. There is no duplicate
/** Returns an iterator over all the songs that are
/** Returns a string representation of an album, listing
/* private instance variables */ private String title; private String band; private ArrayList
/** Lists all the songs carried by the store */ private void listSongs() { println("All songs carried by the store:"); for(int i = 0; i < songs.size(); i++) { println(songs.get(i).toString()); } }
/** Lists all the albums carried by the store */ private void listAlbums() { println("All albums carried by the store:"); Iterator
/** Checks to see if the song (defined by its name and
/** Adds a new song to the store's inventory and returns that
/** Adds a new album to the store's inventory. If the album
if (albums.containsKey(name)) { println("That album is already in the store."); } else { String band = readLine("Band name: "); Album album = new Album(name, band); albums.put(name, album);
while (true) { Song song = addSong(); if (song == null) break; album.addSong(song); } println("New album added to the store."); } }
/** Lists all the songs on a single album in the inventory. */ private void listSongsOnAlbum() { String name = readLine("Album name: "); if (albums.containsKey(name)) { Iterator
/** Updates the price of a song in the store's inventory.
int songIndex = findSong(name, band); if (songIndex == -1) { println("That song is not in the store."); } else { double price = readDouble("New price: "); songs.get(songIndex).setPrice(price); println("Price for " + name + " updated."); }