Answer to Question #349923 in C# for Johnny

Question #349923

Create a new project, and include in it the class


Create a class "Student" and another class "Teacher", both descendants of


"Person".


The class "Student" will have a public method "GoToClasses", which will


write on screen "I’m going to class."


The class "Teacher" will have a public method "Explain", which will show on


screen "Explanation begins". Also, it will have a private attribute "subject", a


string.


The class Person must have a method "SetAge (int n)" which will indicate


the value of their age (eg, 20 years old).


The student will have a public method "ShowAge" which will write on the


screen "My age is: 20 years old" (or the corresponding number).


You must create another test class called "StudentAndTeacherTest" that will


contain "Main" and:


Create a Person and make it say hello


Create a student, set his age to 21, tell him to Greet and display his age


Create a teacher, 30 years old, ask him to say hello and then explain.


Test the other methods also given in the diagram

1
Expert's answer
2022-06-13T08:30:05-0400
namespace UserNamespace
{


    class StudentAndTeacherTest
    {
        static void Main()
        {
            Person human = new Person();
            human.PersonGreetings();


            Student StudentGuy = new Student();
            StudentGuy.SetAge(21);
            StudentGuy.PersonGreetings();
            StudentGuy.ShowAge();


            Teacher teacher = new Teacher();
            teacher.PersonGreetings();
            teacher.SetAge(30);
            teacher.Explain();
        }


    }
    class Person
    {
        public int age;


        public void PersonGreetings()
        {
            Console.WriteLine("Greetings.");
        }
        public int SetAge(int n)
        {
            age = n;
            return n;
        }




    }


    class Teacher : Person
    {
        private string subject;
        public void Explain()
        {
            Console.WriteLine("Explanation begins");
        }
    }
    class Student : Person
    {
        public void GoToClasses()
        {
            Console.WriteLine("I’m going to class.");
        }
        public void ShowAge()
        {
            Console.WriteLine($"My age is {age} years old.");
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS