Jump to content

Help need with C# coding (again) Please help! :)

- - - - -

  • Please log in to reply
4 replies to this topic

#1
Bondy007

Bondy007

    Newbie

  • Members
  • Pip
  • 4 posts
Hey guys ive been trying to get this program to work properly however i have ran into a few errors that i cant work around if someone could have a look and tell me where i am going wrong i would be most thankful, i would ask my lecture but unfortunately, shes ****. so im kinda on my own here guys and help will be much appreciated. here is my current code


using System;


namespace Tut2
{
public abstract class Employee
{
private string _ID, _Name, _Address, _Contact;
private bool _Resident;

public string ID
{
get { return _ID; }
}
public string Name
{
get { return _Name; }
}
public string Address
{
get { return _Address; }
}
public string Contact
{
get { return _Contact; }
}
public bool Resident
{
get { return _Resident; }
}
public Employee(string id, string name, string address, string contact, bool resident)
{
_ID = id;
_Name = name;
_Address = address;
_Contact = contact;
_Resident = resident;
}
public abstract decimal Calculate(ushort hours);

public abstract decimal PayRate();

public override string ToString()
{
string status;
if (_Resident == true)
status = "Yes";
else
status = "No";
return string.Format("{0}::{1} - Resident {3}\n\tContact Details: {4} - {5}", _ID, _Name, status, _Address, _Contact);
}

}
public class Salary : Employee
{
private decimal _AnnualSalary;
public decimal AnnualSalary
{
get { return _AnnualSalary; }
}

public Salary(string id, string name, string address, string contact, bool resident, decimal salary)
: base(id, name, address, contact, resident)
{
_AnnualSalary = salary;
}
public Salary(Salary salary)
{

}
public override decimal Calculate(ushort hours)
{

}
public override decimal PayRate()
{

}
public override string ToString()
{
return string.Format("{0}\n\t Annual Salary: {1:c}", base.ToString(), _AnnualSalary);
}
}
public class Wage : Employee
{
private decimal _Rate;
public decimal Rate
{
get { return _Rate; }
}
public Wage(string id, string name, string address, string contact, bool resident, decimal rate)
: base(id, name, address, contact, resident)
{
_Rate = rate;
}
public Wage(Wage wage)
{

}
public override decimal Calculate(ushort hours)
{

}
public override decimal PayRate()
{

}
public override string ToString()
{
return string.Format("{0}\n\t Hourly Rate: {1:c}", base.ToString(), _Rate);
}
}
public class Payroll
{
private Employee _Employee;
private ushort _Hours;

public Employee Employee
{
get { return _Employee; }
}
public ushort Hours
{
get { return _Hours; }
}
public Payroll(Employee employee, ushort hours)
{
_Employee = employee;
_Hours = hours;
}
public Payroll(payroll Payroll)
{

}
public override decimal Calculate(ushort hours)
{

}
public override string ToString()
{
return string.Format("");
}
}
class Program
{
static void Main(string[] args)
{
Employee[] employee = new Employee[]
{
new Salary("S001", "John Smith", "12 Albert Street - Melbourne - Vic. 3000", "9311 1111", true, 180001m),
new Salary("S002", "Jenny Smith", "12 Albert Street - Melbourne - Vic. 3000", "93111 111", true,80001m),
new Salary("S003", "Jessica Smith", "12 Albert Street - Melbourne - Vic. 3000", "9311 1111", true,35001m),
new Salary("S004", "Tom Brown", "18/9 Spring Road - Noble Park - Vic. 3174", "9777 7777", true, 5001m),
new Salary("S005", "Katherine Zhang", "402/200 Ballarat Rd - Footscray - VIC 3011", "9344 4444", false, 27000m),
new Wage("W001", "Ben Brown", "18/9 Spring Road - Noble Park - Vic. 3174", "9777 7777", true, 17.5M),
new Wage("W002", "July Wang", "34 Smith Street - Collingwood - Vic. 3066", "9322 3231", false, 15.0M),
new Wage("W003", "Tim Garner", "603/250 Barkly St - Footscray - VIC 3011", "9321 7165", true,32.5M),
new Wage("W004", "Tod Jones", "4/27 Gordon St - Footscray - VIC 3011", "9335 7189", true, 25.0M),
new Wage("W005", "Kate Anderson", "1 Rosemary Street - Chadstone - VIC 3148", "9522 3233", true,10.0M)
};

Console.WriteLine("Employee List:\n{0}", new string('=', 40));
foreach (Employee staff in employee)
Console.WriteLine(staff + "\n");
Console.WriteLine();

Payroll[] payroll = new Payroll[]
{
new Payroll(employee[0], 38),
new Payroll(employee[1], 39),
new Payroll(employee[2], 46),
new Payroll(employee[3], 51),
new Payroll(employee[4], 20),
new Payroll(employee[4], 40),
new Payroll(employee[5], 38),
new Payroll(employee[6], 39),
new Payroll(employee[6], 46),
new Payroll(employee[7], 51),
new Payroll(employee[7], 37),
new Payroll(employee[8], 120),
new Payroll(employee[9], 10),
new Payroll(employee[9], 38)
};

Console.WriteLine("Payroll List:\n{0}", new string('=', 40));
foreach (Payroll item in payroll)
Console.WriteLine(item + "\n");
Console.WriteLine();

}
}
}





I will also attach it as a CS file.

Thank you, Bondy

Attached Files



#2
PsychoCoder

PsychoCoder

    Learning Programmer

  • Members
  • PipPipPip
  • 92 posts
It sure would help if you provided some additional information, such as:

  • Are you getting errors (if so what exactly are they)?
  • What's this code doing versus what you need it to do?

Without this information we really have nowhere to start :)
SELECT * FROM Users WHERE Clue > 0;
ERROR: 0 results returned
Posted Image

#3
Bondy007

Bondy007

    Newbie

  • Members
  • Pip
  • 4 posts
Sorry Mate ive been rushing around trying to get this done and didnt have time to sit down and post properly. ok sooo the current errors are:


Error 1 'Tut2.Employee' does not contain a constructor that takes 0 arguments
Error 4 'Tut2.Employee' does not contain a constructor that takes 0 arguments
Error 8 'Tut2.Payroll.Calculate(ushort)': not all code paths return a value
Error 2 'Tut2.Salary.Calculate(ushort)': not all code paths return a value
Error 3 'Tut2.Salary.PayRate()': not all code paths return a value
Error 5 'Tut2.Wage.Calculate(ushort)': not all code paths return a value
Error 6 'Tut2.Wage.PayRate()': not all code paths return a value
Error 7 The type or namespace name 'payroll' could not be found (are you missing a using directive or an assembly reference?)

so far the code is doing nothing because the errors wont let it build:

however the code is ment to be pretty basic and produce this output:

Employee List:
========================================
S001 :: John Smith - Resident Yes
Contact Details: 12 Albert Street - Melbourne - Vic. 3000 - 9311 1111
Annual Salary: $180,001.00

S002 :: Jenny Smith - Resident Yes
Contact Details: 12 Albert Street - Melbourne - Vic. 3000 - 93111 111
Annual Salary: $80,001.00

S003 :: Jessica Smith - Resident Yes
Contact Details: 12 Albert Street - Melbourne - Vic. 3000 - 9311 1111
Annual Salary: $35,001.00

S004 :: Tom Brown - Resident Yes
Contact Details: 18/9 Spring Road - Noble Park - Vic. 3174 - 9777 7777
Annual Salary: $5,001.00

S005 :: Katherine Zhang - Resident No
Contact Details: 402/200 Ballarat Rd - Footscray - VIC 3011 - 9344 4444
Annual Salary: $27,000.00

W001 :: Ben Brown - Resident Yes
Contact Details: 18/9 Spring Road - Noble Park - Vic. 3174 - 9777 7777
Hourly Rate: $17.50


W002 :: July Wang - Resident No
Contact Details: 34 Smith Street - Collingwood - Vic. 3066 - 9322 3231
Hourly Rate: $15.00

W003 :: Tim Garner - Resident Yes
Contact Details: 603/250 Barkly St - Footscray - VIC 3011 - 9321 7165
Hourly Rate: $32.50

W004 :: Tod Jones - Resident Yes
Contact Details: 4/27 Gordon St - Footscray - VIC 3011 - 9335 7189
Hourly Rate: $25.00

W005 :: Kate Anderson - Resident Yes
Contact Details: 1 Rosemary Street - Chadstone - VIC 3148 - 9522 3233
Hourly Rate: $10.00


Payroll List:
========================================
S001 :: John Smith - Resident Yes
Contact Details: 12 Albert Street - Melbourne - Vic. 3000 - 9311 1111
Annual Salary: $180,001.00 - Worked Hours: 38
Gross Earnings: $3,461.56 - Tax Amount: $1,074.05 - Net Income: $2,387.51

S002 :: Jenny Smith - Resident Yes
Contact Details: 12 Albert Street - Melbourne - Vic. 3000 - 93111 111
Annual Salary: $80,001.00 - Worked Hours: 39 - Over Time: $52.63
Gross Earnings: $1,591.11 - Tax Amount: $363.28 - Net Income: $1,227.84

S003 :: Jessica Smith - Resident Yes
Contact Details: 12 Albert Street - Melbourne - Vic. 3000 - 9311 1111
Annual Salary: $35,001.00 - Worked Hours: 46 - Over Time: $187.76
Gross Earnings: $860.85 - Tax Amount: $139.99 - Net Income: $720.87

S004 :: Tom Brown - Resident Yes
Contact Details: 18/9 Spring Road - Noble Park - Vic. 3174 - 9777 7777
Annual Salary: $5,001.00 - Worked Hours: 51 - Over Time: $40.75
Gross Earnings: $136.92 - Tax Amount: $3.23 - Net Income: $133.69

S005 :: Katherine Zhang - Resident No
Contact Details: 402/200 Ballarat Rd - Footscray - VIC 3011 - 9344 4444
Annual Salary: $27,000.00 - Worked Hours: 20
Gross Earnings: $273.28 - Tax Amount: $79.25 - Net Income: $194.03

S005 :: Katherine Zhang - Resident No
Contact Details: 402/200 Ballarat Rd - Footscray - VIC 3011 - 9344 4444
Annual Salary: $27,000.00 - Worked Hours: 40 - Over Time: $35.53
Gross Earnings: $554.76 - Tax Amount: $160.88 - Net Income: $393.88

W001 :: Ben Brown - Resident Yes
Contact Details: 18/9 Spring Road - Noble Park - Vic. 3174 - 9777 7777
Hourly Rate: $17.50 - Worked Hours: 38
Gross Earnings: $665.00 - Tax Amount: $82.44 - Net Income: $582.56

W002 :: July Wang - Resident No
Contact Details: 34 Smith Street - Collingwood - Vic. 3066 - 9322 3231
Hourly Rate: $15.00 - Worked Hours: 39 - Over Time: $19.50
Gross Earnings: $589.50 - Tax Amount: $170.96 - Net Income: $418.55

W002 :: July Wang - Resident No
Contact Details: 34 Smith Street - Collingwood - Vic. 3066 - 9322 3231
Hourly Rate: $15.00 - Worked Hours: 46 - Over Time: $159.00
Gross Earnings: $729.00 - Tax Amount: $212.16 - Net Income: $516.84

W003 :: Tim Garner - Resident Yes
Contact Details: 603/250 Barkly St - Footscray - VIC 3011 - 9321 7165
Hourly Rate: $32.50 - Worked Hours: 51 - Over Time: $523.25
Gross Earnings: $1,758.25 - Tax Amount: $426.79 - Net Income: $1,331.46

W003 :: Tim Garner - Resident Yes
Contact Details: 603/250 Barkly St - Footscray - VIC 3011 - 9321 7165
Hourly Rate: $32.50 - Worked Hours: 37
Gross Earnings: $1,202.50 - Tax Amount: $242.48 - Net Income: $960.02

W004 :: Tod Jones - Resident Yes
Contact Details: 4/27 Gordon St - Footscray - VIC 3011 - 9335 7189
Hourly Rate: $25.00 - Worked Hours: 100 - Over Time: $2,852.50
Gross Earnings: $3,802.50 - Tax Amount: $1,227.47 - Net Income: $2,575.03

W005 :: Kate Anderson - Resident Yes
Contact Details: 1 Rosemary Street - Chadstone - VIC 3148 - 9522 3233
Hourly Rate: $10.00 - Worked Hours: 10
Gross Earnings: $100.00 - Tax Amount: $0.00 - Net Income: $100.00

W005 :: Kate Anderson - Resident Yes
Contact Details: 1 Rosemary Street - Chadstone - VIC 3148 - 9522 3233
Hourly Rate: $10.00 - Worked Hours: 38
Gross Earnings: $380.00 - Tax Amount: $39.69 - Net Income: $340.31


Sorry if this dosent help much, i havent been programming very long and up until recently id only had experiance with VB which in comparison is ALOT easier. and as i said my lecturer does not help lol. if there is anything else you need please just let me know. Thank You so much, Mate

Cheers Bondy

#4
PsychoCoder

PsychoCoder

    Learning Programmer

  • Members
  • PipPipPip
  • 92 posts
Ok for errors 1 and 2:

Quote

Error 1 'Tut2.Employee' does not contain a constructor that takes 0 arguments


public Employee(string id, string name, string address, string contact, bool resident)
{
_ID = id;
_Name = name;
_Address = address;
_Contact = contact;
_Resident = resident;
}

Notice your constructor for Employee, it's looking for 5 parameters, but when you instantiate the Employee class you dont pass it any parameters
Employee[] employee = new Employee[] 
So you need to add a constructor that takes no parameters or when you instantiate your Employee class you need to provide the parameters it's looking for.


For error 2 and 3

Quote

'Tut2.Payroll.Calculate(ushort)': not all code paths return a value

Look at the Calculate method in the Payrol class

public override decimal Calculate(ushort hours)
{
      //you need code in here's that returns a value
}

It's supposed to return a value that's of type decimal, but it's an empty method, so it's not returning a value

For error 4

Quote

'Tut2.Salary.PayRate()': not all code paths return a value

Same as errors 2 and 3, Calculate isnt returning a value

public override decimal Calculate(ushort hours)
{
     //you need code in here that returns a value
}

Error 5, 6, and 7 are the same as the above, your methods aren't returning a value

As for your last error

Quote

The type or namespace name 'payroll' could not be found (are you missing a using directive or an assembly reference?)

C# is a strongly typed language (it's case sensitive) and your class is Payroll, which isnt the same as payroll.
SELECT * FROM Users WHERE Clue > 0;
ERROR: 0 results returned
Posted Image

#5
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
Just a note for Bondy007. When you post code please use
 
tags. It makes it much easier to read. Thanks mate.
-CDG10620
Software Developer




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users