Colorado State University

Recitation R11 - Music Class
Summer 2016

CS160: Foundations in Programming

Music Class


  • Define the following as private instance (non-static) data:
        private String songTitle;
        private String albumName;
        private String artistName;
        private int releaseYear;


    1. Define a constructor takes three Strings called title, album, and artist and one integer called year. Use these parameters to assign values to the instance variables.
      • Remember, a constructor is just like a normal method except uses the class for its name and it has no return value (not even void).

    2. Create getter/accessor methods. These are public non-static methods that return the corresponding instance variables. The method signatures should match the exact signatures shown below:
          // Accessor methods
          public String getTitle() { }
          public String getAlbum() { }
          public String getArtist() { }
          public int getYear() { }
    3. Write a toString method that returns a string with the instance variables corresponding to the title, album, artist, and year, separated by commas and a space, with no trailing commas, spaces or newlines. An example of this String is as follows:
          Brown Eyed Girl, Blowin' Your Mind!, Van Morrison, 1967
    4. Implement a public non-static method called getPrice that has no parameters and returns a double.
      This method should return the price of the title according to the following rules.
      The algorithm for determining the price is:

      • $1.29 for titles released before 1970
      • $1.89 for titles released in the 1970's
      • $0.69 for titles released in the 1980's
      • $0.99 for titles released in the 1990's
      • $1.39 for titles released between 2000 and 2009
      • $0.59 for titles released in 2010 and later.

      The reasoning for this is that some decades have better music than others!

      Once you are finished, go back to R11 and start working on the next part.

    © 2016 CS160 Colorado State University. All Rights Reserved.