1Write a class Actor that contains these attributes with the
1.Write a class “Actor” that contains these attributes with the appropriate level of visibility explicitly defined:
“Name” which is a String,
“numberOfAwards” which is an integer
“SAGMember” which is a bool
2.Write a parameterless constructor for this class that initializes the name to “Bob Smith”, the number of awards to 0, and the SAGMember to “false”.
3.Overload the constructor to take in arguments for all three fields.
4.Write a property (get/set) for the name attribute ONLY.
5.Write a method “winsAnOscar” that increases the number of awards by one AND prints “The crowd applauds for ” and the actor’s name to a message dialog box or the console. For this question, as well as 6, make sure your header is complete, with the appropriate level of visibility and any required keywords.
6.Write a method “joinsScreenActorsGuild” which prints out the number of awards the actor has won to the console or a message dialog box and sets SAGMember to true.
The answers to the following questions should be ONE AND ONLY ONE LINE EACH. NUMBER YOUR WORK.
7.Create one instance of Actor in Main, using the parameterless constructor; name the instance a1.
8.Set the name of a1 to “Dustin Hoffman” using property. HINT: See #4
9.Show how you’d invoke the method you wrote for number five on a1.
10.Create a second instance (named a2) using the overloaded constructor; pass in values of your choice.
11.Show how you’d invoke the method you wrote for number six on a2.
12.Print out both a1 and a2 to the console.
(C#)
Solution
using System;
class Actor{
private String actor;
private int numberOfAwards;
private bool SAGMember;
public Actor()
{
actor=\"Bob smith\";
numberOfAwards=0;
SAGMember=false;
}
public Actor(String name, int awards, bool member)
{
actor=name;
numberOfAwards=awards;
SAGMember=member;
}
public String get_actor()
{
return actor;
}
public void set_actor(String name)
{
actor=name;
}
public void winsAnOscar()
{
numberOfAwards+=1;
Console.WriteLine(\"The crows applauds for \" + actor);
}
public void joinsScreenActorsGuild()
{
Console.WriteLine(\"the number of awards,the actor has won \"+numberOfAwards);
SAGMember=true;
}
}
class Program
{
static void Main()
{
//for question 7
Actor a1=new Actor();
//for question 8
a1.set_actor(\"Dustin Hoffman\");
//for question 9
a1.winsAnOscar();
//for question 10
Actor a2=new Actor(\"abc\",2,true);
//for question 11
a2.joinsScreenActorsGuild();
//for question 12
Console.WriteLine(a1);
Console.WriteLine(a2);
}
}

