Question

In: Computer Science

reate a class Song with the data members listed below: title: string the name of the...

reate a class Song with the data members listed below:

  • title: string the name of the song. (initialize to empty string)
  • artist: string the name of the artist. (initialize to the empty string)
  • downloads: int the number of times the song has been downloaded. (initialize to 0)

Include the following member functions:

  • default constructor,
  • a constructor with parameters for each data member (in the order given above),
  • getters and setter methods for each data member named in camel-case.  For example, if a class had a data member named myData, the class would require methods named in camel-case: getMyData and setMyData.
  • double grossRevenue(double price): This function should take in a price per download and returns the total revenue for the song (revenue = price * downloads).

You only need to write the class definition and any code that is required for that class (i.e., header and implementation).

NOTE: you must not use the implicit "private" for class data types and methods. Include public or private explicitly.

Solutions

Expert Solution

class Song {
   private String title;
   private String artist;
   private int downloads;
  
   public Song() {
       title = "";
       artist = "";
       downloads = 0;
   }

   public Song(String title, String artist, int downloads) {
       this.title = title;
       this.artist = artist;
       this.downloads = downloads;
   }

   public String getTitle() {
       return title;
   }

   public void setTitle(String title) {
       this.title = title;
   }

   public String getArtist() {
       return artist;
   }

   public void setArtist(String artist) {
       this.artist = artist;
   }

   public int getDownloads() {
       return downloads;
   }

   public void setDownloads(int downloads) {
       this.downloads = downloads;
   }
  
   public double grossRevenue(double price) {
       return price * downloads;
   }
}


Related Solutions

C++ language: Class Song The class will have the following private attributes: Title (string) Artist (string)...
C++ language: Class Song The class will have the following private attributes: Title (string) Artist (string) Album (string) PlayTime (integer) Year (integer) It will also have the following public member functions: default constructor setting the playtime to 0 and year to 0. a constructor using Title, Artist, Album, Year, and PlayTime as arguments accessors and mutators for all private attributes a void function 'Play' that will print out the information about the song in the following format (provided) Playing *Title*...
Create a class, called Song. Song will have the following fields:  artist (a string) ...
Create a class, called Song. Song will have the following fields:  artist (a string)  title (a string)  duration (an integer, recorded in seconds)  collectionName (a string) All fields, except for collectionName, will be unique for each song. The collectionName will have the same value for all songs. In addition to these four fields, you will also create a set of get/set methods and a constructor. The get/set methods must be present for artist, title, and duration....
#include <iostream> #include <string> #include <vector> using namespace std; class Song{ public: Song(); //default constructor Song(string...
#include <iostream> #include <string> #include <vector> using namespace std; class Song{ public: Song(); //default constructor Song(string t, string a, double d); //parametrized constructor string getTitle()const; // return title string getAuthor()const; // return author double getDurationMin() const; // return duration in minutes double getDurationSec() const; // return song's duration in seconds void setTitle(string t); //set title to t void setAuthor(string a); //set author to a void setDurationMin(double d); //set durationMin to d private: string title; //title of the song string author;...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance:...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance: balance held in the account interestRate: annual interest rate. accountID: unique 3 digit account number assigned to each BankAccount object. Use a static data member to generate this unique account number for each BankAccount count: A static data member to track the count of the number of BankAccount objects created. Member Functions void withdraw(double amount): function which withdraws an amount from accountBalance void deposit(double...
In Java, Here is a basic Name class. class Name { private String first; private String...
In Java, Here is a basic Name class. class Name { private String first; private String last; public Name(String first, String last) { this.first = first; this.last = last; } public boolean equals(Name other) { return this.first.equals(other.first) && this.last.equals(other.last); } } Assume we have a program (in another file) that uses this class. As part of the program, we need to write a method with the following header: public static boolean exists(Name[] names, int numNames, Name name) The goal of...
Assume you have created the following data definition class: public class Book {    private String title;...
Assume you have created the following data definition class: public class Book {    private String title;    private double cost;       public String getTitle() { return this.title; }    public double getCost() { return this.cost; }       public void setTitle(String title) {       this.title = title;    } // Mutator to return true/false instead of using exception handling public boolean setCost(double cost) {       if (cost >= 0 && cost < 100) {          this.cost = cost;          return true;       }       else {          return false;       }...
Create a class tuck shop with following data members: String Owner String Food_Items[100] Double Price [100]...
Create a class tuck shop with following data members: String Owner String Food_Items[100] Double Price [100] Int Quantity [100]                Note: All arrays are open ended. It is not necessary that they are completely filled. All three arrays will work in synchronization with each other i-e the item at index 0 will have its price in Price array at index 0 and quantity at index 0 of Quantity array. Methods: Two Constructors (default, four-argument) set for Owner , get for...
Create a class called Car (Car.java). It should have the following private data members: • String...
Create a class called Car (Car.java). It should have the following private data members: • String make • String model • int year Provide the following methods: • default constructor (set make and model to an empty string, and set year to 0) • non-default constructor Car(String make, String model, int year) • getters and setters for the three data members • method print() prints the Car object’s information, formatted as follows: Make: Toyota Model: 4Runner Year: 2010 public class...
Create a class called Car (Car.java). It should have the following private data members: • String...
Create a class called Car (Car.java). It should have the following private data members: • String make • String model • int year Provide the following methods: • default constructor (set make and model to an empty string, and set year to 0) • non-default constructor Car(String make, String model, int year) • getters and setters for the three data members • method print() prints the Car object’s information, formatted as follows: Make: Toyota Model: 4Runner Year: 2010 public class...
Write a class called Person that has two private data members - the person's name and...
Write a class called Person that has two private data members - the person's name and age. It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Write a separate function (not part of the Person class) called std_dev that takes as a parameter a list of Person objects and returns the standard deviation of all their ages (the population standard deviation that uses a denominator...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT