Objective: The purpose of this lab project is to expose you to Loops, enforce fu
ID: 656182 • Letter: O
Question
Objective:
The purpose of this lab project is to expose you to Loops, enforce functions, proper use of by-value/by reference, and to expand your skills in writing larger/more sophisticated programs.
Problem Specification:
The Passaic County Contracting Company, PCCC, negotiates building projects/job contracts. They have to subcontract an electrician to do the electrical, a plumber to do the pluming, a roofer to do the roofing a landscaper to do the landscaping. All other work is done internally by their employees. For each project they assign a minimum of 5 employees who are paid salary. The company orders and pays for material which consists of wood, concrete, windows, doors, sheetrock and spackle.
As the programmer for PCCC, they assigned you the task of writing a C++ program to accept the number of the projects/jobs that PCCC has won.
For each job, the program should accept:
The amount of the contract
Each subcontractors pay.
For internal work:
The salary for each of the employees working on the project, is entered as input until the sentinel 0 is entered (the number of employees is unknown).
The cost of the material for each of the items listed above.
The program should output to a file, the amount of contract, the cost of the contract, and the profit/loss from the contract.
At the end, the program will output, to the same file, the total electrical cost, total plumbing cost, total roofing cost, total landscaping cost, total cost for material and total cost for salaries, it then outputs to the same file, the total of all contracts, the cost for all contracts, and the profit/loss for all contracts.
Requirements:
Comment as needed.
All functions have specifications.
All data is passed by value / by reference as appropriate.
Main is the driver function, hardly any statements other than function calls my appear in main.
Use loops as is appropriate to complete the specified task/subtask.
Calculate all totals as requested.
Write the report to a file with proper headings, identifications
Explanation / Answer
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Company implements CompanyInterface{
//private Employee addEmp = new Employee();
// private Position addPosition = new
private ArrayList<Employee> list ;
private static int numberOfCompanies;
private String CompanyName;
private int numEmployees;
private int numManufacturing;
private int numSales;
String SName="";
String JName="";
String position="";
String first="";
String second="";
String empID="";
Scanner File;
//private ArrayList<Emp> list2 ;
private Employee addEmp;
public Company(String cn)
{
cn="Projects ";
list = new ArrayList<Employee>();
numEmployees=0;
numManufacturing=0;
numSales=0;
numberOfCompanies++;
setCompanyName(cn);
}
@Override
@param fName first name
* @param lName last name
* @param pos position
* @return null if everything is right
*/
public String addEmployee(String sName, String jName, String pos,
double firstParam, int secondParam, int empNum) {
String msg=null;
//if (pos.equals("SALES&&numSales<1&&numManufacturing<2)
else if (pos.equals("SALES"))
{
if (numSales==1)
{
msg="There is already a sales person Employee not added";
}else{
//p2=Position.SALES;
addEmp = new Sales(fName, lName,pos);
numSales++;
numEmployees++;
list.add(addEmp);
}
}//else return message;
else if (pos.equals("MANUFACTURING"))
{
if (numManufacturing == 4){
msg="There are already four manufacturing persons Employee not added";
}else{
//p2=Position.MANUFACTURING;
addEmp = new Manufacturing(fName, lName, pos);
numManufacturing++;
numEmployees++;
list.add(addEmp);
}
}
//String str=fName+" "+lName+" "+pos+" "+firstParam+" "+empNum;
System.out.println(fName+" "+lName+" "+pos+" "+firstParam+" "+empNum);
return message;
}
public static int getNumCompanies()
{
return numberOfCompanies;
}
public void setNumCompanies(int nc)
{
numberOfCompanies = nc;
}
public void setNumemployees(int ne)
{
numEmployees = AB;
}
public int getNumEmployees()
{
return numEmployees;
}
@Override
public int getNumManager() {
return numManager;
}
public void setNumDesign(int num)
{
numDesign = num;
}
@Override
public int getNumDesign() {
return numDesign;
}
public void setNumsales(int num)
{
numSales = num;
}
@Override
public int getNumSales() {
return numSales;
public void setNumManufacturing(int num)
{
numManufacturing = num;
}
@Override
public int getNumManufacturing() {
return numManufacturing;
}
public void setNumManager(int num)
{
numManager = num;
}
@Override
public String generateWeeklyReport() {
empID = "";
String title="WEEKLY PAY REPORT FOR "+getCompanyName()+" COMPANY"+" ";
String label="Employee ";
String label2="WEEKLY PAY ";
int payWeek=0;
double total=0.0;
for (Employee index:list)
{
//empId+=label+" "+list.get(index).getEmpId()+" "+label2+" "+list.get(index).calculateWeeklyPay();
empID+=index.getEmpId();
payWeek+=index.calculateWeeklyPay();
}
return title+label+empID+" "+" "+label2+payWeek+" "+"Total Payroll: $"+total+" "+
"Total number of managers paid:"+getNumManager()+" "+
"Total number of Design Employees paid:"+getNumDesign()+" "+
"Total number of Sales Employees paid:"+getNumSales()+" "+
"Total number of Manufacturing Employees paid:"+getNumManufacturing();
}
@Override
public double calculateTotalWeeklyPay() {
int total=0;
for (int index=0; index<list.size();index++)
{
total +=list.get(index).calculateWeeklyPay();
}
return total;
}
public String printCompany( ) {
// TODO Auto-generated method stub
String str = "";
for (int index=0; index<list.size();index++)
{
str +=list.get(index).getFName()+" "+list.get(index).getLName()+" "+"Position:"+list.get(index).getPosition()+" ";
}//System.out.println(str);
return str;
}
public String getCompanyName() {
return CompanyName;
}
public void setCompanyName(String companyName) {
//companyName="Wacky Widgets";
this.CompanyName = companyName;
}
public String toString()
{
// int i =0;
String str =CompanyName+ "";
//String str = "";
for (int i=0; i<list.size();i++)
{
str +=" "+list.get(i).getFName()+" "+list.get(i).getLName()+" "+"Position:"+list.get(i).getPosition()+" ";
}
return str;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.