C# using Visual Studio Create a C# console project named MyPlayList. Create an A
ID: 3783319 • Letter: C
Question
C# using Visual Studio
Create a C# console project named MyPlayList.
Create an Album class with 4 instance variables to keep track of title, artist, genre, and copies sold. Each instance variable should have a get/set property. Your Album class should have a constructor to initialize the title. In addition, create a public method in the Album class to calculate amount sold for the album (copies sold * cost_of_album). You determine the cost of each album. Also create a method in the Album class to display your information. Should look something like this:
The album Tattoo You by the Rolling Stones, a Rock group, made $25,000,000.
In your main method, create 3 instances of the Album class with different albums, use getters to set values of the artist, genre, and copies sold. And then display information about each on the console.
Explanation / Answer
using System;
class Album
{
private string title;
private string artist;
private string genre;
private int copies_sold;
// Declare a Title property of type string:
public string Title
{
get
{
return title;
}
set
{
title = value;
}
}
// Declare a Artist property of type string:
public string Artist
{
get
{
return artist;
}
set
{
artist = value;
}
}
// Declare a CopiesSold property of type string:
public int CopiesSold
{
get
{
return copies_sold;
}
set
{
copies_sold = value;
}
}
// Declare a Genre property of type string:
public string Genre
{
get
{
return genre;
}
set
{
genre = value;
}
}
public Album(string title) //constructor to initialize title variable
{
this.title = title;
}
public int amountSold(int cost_of_album) // compute amount earned by album
{
return (copies_sold * cost_of_album);
}
public override string ToString()
{
return "The album "+ title +" by "+ artist +","+ genre +" group, made $";
}
}
public class Test
{
public static void Main()
{
// Create a new Album object:
Album a1 = new Album("Tattoo You");
// Setting title,artist,genre and copies sold
a1.Artist = "Rolling stones";
a1.Genre = "Rock";
a1.CopiesSold = 1000;
Console.WriteLine();
Console.Write("Album Info: {0}", a1);
Console.Write(a1.amountSold(250));
// Create a new Album object:
Album a2 = new Album("God");
// Setting title,artist,genre and copies sold
a2.Artist = "A. J.";
a2.Genre = "Rhymes";
a2.CopiesSold = 1000;
Console.WriteLine();
Console.Write("Album Info: {0}", a2);
Console.Write(a2.amountSold(50));
// Create a new Album object:
Album a3 = new Album("Dancing doll");
// Setting title,artist,genre and copies sold
a3.Artist = "Julia Williams";
a3.Genre = "Dance";
a3.CopiesSold = 1200;
Console.WriteLine();
Console.Write("Album Info: {0}", a3);
Console.Write(a3.amountSold(650));
}
}
output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.