Simple pay rate calculator Follow-up posted -> Follow up to Pay Rate Calculator



This little bit of code is just some code that I wrote from a flowchart at the beginning of a programming and logic book that I have added some to. I tried to create it as an object.

I would like a review on what I am doing and if I am doing it right, and what I could do better.  I want you to look at this like I am a novice to intermediate Programmer.  I don't think that I learned as much as I should have while I was in school, and it probably shows.

Main Method

public static void Main (string[] args)
{
    var payCheck = new PayRateCalculator();
    Console.Write ("Please provide the Employees Last Name &gt;&gt;");
    payCheck.lastName = Console.ReadLine();
    Console.Write ("How many hours has employee {0} worked? &gt;&gt;", payCheck.lastName);
    payCheck.hours = Convert.ToInt32 (Console.ReadLine());
    Console.Write ("What is employee {0}'s hourly wage? &gt;&gt;", payCheck.lastName);
    payCheck.payrate = Convert.ToInt32 (Console.ReadLine ());
    Console.WriteLine ("{0}'s Gross pay is ${1}", payCheck.lastName, payCheck.grossPay);
    Console.WriteLine ("{0}'s Net pay is ${1}", payCheck.lastName, payCheck.netPay);   
}


Class

class PayRateCalculator
{
    private float _payrate = 8.25f;
    private float _withholdingRate = 0.20F;

    public float hours { get; set; }
    public float grossPay { 
        get {
            return hours * _payrate;
        }
    }
    public float netPay { 
        get {
            return grossPay - (grossPay * _withholdingRate);
        }
    }
    public float payrate {
        get {
            return _payrate;
        }
        set {
            _payrate = value;
        }
    }
    public string lastName { get; set; }

    public PayRateCalculator (string lastName, float hours, float payRate)
    {
        this.hours = hours;
        this.payrate = payrate;
        this.lastName = lastName;
    }

    public PayRateCalculator ()
    {

    }
}


Just a simple console application. Help me to relearn coding the right way.
As a few people have pointed out, there is actually nothing really wrong with this code.

I mean, there needs to be some naming standardization, most notably any public property should be capital.

I would also advise a backing field for each property making the constructor a bit cleaner:

_hours = hours;
_payrate = payrate;
_lastName = lastName;


That being said from a design point of view, it is best to mirror your objects to real world  objects.

Is a PayRateCalculator actually a PayCheck?  Would it not make more sense to have a paycheck of some kind, once you have your details assigned you can return the paycheck as a separate thing?

The means with which you generate the paycheck should stand alone from the paycheck itself,
allowing the possibility in future of having multiple calculation methods or doing something interesting with the paycheck object.

Although again, these are just design considerations as your application scales.

There is nothing inherently wrong with your code, which is well-written, decently-named and functional.

Well done.