In: Computer Science
C# Programming (Class Registration class)
Add a Schedule property to the Person class. Add a new behavior as well: add(Section s) this behavior will add a section to the Person’s schedule. The Person’s display() function will also need to be modified to display() the Person’s Schedule.
Schedule class has Properties: An array of Sections and a Count. Constructors: only a default constructor is needed. Behaviors: add() and display().
This is my schedule class
class Schedule
    {
        private int count =
0;
        private Sections[] sArr
= new Sections[10];
        public void
addSection (Sections s)
        {
           
sArr[count] = s;
           
count++;
        }
        public void
display()
        {
           
for(int i=0; i<count; i++)
           
{
               
sArr[i].display();
           
}
        }
    }
And this is my Person class so far.
class Person
    {
        //Properties
        private string
FirstName;
        private string
LastName;
        private Address address
= new Address();
        private string
Email;
  
        //Constructors
        public Person()
        {
           
FirstName = "";
           
LastName = "";
           
address = new Address ();
           
Email = "";
        }
        public Person(string
fname, string lname, Address a1, string email)
        {
           
FirstName = fname;
           
LastName = lname;
           
address = a1;
           
Email = email;
        }
        //Behaviors
        public void
setFirstName(string fname)
        {
           
FirstName = fname;
        }
        public string
getFirstName()
        {
           
return FirstName;
        }
        public void
setLastName(string lname)
        {
           
LastName = lname;
        }
        public string
getLastName()
        {
           
return LastName;
        }
        public void
setAddress(Address a1)
        {
           
address = a1;
        }
        public Address
getAddress()
        {
           
return address;
        }
        public void
setEmail(string email)
        {
           
Email = email;
        }
        public string
getEmail()
        {
           
return Email;
        }
        //Display Function
        public void
display()
        {
           
Console.WriteLine("First Name = " + getFirstName());
           
Console.WriteLine("Last Name = " + getLastName());
           
Console.WriteLine("Address = " + getAddress());
           
Console.WriteLine("Email = " + getEmail());
        }//end Display
function
    }//end class
}
In the properties section, a Schedule object is added to the Person class.
class Person
    {
        //Properties
        private string
FirstName;
        private string
LastName;
        private Address address
= new Address();
        private string
Email;
private Schedule schedule = new Schedule();
}
The constructor is also edited to accomodate the new property schedule
public Person()
        {
           
FirstName = "";
           
LastName = "";
           
address = new Address ();
           
Email = "";
schedule = new Schedule();
        }
        public Person(string
fname, string lname, Address a1, string email, Schedule s1)
        {
           
FirstName = fname;
           
LastName = lname;
           
address = a1;
           
Email = email;
schedule = s1;
        }
A new behaviour is added to add a section to the persons schedule:
public void add(Section s){
return Schedule.addSection(s);
}
Display section of Persons class is edited to display the persons schedule,
public void display()
        {
           
Console.WriteLine("First Name = " + getFirstName());
           
Console.WriteLine("Last Name = " + getLastName());
           
Console.WriteLine("Address = " + getAddress());
           
Console.WriteLine("Email = " + getEmail());
Console.WriteLine("Schedule =" +
schedule.display())
        }//end Display
function
So the final code is:
class Schedule
    {
        private int count =
0;
        private Sections[] sArr
= new Sections[10];
        public void
addSection (Sections s)
        {
           
sArr[count] = s;
           
count++;
        }
        public void
display()
        {
           
for(int i=0; i<count; i++)
           
{
Console.WriteLine(sArr[i]);
           
}
        }
    }
class Person
    {
        //Properties
        private string
FirstName;
        private string
LastName;
        private Address address
= new Address();
        private string
Email;
private Schedule schedule = new Schedule();
public Person()
        {
           
FirstName = "";
           
LastName = "";
           
address = new Address ();
           
Email = "";
schedule = new Schedule();
        }
        public Person(string
fname, string lname, Address a1, string email, Schedule s1)
        {
           
FirstName = fname;
           
LastName = lname;
           
address = a1;
           
Email = email;
schedule = s1;
        }
//Behaviors
        public void
setFirstName(string fname)
        {
           
FirstName = fname;
        }
        public string
getFirstName()
        {
           
return FirstName;
        }
        public void
setLastName(string lname)
        {
           
LastName = lname;
        }
        public string
getLastName()
        {
           
return LastName;
        }
        public void
setAddress(Address a1)
        {
           
address = a1;
        }
        public Address
getAddress()
        {
           
return address;
        }
        public void
setEmail(string email)
        {
           
Email = email;
        }
        public string
getEmail()
        {
           
return Email;
        }
public void add(Section s){
return schedule.addSection(s);
}
  public void display()
        {
           
Console.WriteLine("First Name = " + getFirstName());
           
Console.WriteLine("Last Name = " + getLastName());
           
Console.WriteLine("Address = " + getAddress());
           
Console.WriteLine("Email = " + getEmail());
Console.WriteLine("Schedule =" +
schedule.display())
        }//end Display
function
}//end class
}