Hello I am having problems completing thi code in C# can someone please tell what I am doing wrong.I ge Error Error 1 Program 'C:\Users\stacey ann loretta\documents\visual studio 2010\Projects\EmployeeEceptionDemo\EmployeeEceptionDemo\obj\x86\Release\EmployeeEceptionDemo.exe' does not contain a static 'Main' method suitable for an entry point EmployeeEceptionDemo

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

namespace ConsoleApplication1
{


    public class Employee
    {

        string Wage;
        int IDNum;
        double hourlyWage;
        public Employee() { }
        public Employee(int id, double hw)
        {


            IDNum = id;
            hourlyWage = hw;
            if (hw < 6.0 || hw > 50.0)
            {
                IDNum = 999;
                hourlyWage = 6.0;
                throw new Exception(new EmployeeException(id, hw).errorMessage);

            }



        }
        public class EmployeeException
        {

            public string errorMessage;

            public EmployeeException(int id, double hw)
            {
                throw new Exception("For " + id + " Hourly Wagr is invalid\n...  Hourly Wage is " + hw.ToString("C") + errorMessage);

            }
        }
        public int getID()
        {
            return IDNum;
        }
        public Double getWage()
        {
            return hourlyWage;
        }
    }
}

Every C# program has to have a static Main(...) method (a so called entrypoint) From here is where your program starts to run. Are you using Visual Studio?

Well i m not exactly sure what your goal is but if you want to display something you have to call your class! So you have to make a instance of it, for example

Employee em=new Employee(); 

and you can pass parameters to it because you created a constructor otherwise you won t have any use of it

Employee em =new Employee(value1,value2); //value1=type_int,value2=type_double

AND one other thing, before you do that be sure to insert the Namespace wich is ConsoleApplication1 by doing this

using ConsoleApplication1;

otherwise you won t be able to access your class that you creater eralier before.

This is what I am attempting to do:
Create an Employee class with two fields—IDNum and hourlyWage. The Employee constructor requires values for both fields. Upon construction, throw an ArgumentException if the hourlyWage is less than $6.00 or more than $50.00. Write a program that establishes, one at a time, at least three Employees with hourlyWages that are above, below, and within the allowed range. Immediately after each instantiation attempt, handle any thrown Exceptions by displaying an error message.

I have the ConsoleApplication1; in place.

Also I can put the employees bt the id and do I need to add all three seperate or can I use[3]
I think it will have to be like this

Employee em1 =new Employee(value1,value2)
Employee em 2=new Employee(value1,value2)
Employee em2 =new Employee(value1,value2)

That looks to be Ok. There are several ways to do it each with their own pros and cons. As was mentioned you need to do it in a static main class,static void Main(), and I'm not sure how necessary it is, but mine always goes inside the Program class, so basically you'd end up with something like this:

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            //create new employees here
        }
    }
    public class Employee
    {
        //create class here
    }
}

Edited 3 Years Ago by tinstaafl

Comments
Great explanation
This question has already been answered. Start a new discussion instead.