Record will be separated by a comma

Assignment Help Business Management
Reference no: EM132197653

How do you run an array through a file in C#?

THIS IS THE ASSIGNMENT INVOLVING THE QUESTION

Code a C# project (using Visual Studio) to solve the following problem:

A company wants to see a printout of the gross pay for each of its 7 departments. The output should be a list of the seven departments and the total gross pay (the sum of the gross pay for all the employees in that department) for each department. Be sure to validate the input data. If a line of data is invalid print out an error message along with the invalid data, then continue processing with the next record.

The file containing the employee data that will be used for the calculations is structured as follows:

FIELD DESCRIPTION DATA TYPE VALID VALUES

Employee ID Character Non blank

Department Number Numeric 1 - 7

Hourly Salary Numeric at least 10.00

Hours Worked Numeric greater than 0

The fields in each record will be separated by a comma (e.g. EID001, 2, 15.50, 40).

THIS IS THE FAILED CODE I HAVE NOW

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.IO;

namespace ConsoleApp12

{

class Program

{

static void Main(string[] args)

{

const int DEPARTMENT = 7;

const int SIZE = 4;

FileStream fstream = new FileStream("Exam3text.txt", FileMode.Open, FileAccess.Read);

StreamReader infile = new StreamReader(fstream);

string inputRecord = "";

int department = 0;

int[] departmentCount = new int[DEPARTMENT];

double hourlySalary = 0.0;

double totalHoursWorked = 0.0;

double hoursWorked = 0.0;

double grossPay = 0.0;

double totalHourlySalary = 0.0;

inputRecord = infile.ReadLine();

string[] employee = new string[SIZE];

double[] totalGrossPay = new double[SIZE];

while (inputRecord != null)

{

employee = inputRecord.Split(',');

if (int.TryParse(employee[1], out department) && department >= 0 && department <= DEPARTMENT)

{

departmentCount[department - 1] = departmentCount[department - 1] + 1;

}

else

Console.WriteLine(inputRecord);

if (double.TryParse(employee[2], out totalHourlySalary) && hourlySalary >= 10.0)

{

totalHourlySalary = totalHourlySalary + hourlySalary;

}

if (double.TryParse(employee[3], out totalHoursWorked) && hoursWorked > 0)

{

totalHoursWorked = totalHoursWorked * hoursWorked;

//Console.WriteLine(totalHoursWorked);

}

if (department >= 1 && department <= SIZE)

{

totalGrossPay[department - 1] = totalGrossPay[department - 1] + (totalHoursWorked * totalHourlySalary);

totalGrossPay[department - 1] = grossPay;

//Console.WriteLine(grossPay);

}

inputRecord = infile.ReadLine();

grossPay = totalHourlySalary * totalHoursWorked;

}//end while

showOutput(departmentCount, totalHourlySalary, totalHoursWorked, totalGrossPay);

}

static void showOutput(int[] departmentCount, double totalHourlySalary, double totalHoursWorked, double[] totalGrossPay)

{

Console.WriteLine("Grosspay for each department");

Console.WriteLine("Departmentt Employeest Hourly Salaryt Hours Workedt Gross Payt ");

for (int i = 0; i < departmentCount.Length; i++)

{

if (departmentCount[i]>= 0)

{

Console.WriteLine("{0}tt {1}tt {2}tt {3}tt {4}tt", i + 1, departmentCount[i], totalHourlySalary, totalHoursWorked, totalGrossPay[]);

}//end if

}//end for

}//end showOutput

}

}

Reference no: EM132197653

Questions Cloud

Post an application of the attachment theory : Post an application of the attachment theory to the case of Brady. Discuss the connection between his attachment style and the exhibiting behavior.
People begin to engage with internet : What do you think the age is now when people begin to engage with internet?
Calculate the value of pi by estimating the area : Write a code in matlab to calculate the value of Pi by estimating the area of a 2x2 square and the inscribing circle of radius 1.
The assigned topic in current business publication : Find an article on the assigned topic in a current business publication. Current business publications include the Wall St. Journal, Business Week, Fortune.
Record will be separated by a comma : THIS IS THE ASSIGNMENT INVOLVING THE QUESTION. Code a C# project (using Visual Studio) to solve the following problem:
Major social and political achievements of reconstruction : What do you think were the major social and political achievements of Reconstruction? In what ways was Reconstruction a failure?
Discuss the different categories of innovative strategies : Identify and discuss the different categories of innovative strategies. Provide examples.
Difference between the binary and decimal counting system : Explain the difference between the binary and decimal counting system and why is binary used in computer science?
Decide between alliance and acquisition : How do you decide between an alliance and an acquisition? Provide examples.

Reviews

Write a Review

Business Management Questions & Answers

  How a person''s mood may affect decision making

Do you believe mood affects decision making? Do you feel that you make better decisions when you are in a good mood? Or do you feel you make better decisions when you are in a bad mood?

  What you have learned about hireviews hiring strategy

Based on what you have learned about Hireview''s hiring strategy, respond to the following: How can computer mediated communication impact job interviews

  National bureau of economic research

National Bureau of Economic Research.  CIA's World Factbook. Organization for Economic Co-operation and Development.  You should also consider the sources in the University Library listed under Country Profiles and Econcomic Data.

  Why did you ignore the base rates

Why did you/they ignore the base rates? What other statistically relevant factors did you/they fail to incorporate? How could you have altered the framing of the situation to make a better decision?

  Concept of motivation for healthcare staff members

Define and briefly discuss the concept of motivation for healthcare staff members. (must be at least 150 words)

  What is sams gross profit for march

Which country does the text describe as becoming the largest producer and consumer of many of the world's goods - following terms is not required to be disclosed under the Truth-in-Lending Act?

  Employees to learn new technologies

IBM Offers Training and pay cuts to its employees to learn new Technologies. Is this program strategic? Why or Why Not? Should the employees salaries be reduced for the time they attend training programs? Provide a rationale for your answer. What ..

  Accurate predictions about company financial condition

Then, imagine you are an investor or creditor; suggest the ratios that you believe would provide an investor or creditor with the most important information needed to make accurate predictions about the company's financial condition. When analyzin..

  Angry customer at grocery store

Think of a time when you observed an angry customer at grocery store, retail, or bank. Describe the behavior tf the person you observed.

  What are the potential benefits of each stage

Why an ERP systems journey may never end What are the possible stages in an ERP systems journey? What are the potential benefits of each stage?

  Transactional and transformational leadership

What are some differences between transactional and transformational leadership?

  Declines in the size of benefit packages

There are five reasons for the historical growth in the size of benefits packages. Which of these reasons still affects the growth of employee benefits today? Which actually might be current reasons for declines in the size of benefit packages

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd