1
Reply

Homework help did i do it right

Jenni Witzel

Jenni Witzel

Oct 29 2008 4:13 PM
2.8k

/********************************************************/

/*   Your Name                                          */

/*   CIS 218                                            */

/*   LAB 9 - Working with parallel arrays               */

/*   Due Date: xx/xx/xxxx                               */

/*                                                      */

/*   Description: This program builds on lab 7, adding  */

/*                data validation as well as job codes  */

/*                that are implemented via parallel     */

/*                arrays.                               */

/*                                                      */

/********************************************************/

using System;

using SC = System.Console;

public class FLastLab7

{ //Main Method

    public static void Main()

    {

        string eName;

        double hoursWorked;

        int jobCode;

 

        SC.WriteLine("Lab 9 – Your Name");

 

        SC.Write("\nPlease input Employee Name: ");

        eName = SC.ReadLine();

 

        while (eName != "Quit")

Oval: A do-while loop that gets hours worked and validates each entry        {

            do

            {

                SC.Write("Please input hours worked:  ");

                hoursWorked = Convert.ToDouble(SC.ReadLine();

            } while (hoursWorked <= 0 || hoursWorked > 60);

 

Oval: You code a loop that gets the job code and validates each entry            do

            {

                SC.Write(". . .;

                jobCode = . . .;

            } while ( . . . );

 

Oval: Create a newEmployee object using the name, hours worked, and job code            Employee newEmployee = new . . .;

 


            newEmployee.PrintName();

            newEmployee.OutputJobInfo();

            newEmployee.CalculateGrossPay();

            newEmployee.CalculateStateTax();

            newEmployee.CalculateFederalTax();

            newEmployee.CalculateFICATax();

            newEmployee.CalculateNetPay();

 

            SC.Write("\nPlease input Employee Name: ");

            eName = SC.ReadLine();

        }

 

        SC.WriteLine("\nEnd of Lab 9\n");

    }


 

Oval: Put in two arrays    class Employee

    {

        private double[] hourlyRates =      {. . . };

 

        private string[] jobDescriptions =  {"no such job", ". . .        };

 

        private string employeeName, employeeJob;

 

        private double hoursWorked, rateOfPay, grossPay, stateTax, federalTax,
                       ficaTax, netPay;

Oval: Note that jobCode replaces hours worked
 


        public Employee(string eName, double hours, int jobCode)

        {

            employeeName = eName;

Oval: Get the rate from the hourlyRates array and get the job name from the jobDescriptions array            hoursWorked = hours;

 

            rateOfPay = . . .        ;

            employeeJob = . . .      ;

        }

 

        public void PrintName()

        {

            SC.WriteLine("\nEmployee Name:    {0}", employeeName);

Oval: This method is new        }

 

        public void OutputJobInfo()

        {

            SC.WriteLine("Hourly rate is:\t{0,9}", rateOfPay.ToString("F2"));

            SC.WriteLine("Job Description:  {0}", employeeJob);

        }

 

Oval: The rest of the code here should be the same as what was in the Employee class in Lab 7
 

 

 

 

 

 

 

 

 

 

 

 

 

 


}



This is what i did


/********************************************************/
/*   Your Name                                          */
/*   CIS 218                                            */
/*   LAB 9 - Working with parallel arrays               */
/*   Due Date: xx/xx/xxxx                               */
/*                                                      */
/*   Description: This program builds on lab 7, adding  */
/*                data validation as well as job codes  */
/*                that are implemented via parallel     */
/*                arrays.                               */
/*                                                      */
/********************************************************/
using System;
using SC = System.Console;
public class FLastLab7
{ //Main Method
    public static void Main()
    {
        string eName;
        double hoursWorked;
        int jobCode;

        SC.WriteLine("Lab 9 – Your Name");

        SC.Write("\nPlease input Employee Name: ");
        eName = SC.ReadLine();

        while (eName != "Quit")
        {
            do
            {
                SC.Write("Please input hours worked:  ");
                hoursWorked = Convert.ToDouble(SC.ReadLine();
            } while (hoursWorked <= 0 || hoursWorked > 60);

            do
            {
                SC.Write("Please input job code:  ");
                jobCode = Convert.ToDouble(SC.ReadLine();
            } while (jobCode <= 0 || jobCode > 60);

            Employee newEmployee = new Employee(eName, hoursWorked, rateOfPay);

            newEmployee.PrintName();
            newEmployee.OutputJobInfo();
            newEmployee.CalculateGrossPay();
            newEmployee.CalculateStateTax();
            newEmployee.CalculateFederalTax();
            newEmployee.CalculateFICATax();
            newEmployee.CalculateNetPay();

            SC.Write("\nPlease input Employee Name: ");
            eName = SC.ReadLine();
        }

        SC.WriteLine("\nEnd of Lab 9\n");
    }
 

    class Employee
    {
        private double[] hoursWorked = hrsWorked;

        private string[] jobDescriptions =  {"no such job", "WHAT GOES HERE" };

        private string employeeName, employeeJob;

        private double hoursWorked, rateOfPay, grossPay, stateTax, federalTax,
                       ficaTax, netPay;

        public Employee(string eName, double hours, int jobCode)
        {
            employeeName = eName;
            hoursWorked = hours;

            rateOfPay = rate;
            employeeJob = eJob ;
        }

        public void PrintName()
        {
            SC.WriteLine("\nEmployee Name:    {0}", employeeName);
        }

        public void OutputJobInfo()
        {
            SC.WriteLine("Hourly rate is:\t{0,9}", rateOfPay.ToString("F2"));
            SC.WriteLine("Job Description:  {0}", employeeJob);
        }

        public static void Main()
    {
        double hours, rate;
        string employeeName, hoursStr, rateStr;

        SC.WriteLine("Lab 7 – Your Name\n");
        SC.Write("\nPlease input Employee Name: ");
        employeeName = SC.ReadLine();

        while (employeeName != "Quit")
        {
            SC.Write("\nPlease input hours worked: ");
            hoursStr = SC.ReadLine();
            SC.Write("\nPlease input rate of pay: ");
            rateStr = SC.ReadLine();
            hours = Convert.ToDouble(hoursStr);
            rate = Convert.ToDouble(rateStr);

            Employee newEmployee = new Employee(eName, hoursWorked, rateOfPay);

            newEmployee.PrintName();
            newEmployee.CalculateGrossPay();
            newEmployee.CalculateStateTax();
            newEmployee.CalculateFederalTax();
            newEmployee.CalculateFICATax();
            newEmployee.CalculateNetPay();

            SC.Write("\nPlease input Employee Name: ");
            employeeName = SC.ReadLine();
        } // end of loop
        SC.WriteLine("\nEnd of Lab 7\n");
        SC.ReadLine();
    } // end of Main method
} // end of Main class


class Employee
{
    private string employeeName;
    private double hoursWorked, rateOfPay, grossPay, stateTax,
    federalTax, ficaTax, netPay, overtimePay;

    public Employee(string eName, double hrsWorked, double rate)
    {
        employeeName = eName;
        hoursWorked = hrsWorked;
        rateOfPay = rate;
    }
    public void PrintName()
    {
        SC.WriteLine("\nEmployee Name:\t{0}", employeeName);
    }

    public void CalculateGrossPay()
    {
        grossPay = hoursWorked * rateOfPay;
        if (hoursWorked > 40)
        {
            overtimePay = (hoursWorked - 40) * rateOfPay;
        }
        else
        {
            overtimePay = 0;
        }
        SC.Write("\nGross pay is:\t{0,10}", grossPay.ToString("C"));
        SC.WriteLine(" (including Overtime: {0})", overtimePay.ToString("C"));
    }

    public void CalculateStateTax()
    {
        const double stateTaxRate = 0.04;
        stateTax = grossPay * stateTaxRate;

        SC.WriteLine("\nState tax is:\t{0,10}", stateTax.ToString("C"));
    }

    public void CalculateFederalTax()
    {
        const double federalTaxRate = 0.23;
        federalTax = grossPay * federalTaxRate;

        SC.WriteLine("\nFederal tax is:\t{0,10}", federalTax.ToString("C"));
    }

    public void CalculateFICATax()
    {
        const double ficaTaxRate = 0.14;
        ficaTax = grossPay * ficaTaxRate;

        SC.WriteLine("\nFICA tax is:\t{0,10}", ficaTax.ToString("C"));
    }

    public void CalculateNetPay()
    {
        netPay = grossPay - (stateTax + federalTax + ficaTax);
        SC.WriteLine("\nNet pay is:\t{0,10}", netPay.ToString("C"));
    }
} // end of Employee class













}


Answers (1)