Question

In: Computer Science

C# Programming (Class Registration class) Add a Schedule property to the Person class. Add a new...

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
}

Solutions

Expert Solution

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
}


Related Solutions

Programming Language: C# Person Class Fields - password : string Properties + «C# property, setter private»...
Programming Language: C# Person Class Fields - password : string Properties + «C# property, setter private» IsAuthenticated : bool + «C# property, setter absent» SIN : string + «C# property, setter absent» Name : string Methods + «Constructor» Person(name : string, sin : string) + Login(password : string) : void + Logout() : void + ToString() : string Transaction Class Properties + «C# property, setter absent » AccountNumber : string + «C# property, setter absent» Amount : double + «C#...
Description In C# Further enhance the registration program for Continental University. Add more attributes about a...
Description In C# Further enhance the registration program for Continental University. Add more attributes about a student, including gender, residency (in-state or out-state), and entrance date. Allow the user to repeatedly enter student information until the user wants to quit. When the user enters an invalid value, ask the user to repeatedly enter the value until a valid value has been entered. Gender must be ‘M’ or ‘F’. Residency must be ‘I’ or ‘O’. Display a short summary after each...
Lab 1 Write a program in the C/C++ programming language to input and add two fractions...
Lab 1 Write a program in the C/C++ programming language to input and add two fractions each represented as a numerator and denominator. Do not use classes or structures. Print your result (which is also represented as a numerator/denominator) to standard out. If you get done early, try to simplify your result with the least common denominator. The following equation can be used to add fractions: a/b + c/d = (a*d + b*c)/(b*d) Example: 1/2 + 1/4 = ( 1(4)...
C++ * Program 2:      Create a date class and Person Class.   Compose the date class...
C++ * Program 2:      Create a date class and Person Class.   Compose the date class in the person class.    First, Create a date class.    Which has integer month, day and year    Each with getters and setters. Be sure that you validate the getter function inputs:     2 digit months - validate 1-12 for month     2 digit day - 1-3? max for day - be sure the min-max number of days is validate for specific month...
Write a C program that calculates a student grade in the C Programming Class. Ask the...
Write a C program that calculates a student grade in the C Programming Class. Ask the user to enter the grades for each one of the assignments completed in class: Quiz #1 - 25 points Quiz #2 - 50 points Quiz #3 - 30 points Project #1 - 100 points Project #2 - 100 points Final Test - 100 points The total of the quizzes count for a 30% of the total grade, the total of the projects counts for...
WRITE IN C++ Add to the Coord class Edit the provided code in C++ Write a...
WRITE IN C++ Add to the Coord class Edit the provided code in C++ Write a member function named      int distance2origin() that calculates the distance from the (x, y, z) point to the origin (0, 0, 0) the ‘prototype’ in the class definition will be      int distance2origin() outside the class definition             int Coord :: distance2origin() {                         // your code } _______________________________________________________________________________________________________ /************************************************** * * program name: Coord02 * Author: * date due: 10/19/20 * remarks:...
C++ Programming 1) What is the feature that makes a base class an abstract class? 2)...
C++ Programming 1) What is the feature that makes a base class an abstract class? 2) When designing a class hierarchy involving classes A and B, what are the two questions that must be asked to determine whether class B should be derived from class A?
c++ programming 1.1 Class definition Define a class bankAccount to implement the basic properties of a...
c++ programming 1.1 Class definition Define a class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data:  Account holder’s name (string)  Account number (int)  Account type (string, check/savings/business)  Balance (double)  Interest rate (double) – store interest rate as a decimal number.  Add appropriate member functions to manipulate an object. Use a static member in the class to automatically assign account numbers. 1.2 Implement...
Class object in C++ programming language description about lesson base class and derived class example.
Class object in C++ programming language description about lesson base class and derived class example.
c++ Add exception handling to the MyStack class (e.g. an instance of the class should throw...
c++ Add exception handling to the MyStack class (e.g. an instance of the class should throw an exception if an attempt is made to remove a value from an empty stack) and use the MyStack class to measure the execution cost of throwing an exception. Create an empty stack and, within a loop, repeatedly execute the following try block: try { i n t s t a c k . pop ( ) ; } catch ( e x c...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT