Answer to Question #328707 in C# for vijay

Question #328707

create a class called person


populate the class with below private fields

1.First name as an String

2.Last name as an String

3.email id as string

4.Dateofbirth as DateTime



Add a constructor that accept Firstname,Lastname,Email,DateBirth as Parameter



Add read only properties that return the following computer information

1.Isadult a bool- Whether or not the person is over 18

2.Sunsing as string - the traditional western sun sign of the person

3.Isbirthday as bool - wether or not today is the persons birthday

4 ScreenName as string - a default screeb name that you might seen being offered to a first time user of gmail or yahoo(e.g. hari joe born on may 25th,1980 might be hdoe525 or haridoe052580)





Create a class classed employee which should be driven from person class. employee class should add the following properties

1. Salary as double



in the main method created object of employee class and test

the behavior by calling read-only properties



1
Expert's answer
2022-04-14T08:04:45-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ComputeAverageApp
{
    class ComputeAverageProgram
    {
        static void Main(string[] args)
        {


            Employee employee = new Employee("John", "Doe", "jd@gmail.com", new DateTime(2000, 12, 01), 10000);
           
            Console.WriteLine("Person.IsAdult = {0}", employee.IsAdult);
            Console.WriteLine("Person.Sunsing = {0}", employee.Sunsing);
            Console.WriteLine("Person.Isbirthday = {0}", employee.Isbirthday);
            Console.WriteLine("Person.ScreenName = {0}", employee.ScreenName);
            Console.WriteLine("Person.Salary = {0}", employee.Salary);

            Console.ReadLine();
        }
    }

    public class Person
    {
        private string FirstName;
        private string LastName;
        private string email;
        private DateTime DateOfBirth;

        public Person(string fName, string lName, string mail, DateTime bDate)
        {
            FirstName = fName;
            LastName = lName;
            email = mail;
            DateOfBirth = bDate;
        }

        public bool IsAdult {
            get
            {
                bool result = false;
                if (DateTime.Now.Year - DateOfBirth.Year >= 18)
                    result = true;
                return result;
            }
        }

        public string Sunsing
        {
            get
            {
                string result = "";
                if ((DateOfBirth.Month >= 3 && (DateOfBirth.Day >= 21 || DateOfBirth.Day <=31 )) && (DateOfBirth.Month <= 4 && (DateOfBirth.Day <= 19 || DateOfBirth.Day >= 1)))
                    result = "Aries";
                if ((DateOfBirth.Month >= 4 && (DateOfBirth.Day >= 20 || DateOfBirth.Day <= 31)) && (DateOfBirth.Month <= 5 && (DateOfBirth.Day <= 20 || DateOfBirth.Day >= 1)))
                    result = "Taurus";
                if ((DateOfBirth.Month >= 5 && (DateOfBirth.Day >= 21 || DateOfBirth.Day <= 31)) && (DateOfBirth.Month <= 6 && (DateOfBirth.Day <= 21 || DateOfBirth.Day >= 1)))
                    result = "Gemini";
                if ((DateOfBirth.Month >= 6 && (DateOfBirth.Day >= 21 || DateOfBirth.Day <= 31)) && (DateOfBirth.Month <= 7 && (DateOfBirth.Day <= 22 || DateOfBirth.Day >= 1)))
                    result = "Cancer";
                if ((DateOfBirth.Month >= 7 && (DateOfBirth.Day >= 23 || DateOfBirth.Day <= 31)) && (DateOfBirth.Month <= 8 && (DateOfBirth.Day <= 22 || DateOfBirth.Day >= 1)))
                    result = "Leo";
                if ((DateOfBirth.Month >= 8 && (DateOfBirth.Day >= 23 || DateOfBirth.Day <= 31)) && (DateOfBirth.Month <= 9 && (DateOfBirth.Day <= 22 || DateOfBirth.Day >= 1)))
                    result = "Virgo";
                if ((DateOfBirth.Month >= 9 && (DateOfBirth.Day >= 23 || DateOfBirth.Day <= 31)) && (DateOfBirth.Month <= 10 && (DateOfBirth.Day <= 23 || DateOfBirth.Day >= 1)))
                    result = "Libra";
                if ((DateOfBirth.Month >= 10 && (DateOfBirth.Day >= 24 || DateOfBirth.Day <= 31)) && (DateOfBirth.Month <= 11 && (DateOfBirth.Day <= 21 || DateOfBirth.Day >= 1)))
                    result = "Scorpius";
                if ((DateOfBirth.Month >= 11 && (DateOfBirth.Day >= 22 || DateOfBirth.Day <= 31)) && (DateOfBirth.Month <= 12 && (DateOfBirth.Day <= 21 || DateOfBirth.Day >= 1)))
                    result = "Sagittarius";
                if ((DateOfBirth.Month >= 12 && (DateOfBirth.Day >= 22 || DateOfBirth.Day <= 31)) || (DateOfBirth.Month <= 1 && (DateOfBirth.Day <= 19 || DateOfBirth.Day >= 1)))
                    result = "Capricornus";
                if ((DateOfBirth.Month >= 1 && (DateOfBirth.Day >= 20 || DateOfBirth.Day <= 31)) && (DateOfBirth.Month <= 2 && (DateOfBirth.Day <= 18 || DateOfBirth.Day >= 1)))
                    result = "Aquarius";
                if ((DateOfBirth.Month >= 2 && (DateOfBirth.Day >= 19 || DateOfBirth.Day <= 31)) && (DateOfBirth.Month <= 3 && (DateOfBirth.Day <= 20 || DateOfBirth.Day >= 1)))
                    result = "Pisces";

                return result;
            }
        }

        public bool Isbirthday
        {
            get
            {
                bool result = false;
                if (DateTime.Now.Month == DateOfBirth.Month && DateTime.Now.Day == DateOfBirth.Day)
                    result = true;
                return result;
            }
        }


        public string ScreenName
        {
            get
            {
                string result = "";
                result = String.Format("{0}{1}{2}{3}{4}", LastName.Substring(0, 2), FirstName, DateOfBirth.Day, DateOfBirth.Month, DateOfBirth.Year);
                return result;
            }
        }
    }
 
    public class Employee : Person
    {
        public double Salary { get; set; }

        public Employee(string fName, string lName, string mail, DateTime bDate, double sal) : base(fName, lName, mail, bDate)
        {
            Salary = sal;
        }
    }
}

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