Answer to Question #216962 in C# for Question 02

Question #216962

Create the classes required to store data regarding different types of Courses. All course shave name, duration and course fee. Some courses are part time where you have to storethe timing for course. Some courses are onsite where you have to store the companyname and the no. of candidates for the course. For onsite course we charge 10% more on the course fee. For part-time course, we offer 10% discount.Provide constructors and the following methods.Print() GetTotalFee()


1
Expert's answer
2021-07-14T04:47:56-0400
using System;


namespace trip
{
    class Course
    {
        protected string name;
        protected int duration;
        protected int fee;


        public Course(string name, int duration, int fee)
        {
            this.name = name;
            this.duration = duration;
            this.fee = fee;
        }


        public void Print()
        {
            Console.WriteLine("Name: " + name);
            Console.WriteLine("Duration: " + duration.ToString());
            Console.WriteLine("Fee: " + fee.ToString());
            Console.WriteLine("Total fee: " + GetTotalFee().ToString());
        }


        public virtual double GetTotalFee()
        {
            return fee * duration;
        }
    }


    class PartTimeCourse : Course
    {
        protected int discount;
        public PartTimeCourse(string name, int duration, int fee) : base(name, duration, fee)
        {
            discount = 10;
        }


        public override double GetTotalFee()
        {
            var total = fee * duration;
            return total - (total * discount / 100);
        }
    }


    class OnsiteCourse : Course
    {
        protected double charge;
        public OnsiteCourse(string name, int duration, int fee) : base(name, duration, fee)
        {
            charge = 10;
        }


        public override double GetTotalFee()
        {
            var total = fee * duration;
            return total + (total * charge / 100) ;
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            var course = new Course("course", 10, 100);
            var partCourse = new PartTimeCourse("partCourse", 10, 100);
            var onsiteCourse = new OnsiteCourse("onsiteCourse", 10, 100);


            course.Print();
            partCourse.Print();
            onsiteCourse.Print();
        }
    }
}

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