I need to output the following from my program to a console in C# ; From the mai
ID: 3726882 • Letter: I
Question
I need to output the following from my program to a console in C# ;
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
I think I am almost there, but I cannot get anything I try with writeline to not throw me an error.
//Start Code
using System;
using static System.Console;
namespace Lesson_5_Program
{
//Name class
class EmployeeApp
{
//Start program
static void Main(string[] args)
{
WriteLine();
}
}
public class Employee
{
//Employee number
private int number;
private string firstName;
private string lastName;
private string hireDate;
private string jobDescription;
private double wage;
private double hoursWorked;
private double grossAmount;
//default constructor
public Employee()
{
firstName = "Wayne";
lastName = "Dancer";
hireDate = "02/02/2017";
jobDescription = "developing contenet";
wage = 30;
hoursWorked = 40;
}
//parameterized constructor
public Employee(int number, string firstName, string lastName,
string hireDate, string jobDescription, string department, long wage,
double hoursWorked, double grossAmount)
{
this.number = number;
this.firstName = firstName;
this.lastName = lastName;
this.hireDate = hireDate;
this.jobDescription = jobDescription;
this.wage = wage;
this.hoursWorked = hoursWorked;
this.grossAmount = grossAmount;
}
//copy constructor
public Employee(Employee e)
{
number = e.number;
firstName = e.firstName;
lastName = e.lastName;
hireDate = e.hireDate;
jobDescription = e.jobDescription;
wage = e.wage;
hoursWorked = e.hoursWorked;
grossAmount = e.grossAmount;
}
//property to read or set first name
public string FirstName
{
get
{
return firstName;
}
set
{
firstName = value;
}
}
//property to read or set last name
public string LastName
{
get
{
return lastName;
}
set
{
lastName = value;
}
}
//property to read or set hire date
public string Hiredate
{
get
{
return hireDate;
}
set
{
hireDate = value;
}
}
//property to read or set job description
public string JobDescription
{
get
{
return jobDescription;
}
set
{
jobDescription = value;
}
}
//property to read or set wage
public double Wage
{
get
{
return wage;
}
set
{
wage = value;
}
}
//property to read or set hours worked
public double HoursWorked
{
get
{
return hoursWorked;
}
set
{
hoursWorked = value;
}
}
//Make and return name of employee
public string GetName()
{
return firstName + " " + lastName;
}
//Make and return payment for hours worked
public double GrossAmount(double wage, double hoursworked)
{
return grossAmount = (wage * hoursWorked);
}
}
}
//End Code
Explanation / Answer
using System;
public class EmployeeApp
{
//Start program
static void Main(string[] args)
{
Employee emp = new Employee();//using default constructor
Console.WriteLine("Employee Full Name : "+emp.FirstName +" "+emp.LastName);
Console.WriteLine("Hire Date : "+emp.Hiredate);
Console.WriteLine("Job Description : "+emp.JobDescription);
Console.WriteLine("Wage : "+emp.Wage);
Console.WriteLine("Hours Worked : "+emp.HoursWorked);
Console.WriteLine("Gross Pay : $"+emp.GrossAmount());
}
}
class Employee
{
//Employee number
private int number;
private string firstName;
private string lastName;
private string hireDate;
private string jobDescription;
private double wage;
private double hoursWorked;
//default constructor
public Employee()
{
firstName = "Wayne";
lastName = "Dancer";
hireDate = "02/02/2017";
jobDescription = "developing contenet";
wage = 30;
hoursWorked = 40;
}
//parameterized constructor
public Employee(int number, string firstName, string lastName,
string hireDate, string jobDescription, string department, long wage,
double hoursWorked)
{
this.number = number;
this.firstName = firstName;
this.lastName = lastName;
this.hireDate = hireDate;
this.jobDescription = jobDescription;
this.wage = wage;
this.hoursWorked = hoursWorked;
}
//copy constructor
public Employee(Employee e)
{
number = e.number;
firstName = e.firstName;
lastName = e.lastName;
hireDate = e.hireDate;
jobDescription = e.jobDescription;
wage = e.wage;
hoursWorked = e.hoursWorked;
}
//property to read or set first name
public string FirstName
{
get
{
return firstName;
}
set
{
firstName = value;
}
}
//property to read or set last name
public string LastName
{
get
{
return lastName;
}
set
{
lastName = value;
}
}
//property to read or set hire date
public string Hiredate
{
get
{
return hireDate;
}
set
{
hireDate = value;
}
}
//property to read or set job description
public string JobDescription
{
get
{
return jobDescription;
}
set
{
jobDescription = value;
}
}
//property to read or set wage
public double Wage
{
get
{
return wage;
}
set
{
wage = value;
}
}
//property to read or set hours worked
public double HoursWorked
{
get
{
return hoursWorked;
}
set
{
hoursWorked = value;
}
}
//Make and return name of employee
public string GetName()
{
return firstName + " " + lastName;
}
//Make and return payment for hours worked
public double GrossAmount()
{
return (wage * hoursWorked);
}
}
Output:
Employee Full Name : Wayne Dancer
Hire Date : 02/02/2017
Job Description : developing contenet
Wage : 30
Hours Worked : 40
Gross Pay : $1200