none
I am stuck, i am new to this

    Question


  • Hello good evening i am new to c# and i need help on the following:

    Create an employee class. Include the following attributes as properties.

    First Name

    Last Name

      Rate of Pay
      Job Title
      Hire Date

      Add an instance method that returns back the employee's full name.

      Add another instance method that calculates the gross amount to pay given the hours the employee worked in the pay period.

      Make sure to create useful constructors for your class.

      From the main method, instantiate the employee class and populate the properties.

      Output the full name using the instance method you created. Output the gross pay given that the employee worked 40 hours using the other instance method that you created.

      Make sure to use the proper types in your properties and return types for your methods.

      This is what i have so far:

      using System;

      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;

      namespace Lesson5
      {
          class Program
          {
              static void Main(string[] args)
              {
                  EmployeeClass PayPeriod = new EmployeeClass();

                  PayPeriod.FirstName = "Roberto";
                  PayPeriod.LastName = "Martinez";
                  PayPeriod.RateOfPay = 25;
                  PayPeriod.JobTitle = "Manager";
                  PayPeriod.HireDate = 01 / 01 / 2017;


                  Console.WriteLine("{0} - {1} - {2}",
                      PayPeriod.FirstName,
                      PayPeriod.LastName,
                      PayPeriod.JobTitle,
                      PayPeriod.RateOfPay,
                      PayPeriod.HireDate);


                  Console.ReadLine();

              }


              }
          }

          class EmployeeClass
          {
              public string FirstName { get; set; }
              public string LastName { get; set; }
              public int RateOfPay { get; set; }
              public string JobTitle { get; set; }
              public int HireDate { get; set; }



          }

      Any help is greatly appreciated!!

      Thank you


    Wednesday, May 3, 2017 11:08 PM

All replies

  • Greetings.

    We're not supposed to do homework assignments here, but since you've had a go and made a start we can give pointers.

    You can make an instance method that returns the employee's full name something like this

        class EmployeeClass
        {
            public string FirstName { get; set; }
            public string LastName { get; set; }
            public int RateOfPay { get; set; }
            public string JobTitle { get; set; }
            public int HireDate { get; set; }
    
    
            // Construct and return the full name.
            public string GetFullName()
            {
               return FirtsName + " " + LastName;
            }
    
        }

    You would then use it something like so...

    Console.WriteLine("Full name is : " + PayPeriod.GetFullName());

    ... or maybe like this.

    string fullName = PayPeriod.GetFullName();
    Console.WriteLine("Full name is : " + fullName);

    Wednesday, May 3, 2017 11:28 PM
  • And then, create a another method that returns the Employee's gross pay, based on the 40 hour week. We'll leave that one for you to do ...

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Thursday, May 4, 2017 4:51 AM
    Moderator
  • Given there is requirement to create meaningful constructor to the class, I don't think your instructor want to see the following lines (why set HireDate as int anyway?).

                 PayPeriod.FirstName = "Roberto";
                 PayPeriod.LastName = "Martinez";
                 PayPeriod.RateOfPay = 25;
                 PayPeriod.JobTitle = "Manager";
                 PayPeriod.HireDate = new DateTime(2017, 1, 1);



    Thursday, May 4, 2017 6:03 AM
    Answerer