hi
i am currenlty studying C sharp Visual studio, trying to convert a case study of polymorphism in payroll (which is avaiable in different books as console application) into windows application..
everything is going well, except here where i got switch statement and giving error in case 2- case 4
i have made this in VS 2010, soo convertor is included in attached file...

code is

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PayrollSystem
{
    public partial class payrollCalculaterForm : Form
    {
        public payrollCalculaterForm()
        {
            InitializeComponent();
        }

        private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            fixedWeeklySalaryTextBox.Text = "";
            hourlyPayTextBox.Text = "";
            totalHoursTextBox.Text = "";
            overTimePayTextBox.Text = "";
            commissionRateTextBox.Text = "";
            totalSaleTextBox.Text = "";
            switch (employeeComboBox.Text)
            {
                case "Permanent":
                    fixedWeeklySalaryTextBox.Enabled = true;
                    hourlyPayTextBox.Enabled = false;
                    totalHoursTextBox.Enabled = false;
                    overTimePayTextBox.Enabled = false;
                    commissionRateTextBox.Enabled = false;
                    totalSaleTextBox.Enabled = false;
                    break;
                case "Part time":
                    fixedWeeklySalaryTextBox.Enabled = false;
                    hourlyPayTextBox.Enabled = true;
                    totalHoursTextBox.Enabled = true;
                    overTimePayTextBox.Enabled = true;
                    commissionRateTextBox.Enabled = false;
                    totalSaleTextBox.Enabled = false;
                    break;
                case "Part time Commission based":
                    fixedWeeklySalaryTextBox.Enabled = false;
                    hourlyPayTextBox.Enabled = false;
                    totalHoursTextBox.Enabled = false;
                    overTimePayTextBox.Enabled = false;
                    commissionRateTextBox.Enabled = true;
                    totalSaleTextBox.Enabled = true;
                    break;
                case "Permanent Plus Commission based":
                    fixedWeeklySalaryTextBox.Enabled = true;
                    hourlyPayTextBox.Enabled = false;
                    totalHoursTextBox.Enabled = false;
                    overTimePayTextBox.Enabled = false;
                    commissionRateTextBox.Enabled = true;
                    totalSaleTextBox.Enabled = true;
                    break;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (employeeComboBox.Text == "" || employeeComboBox.Text == "Choose Employee Type")
            {
                MessageBox.Show("Please Choose atleast one Employee Category in order to calculate Pay");
            }
            else 
            {
                switch (employeeComboBox.Text)
                {
                    case "Permanent":

                        permanentEmployees perEmployee = new permanentEmployees(fnameTextBox.Text,
                            LnameTextBox.Text, Convert.ToDecimal(fixedWeeklySalaryTextBox.Text));
                        totalEarningLabel.Text = "" + perEmployee.ToString() + "\r\n\n Weekly Earning : " 
                            + perEmployee.Earnings().ToString("C") + "";
                        break;
                    case "Part time":
                       /* partTimeEmployees Employee = new partTimeEmployees (fnameTextBox.Text,
                          LnameTextBox.Text, Convert.ToDecimal(fixedWeeklySalaryTextBox.Text), 
                          Convert.ToDecimal(hourlyPayTextBox.Text), Convert.ToDecimal(totalHoursTextBox.Text),
                          Convert.ToDecimal(overTimePayTextBox.Text));
                      totalEarningLabel.Text = "" + Employee.ToString() + "\r\n\n Weekly Earning : " 
                          + Employee.Earnings().ToString("C") + "";
                        */
                      break; 
                    case "Part time Commission based":
                        
                        break;
                    case "Permanent Plus Commission based":
                        
                        break;
                }
            }
        }      
    }
}

Problem is i am unable to figure out what excatly to write in case for employees then permanent one

thanks alot for your time

yeah i said its interesting
but i really neeed help with it guyz
pleaseeeeeee help

He man what's the hurry?
Over here it is sunday, so relax.
My guess is you have to do some calculations, based on the textboxes that are enabled for a parttimer.
See what you can come up with. Succes! :)

i kno its sunday lol
yeah definatly need to do calculations but my brain stuck here

its more like someone gave me a puzzle half solved and i cant move any forward

please any code of lines will be appreciated thanks

:) and tomorrow is deadline :(

So this is homework, right? ;)
Do you know the rules here?
But as I'm in a good mood these days...
For parttimers:
totalEarningLabel:
It al boils down to a multipication of hours worked and pay rate per hour. Add the overtime rate.
Show us your code. I know you can do it, YES YOU CAN!!!

yes mate, it is my assignment but when one is unable to find help from anywhere he comes straight to forum, instead of lie this and that i come straight to point

even if sumone will give me answer with explanation i will learn something and thats the main purpose of a forum, to learn things anyway :)

i am trying doing that but its not working :(

lines of code will be appreciated

97% of application is done except here

i dunt know how to accept 3 parameters over here or i will just get the final salary

which is already in partTimeEmployee class

and as i forgot to show the scenario its down here

A software solutions company Newcomb employs a large number of employees in a number of offices spread around the Surrey County. The company pays its employees on a weekly basis. The employees are of four types:

1. Permanent employees are paid a fixed weekly salary regardless of the hours worked.
2. Part time employees are paid by the hour and receive overtime pay for hours worked in the excess of 37 hours.
3. Part time Commission employees are paid a percentage of their sales.
4. Permanent Commission employees receive a base salary plus a percentage of their sales.

For the current period, the company has decided to reward permanent commission employees by adding 5% of their basic salary. The company wants to implement a C# Windows application that performs its payroll calculations polymorphically.

this excercise is everywhere but in console but i am making it in application


confusion comes here lol :(

Sorry, perhaps it is me who is dumb.
Part time employees get paid by the hour and if they work more than 37 hours they get extra. Am I right? This should be not too difficult to translate into code (a multiplication and an if statement, come on man!)
Dani would kill me if I should do it for you, so come on DO IT!

Edited 5 Years Ago by ddanbe: n/a

Comments
Yes, she would.

yeah thats right

and its already calculating it in another class

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

namespace PayrollSystem
{
    public class partTimeEmployees : Employee
    {
        private decimal wage;       // wage per hour of work
        private double hoursWorked; // hours worked during week
        private decimal overTimeWage; // wage per hour for over time

        // constructor
        public partTimeEmployees(string firstNameValue, string LastNameValue,
           decimal wageValue, double hoursWorkedValue, decimal overTimeWageValue)
            : base(firstNameValue, LastNameValue)
        {
            Wage = wageValue;
            HoursWorked = hoursWorkedValue;
            OverTimeWage = overTimeWageValue;
        }

        // property Wage
        public decimal Wage
        {
            get
            {
                return wage;
            }

            set
            {
                // ensure non-negative wage value
                if (value > 0)
                    wage = value;
            }
        }
        // property HoursWorked
        public double HoursWorked
        {
            get
            {
                return hoursWorked;
            }

            set
            {
                // ensure non-negative hoursWorked value
                if (value > 0)
                    hoursWorked = value;
            }
        }
        // property over time Wage
        public decimal OverTimeWage
        {
            get
            {
                return overTimeWage;
            }

            set
            {
                // ensure non-negative wage value
                if (value > 0)
                    overTimeWage = value;
            }
        }

        // override base-class method to calculate 
        // HourlyWorker earnings
        public override decimal Earnings()
        {
         // compensate for overtime (paid "time-and-a-half")
         if ( HoursWorked <= 37 )
         {
            return Wage * Convert.ToDecimal( HoursWorked );
         }
   
         else
         {
            // calculate base and overtime pay
            decimal basePay = Wage * Convert.ToDecimal(37);
            decimal overtimePay = OverTimeWage *
               Convert.ToDecimal( HoursWorked - 37);
   
            return basePay + overtimePay;
         }
        }

        // return string representation of HourlyWorker
        public override string ToString()
        {
            return "Part Time Employee: " + base.ToString();
        }
    }

}

i am confused how can i display salary into label like it works for permanent employee..

if you run the program sum how on visual 2010, it will be clear where i am stuck atm :)
as its bit hard to explain :( sorry for confusion

You know whats the problem with your code, you can pass to the constructor of the class (partTimeEmployees) only 3 parametes, but in your switch loop "partTime", you pass them 5. You have to change them to 3, or re-edit the constructor.

Mitja

I have repaired your code in the loop to:

case "Part time":
                        partTimeEmployees Employee = new partTimeEmployees (
                            fnameTextBox.Text,
                          LnameTextBox.Text, 
                          //Convert.ToDecimal(fixedWeeklySalaryTextBox.Text), 
                          Convert.ToDecimal(hourlyPayTextBox.Text), 
                          Convert.ToDouble(totalHoursTextBox.Text),
                          Convert.ToDecimal(overTimePayTextBox.Text));
                        totalEarningLabel.Text = "" + Employee.ToString() + "\r\n\n Weekly Earning : "
                            + Employee.Earnings().ToString("C") + "";
                        break;

..and now works, but Iam not sure if its correct. Now its on you to check it out.
PROBLEM WAS: you didnt pass the same npumber of arameters from button Click event to the constructor of the class "partTimeEmployees". And neither the value types werent the same (decimal, double).
Hope it helps,
Mitja

thanks alot mitja for ur contribution,
i tried it in my code and my code started given me output which is sumthing better then before, but the output wasn;t correct...
i checked program using debugging and came to know as its not calculating right salary instead its just multiplying

hourly pay with overTime hourly pay

where as program is not stepping into this if and else statement... it seems to be logical error and i am still struggling with it.

program is suppose to go into this if and else statement in order to calculate right salary as if hours are more then 37 then it will use over time pay rate

// override base-class method to calculate 
        // HourlyWorker earnings
        public override decimal Earnings()
        {
         // compensate for overtime (paid "time-and-a-half")
         if ( HoursWorked <= 37 )
         {
            return Wage * Convert.ToDecimal( HoursWorked );
         }
   
         else
         {
            // calculate base and overtime pay
            decimal basePay = Wage * Convert.ToDecimal(37);
            decimal overtimePay = OverTimeWage * Convert.ToDecimal( HoursWorked - 37);
   
            return basePay + overtimePay;
         }
        }

        // return string representation of HourlyWorker
        public override string ToString()
        {
            return "Part Time Employee: " + base.ToString();
        }
    }

}

forgot to tell


control is not going in the method earning given above

Done everything Except that bug i just explained

thanks alot Mitja

but i am still working on that bug i hope i will solve it in few minutes but in mean time if sumone know anything let me knw please :)

Code given below, suppose to give
hourly pay * number of hours + if hours greator then 37 then calculate rest with given rate (overtime)
and display final result

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

namespace PayrollSystem
{
    public class partTimeEmployees : Employee
    {
        private decimal wage;       // wage per hour of work
        private double hoursWorked; // hours worked during week
        private decimal overTimeWage; // wage per hour for over time

        // constructor
        public partTimeEmployees(string firstNameValue, string LastNameValue,
           decimal wageValue, double hoursWorkedValue, decimal overTimeWageValue)
            : base(firstNameValue, LastNameValue)
        {
            Wage = wageValue;
            HoursWorked = hoursWorkedValue;
            OverTimeWage = overTimeWageValue;
        }

        // property Wage
        public decimal Wage
        {
            get
            {
                return wage;
            }

            set
            {
                // ensure non-negative wage value
                if (value > 0)
                    wage = value;
            }
        }
        // property HoursWorked
        public double HoursWorked
        {
            get
            {
                return hoursWorked;
            }

            set
            {
                // ensure non-negative hoursWorked value
                if (value > 0)
                    hoursWorked = value;
            }
        }
        // property over time Wage
        public decimal OverTimeWage
        {
            get
            {
                return overTimeWage;
            }

            set
            {
                // ensure non-negative wage value
                if (value > 0)
                    overTimeWage = value;
            }
        }

        // override base-class method to calculate 
        // HourlyWorker earnings
        public override decimal Earnings()
        {
         // compensate for overtime (paid "time-and-a-half")
         if ( HoursWorked <= 37 )
         {
            return Wage * Convert.ToDecimal( HoursWorked );
         }
   
         else
         {
            // calculate base and overtime pay
            decimal basePay = Wage * Convert.ToDecimal(37);
            decimal overtimePay = OverTimeWage * Convert.ToDecimal( HoursWorked - 37);
   
            return basePay + overtimePay;
         }
        }

        // return string representation of HourlyWorker
        public override string ToString()
        {
            return "Part Time Employee: " + base.ToString();
        }
    }

}

DOne it
thanks for help both of u guyz :)

specially mitja

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