Using C# Create a class called Artist that contains 4 pieces of information as i
ID: 3788225 • Letter: U
Question
Using C#
Create a class called Artist that contains 4 pieces of information as instance variables: name (datatype string), specialization – i.e., music, pottery, literature, paintings (datatype string), number of art items (datatype int), country of birth (datatype string).
Create a constructor that initializes the 4 instance variables. The Artist class must contain a property for each instance variable with get and set accessors. The property for number should verify that the Artist contributions is greater than zero. If a negative value is passed in, the set accessor should set the Artist’s number to 0.
Create a second class ArtistTest that creates two Artist objects using the constructor that you developed in the Artist class. Display the name, specialization, number of art items, country of birth. Your assignment submission must include
Explanation / Answer
using System;
public class Artist
{
private string name;
private string specialization;
private int artItems;
private string birthCountry;
//constructor
public Artist(string name,string specialization,int artItems,string birthCountry)
{
this.name = name;
this.specialization = specialization;
this.artItems = artItems;
this.birthCountry = birthCountry;
}
//properties
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public string Specialization
{
get
{
return specialization;
}
set
{
specialization = value;
}
}
public int ArtItems
{
get
{
return artItems;
}
set
{
if(value > 0)
artItems = value;
else
artItems = 0; //if artItems is negative set the artItems = 0
}
}
public string BirthCountry
{
get
{
return birthCountry;
}
set
{
birthCountry = value;
}
}
}
public class ArtistTest
{
public static void Main()
{
Artist A1 = new Artist("Picasso","Painting",300,"Spain");
Artist A2 = new Artist("William Shakespear","Poetry",150,"England");
//calling properties
Console.WriteLine(A1.Name+" has created "+A1.ArtItems +" " +A1.Specialization+ " belonged to "+A1.BirthCountry);
Console.WriteLine(A2.Name+" has created "+A2.ArtItems +" " +A2.Specialization+ " belonged to "+A2.BirthCountry);
}
}
output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.