Friday, April 6, 2012

Sense of Accomplishment

Its funny how the little things in our pursuits make such a big deal to us, in my case solving an incredibly easy problem for the first time without looking up reference or clues.

As part of my personal and professional development into the world of software development, I have decided to tackle Java. Mostly because my clients have indicated that Java will be the primary language that they wish to focus on for a myriad of reasons, which I will not go into.

So what is it that got me so excited enough to make a blog post about it?

This little baby step here:


Assignment: FooCorporation
Method to print pay based on base pay and hours worked 
Overtime: More than 40 hours,paid 1.5 times base pay 
Minimum Wage: $8.00/hour 
Maximum Work: 60 hours a week

Reminder • Write your own code

So with no Google or StackOverflow to assist me I came up with this code...



class OvertimeCalculator {
    public static void main(String[] args) {
        int hoursWorked = 60;
        int overtimeHours = 20;
        int regularHours = 40;
        double hourRate = 8.00;
        double overtimeRate = hourRate * 1.5;
        
        System.out.println(
                "Hours worked at regular time: \t" + (hoursWorked - overtimeHours) +
                "\nRegular pay rate: \t\t$" + hourRate + 
                "\nOver time hours: \t\t" + overtimeHours +
                "\nOvertime rate: \t\t\t$" + overtimeRate +
                "\nRegular time pay: \t\t$" + (regularHours * hourRate) +
                "\nOvertime pay: \t\t\t$" + (overtimeHours * overtimeRate) +
                "\n--------------------------------------" +
                "\nTotal pay: \t\t\t$" + ((regularHours * hourRate) + (overtimeHours * overtimeRate)));
                
                }
}   
 


Result:

...and it worked, not the most elegant solution, and in a few days I'm sure I'll see that I could have done a whole lot better, but it is a milestone for me.