/** * A collection of functions for determining how much mp3 music can * fit on various-sized discs/devices. * * @author Ian Barland * @version 2006.Sep.11 */ class Mp3_Size { /** How many minutes of mp3 music which can be stored in 1Gig (approx). */ final double MINS_PER_GIG = 940.0; /** The number of minutes on an album (approx). */ final double MINS_PER_ALBUM = 45.0; /** * return The number of minutes of mp3 music which can fit into `size'. * @return The number of minutes of mp3 music which can fit into `size'. * @param size The amount of storage space, in GB. */ double gbToMins( double size ) { return size * MINS_PER_GIG; } /** * return The number of *complete* albums which can fit into `size'. * @return The number of *complete* albums which can fit into `size'. * @param size An amount of storage space, in GB. */ int gbToAlbums( double size ) { return doubleToInt( Math.floor( gbToMins(size) / MINS_PER_ALBUM ) ); } /** * Print to the screen, a message about how much music `d' can hold. * (No return value.) * @param d An amount of disc space, in GB. */ void printAnAdvertisingSpec(double d) { System.out.println( "A " + d + " GB disk can hold " + gbToAlbums( d ) + " albums." ); } /** * Print to the screen, messages about how much mp3 music can fit * on to various disc sizes. * Suitable for printing on a screen seen by customers. */ void printManyAdvertisingSpecs() { double discSize = 0.0; // A variable just to hold various sizes. printAnAdvertisingSpec( discSize ); discSize = 8.0; printAnAdvertisingSpec( discSize ); discSize = 0.5; printAnAdvertisingSpec( discSize ); discSize = 3.0; printAnAdvertisingSpec( discSize ); discSize = Math.pow( 3, 2 ); printAnAdvertisingSpec( discSize ); } /** * return an integer close to `d' (not specified as rounding up or down though). * @return an integer close to `d' (not specified as rounding up or down though). * @param d A double to be converted. * * WARNING: If d is outside of plus/minus 2.15billion (or so), * this program will silently return a wildly incorrect answer! */ int doubleToInt( double d ) { /* Turn d into an int by casting it. * (You can look up 'casting' in the book.) */ return (int) d; } }