Question: I need help with this particular Java project. I am almost done with it. I just need to fix two things. Every time I add

I need help with this particular Java project. I am almost done with it. I just need to fix two things. Every time I add an employee the currency format doesn't come out correctly. I need help with this particular Java project. I am almost done

The results should be looking like this.

with it. I just need to fix two things. Every time I

Also, this project is suppose to allow the user to remove an employee but for some reason the program does not allow me to. The results should look like the image below.

add an employee the currency format doesn't come out correctly. The results

If anyone can help me I would really appreciate it!! thank you. I have posted my code down below for you guys to see.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Company.Java

// imports

import java.util.ArrayList;

import java.text.NumberFormat;

import java.io.*;

import java.util.*;

public class Company implements CompanyInterface {

// Fields

private String companyName;

private ArrayList employees;

private static int numberOfCompanies = 0;

private int numDesign;

private int numEmployees;

private int numManufacturing;

private int numSales;

private int numManager;

private NumberFormat fmt;

public Company(String arg)

{

// Instantiate fields

this.companyName = arg;

this.employees = new ArrayList();

this.numSales = 0;

this. numEmployees = 0;

this.numDesign = 0;

this.numManufacturing = 0;

this. numManager = 0;

updateCompanyNumber();

this.fmt = NumberFormat.getCurrencyInstance(Locale.US);

}

public String addEmployee(String fname, String lname, String pos,double firstParam, int secondParam, int empNum)

{

if(numSales == 1 && pos.equals("Sales")){

return "There is already a sales person Employee not added";

}

else if(numDesign == 2 && pos == "Design")

return "There are already two design persons Employee not added";

else if(numManufacturing == 4 && pos.equals("Manufacturing"))

return "There are already four manufacturing persons Employee not added";

else if (numManager == 1 && pos.equals("Manager"))

return "There is already a manager Employee not added";

else if(this.getNumEmployees()== 8)

return "There are already 8 employees Employee not added";

else if(pos.equals("Sales") == false && pos.equals("Design") == false && pos.equals("Manufacturing") == false && pos.equals("Manager") == false)

return "That position does not exist";

else{

if(pos.equals("Sales")){

Sales s = new Sales(fname, lname, empNum, firstParam);

employees.add(s);

numSales++;

}

else if (pos.equals("Design")){

Design d = new Design(fname, lname, empNum, firstParam, secondParam);

employees.add(d);

numDesign++;

}

else if(pos.equals("Manufacturing")){

Manufacturing m = new Manufacturing(fname, lname, secondParam, firstParam, empNum);

employees.add(m);

numManufacturing++;

}

else{

Manager m = new Manager(fname, lname, empNum, firstParam);

employees.add(m);

numManager++;

}

return null;

}

}

public static int getNumCompanies()

{

return numberOfCompanies;

}

private static void updateCompanyNumber()

{

numberOfCompanies += 1;

}

public static void resetCompanyCount()

{

numberOfCompanies = 0;

}

public int getNumEmployees()

{

return numEmployees;

}

public String printCompany()

{

String a = companyName;

a = this.companyName + " ";

for(Employee e: employees){

a += e.getfName() + " " + e.getlName() + " Position: " + e.getPos() + " ";

}

return a;

}

public String generateWeeklyReport() {

String s = "WEEKLY PAY REPORT FOR " + companyName + " COMPANY EMPLOYEE WEEKLY PAY " +

toString() + " Total payroll: " + fmt.format(calculateTotalWeeklyPay()) +

" Total number of managers paid: " + String.valueOf(numManager) +

" Total number of Design employees paid: " + String.valueOf(numDesign) +

" Total number of Sales employees paid: " + String.valueOf(numSales) +

" Total number of Manufacturing employees paid: "

+ String.valueOf(numManufacturing) ;

return s;

}

public double calculateTotalWeeklyPay() {

double total = 0;

for(Employee e: employees){

total += e.calculateWeeklyPay();

fmt.format(total);

}

return total;

}

public int getNumManager() {

return numManager;

}

public int getNumDesign() {

return numDesign;

}

public int getNumSales() {

return numSales;

}

public int getNumManufacturing() {

return numManufacturing;

}

@Override

public boolean removeEmployee(String firstName, String lastName) {

Employee d = null;

if(firstName == d.getfName() && lastName == d.getlName()){

employees.remove(firstName);

employees.remove(lastName);

return true;

}

else

return false;

}

@Override

public String toString()

{

String s = "";

for(Employee e : employees){

s += e.toString() + " ";

}

return s;

}

}

CompanyInterface.Java

public interface CompanyInterface {

/**

* Add an employee to the ArrayList.

* @param type Type of employee: Manager, Design, Sales, Manufacturing

* @param fname First Name

* @param lname Last Name

* @param firstParam Manager-salary, Design-hourly rate, Sales-weekly sales, Manufacturing-rate per piece

* @param secondParam Manager-not needed (0), Design-number of hours, Sales-not needed (0), Manufacturing-number of pieces

* @param empNum employee number

* @return null if successful add. Returns a string that describes the reason

* for not adding the employee. It will be one of the following:

*

1. There is already a sales person Employee not added

*

2. There are already two design persons Employee not added

*

3. There are already four manufacturing persons Employee not added

*

4. There is already a manager Employee not added

*

5. There are already 8 employees Employee not added

*/

public String addEmployee(String fname, String lname, String type, double firstParam, int secondParam, int empNum);

/**

* Remove a specified employee from the ArrayList.

* @param firstName First name of the employee to remove from the payroll

* @param lastName Last name of the employee to remove from the payroll

* @return true if the employee was successfully removed, false otherwise

*/

public boolean removeEmployee(String firstName, String lastName);

/**

* Returns the number of Managers in the ArrayList

* @return number of Managers

*/

public int getNumManager();

/**

* Returns the number of Hourly Workers in the ArrayList

* @return number of Hourly Workers

*/

public int getNumDesign();

/**

* Returns the number of Commission Worker in the ArrayList

* @return number of Commission Worker

*/

public int getNumSales();

/**

* Returns the number of Piece Worker in the ArrayList

* @return number of Piece Worker

*/

public int getNumManufacturing();

/**

* Generates a weekly report of employee weekly pay

* @return String that contains the Weekly Report

*/

public String generateWeeklyReport();

/**

* Calculate the total weekly pay for all employees in the ArrayList

* @return the total weekly pay for all employees

*/

public double calculateTotalWeeklyPay();

/**

* Creates a string with the name of the company followed by the first and last name

* and position of each of the employees

* @return string

* Example:

*

PigeonHawks

*

John Smith Position: Manufacturing

*

Bob Jones Position: Sales

*/

public String printCompany();

/**

* Creates a string representation of the object

* @return String that represents all the objects in the ArrayList

*/

public String toString();

}

FXMainPane.Java

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Scanner;

import javax.swing.JOptionPane;

import javafx.event.ActionEvent;

import javafx.event.EventHandler;

import javafx.geometry.Pos;

import javafx.scene.control.Button;

import javafx.scene.control.RadioButton;

import javafx.scene.control.ToggleGroup;

import javafx.scene.control.Label;

import javafx.scene.control.TextField;

import javafx.scene.image.Image;

import javafx.scene.image.ImageView;

import javafx.scene.layout.BorderPane;

import javafx.scene.layout.FlowPane;

import javafx.scene.layout.HBox;

import javafx.scene.layout.VBox;

import javafx.stage.FileChooser;

import javafx.geometry.Insets;

public class FXMainPane extends BorderPane {

private static final long serialVersionUID = 1L;

private HBox positionButtonGroupPanel,headerPanel,employeeInfoPanel,addEmployeeButtonPanel;

private VBox addEmployeePanel, employeeLabelPanel, employeeTextPanel;

private FlowPane employeeMgmtButtonPanel;

private TextField firstNameField;

private TextField lastNameField, idField, firstField, secondField;

private Label headerLabel, idLabel, firstLabel, secondLabel;

private Label firstNameLabel, lastNameLabel, blankLabel1, blankLabel2;

private RadioButton manufacturingButton, designButton, salesButton, managerButton;

private Button addEmployeeButton, printPayButton, readFileButton, Exit, clearButton, printCompanyButton;

private Company company;

private ImageView icon;

public FXMainPane(){

this.setMaxSize(400,550); //setPreferredSize(new Dimension(400,550));

company = new Company("Wacky Widgets");

firstNameLabel = new Label("First Name:");

idLabel = new Label("Employee ID:");

firstLabel = new Label("Weekly Sales:");

secondLabel = new Label("");

secondLabel.setVisible(false);

lastNameLabel = new Label("Last Name:");

icon = new ImageView("file:src/company.png");

headerLabel = new Label("Wacky Widgets");

headerLabel.setStyle("-fx-font-size: 20");

headerLabel.setPadding(new Insets(0,0,20,0));

blankLabel1 = new Label(" ");

blankLabel2 = new Label(" ");

firstNameField = new TextField();

lastNameField = new TextField();

idField = new TextField();

firstField = new TextField();

secondField = new TextField();

secondField.setVisible(false);

//radio buttons

salesButton = new RadioButton("Sales");

salesButton.setOnAction(new RadioButtonHandler());

manufacturingButton = new RadioButton("Manufacturing");

manufacturingButton.setOnAction(new RadioButtonHandler());

designButton = new RadioButton("Design");

designButton.setOnAction(new RadioButtonHandler());

managerButton = new RadioButton("Manager");

managerButton.setOnAction(new RadioButtonHandler());

ToggleGroup positionButtonGroup = new ToggleGroup();

designButton.setToggleGroup(positionButtonGroup);

salesButton.setToggleGroup(positionButtonGroup);

manufacturingButton.setToggleGroup(positionButtonGroup);

managerButton.setToggleGroup(positionButtonGroup);

//add-employee buttons

addEmployeeButton = new Button("Add Employee");

clearButton = new Button("Clear");

addEmployeeButton.setOnAction(new ButtonHandler());

clearButton.setOnAction(new ButtonHandler());

//employee mgmt buttons

printPayButton = new Button("Print Weekly Pay Report");

readFileButton = new Button("Read File");

printCompanyButton = new Button("Print Company Employees");

Exit = new Button("Exit");

printPayButton.setOnAction(new ButtonHandler());

readFileButton.setOnAction(new ButtonHandler());

Exit.setOnAction(new ButtonHandler());

printCompanyButton.setOnAction(new ButtonHandler());

//company title panel

headerPanel = new HBox();

headerPanel.getChildren().addAll(icon, headerLabel);

headerPanel.setAlignment(Pos.CENTER);

Insets insets=new Insets(40,10,20,10);

HBox.setMargin(headerLabel, insets);

headerPanel.setPrefHeight(10);

setTop(headerPanel);

BorderPane.setAlignment(headerPanel, Pos.CENTER);

//radio button panel

positionButtonGroupPanel = new HBox();

positionButtonGroupPanel.getChildren().addAll(managerButton,designButton,manufacturingButton,salesButton);

positionButtonGroupPanel.setAlignment(Pos.CENTER);

insets=new Insets(10,10,20,10);

HBox.setMargin(managerButton, insets);

HBox.setMargin(designButton, insets);

HBox.setMargin(manufacturingButton, insets);

HBox.setMargin(salesButton, insets);

//employee info labels

employeeLabelPanel = new VBox();

employeeLabelPanel.getChildren().addAll(idLabel,firstNameLabel,lastNameLabel,firstLabel,secondLabel);

employeeLabelPanel.setAlignment(Pos.CENTER);

insets=new Insets(8,10,10,10);

VBox.setMargin(idLabel, insets);

VBox.setMargin(firstNameLabel, insets);

VBox.setMargin(lastNameLabel, insets);

VBox.setMargin(firstLabel, insets);

VBox.setMargin(secondLabel, insets);

//employee info text panels

employeeTextPanel = new VBox();

employeeTextPanel.getChildren().addAll(idField,firstNameField,lastNameField,firstField,secondField);

employeeTextPanel.setAlignment(Pos.CENTER);

insets=new Insets(5,10,5,10);

VBox.setMargin(idField, insets);

VBox.setMargin(firstNameField, insets);

VBox.setMargin(lastNameField, insets);

VBox.setMargin(firstField, insets);

VBox.setMargin(secondField, insets);

//employee info panel

employeeInfoPanel = new HBox();

employeeInfoPanel.getChildren().addAll(employeeLabelPanel,employeeTextPanel);

employeeInfoPanel.setAlignment(Pos.CENTER);

//add employee buttons

addEmployeeButtonPanel = new HBox();

addEmployeeButtonPanel.getChildren().addAll(addEmployeeButton,clearButton);

addEmployeeButtonPanel.setAlignment(Pos.CENTER);

insets=new Insets(10,10,10,10);

HBox.setMargin(addEmployeeButton, insets);

HBox.setMargin(clearButton, insets);

//employ info

addEmployeePanel = new VBox();

addEmployeePanel.getChildren().addAll(positionButtonGroupPanel,employeeInfoPanel,addEmployeeButtonPanel);

addEmployeePanel.setAlignment(Pos.TOP_CENTER);

addEmployeePanel.setStyle("-fx-border-color: black");

setCenter(addEmployeePanel);

employeeMgmtButtonPanel = new FlowPane();

employeeMgmtButtonPanel.getChildren().addAll(readFileButton, printCompanyButton, printPayButton, Exit);

employeeMgmtButtonPanel.setAlignment(Pos.CENTER);

insets=new Insets(5,5,5,5);

FlowPane.setMargin(readFileButton, insets);

FlowPane.setMargin(printCompanyButton, insets);

FlowPane.setMargin(printPayButton, insets);

FlowPane.setMargin(Exit, insets);

setBottom(employeeMgmtButtonPanel);

BorderPane.setMargin(employeeMgmtButtonPanel, insets);

setRight(blankLabel1);

setLeft(blankLabel2);

}

public void readFile() throws FileNotFoundException{

// TODO Auto-generated method stub

FileChooser chooser = new FileChooser();

Scanner input;

String[] fields;

String fname, lname, type, line;

double salary, wage, payRate, grossSales, piecePrice;

int empNum, hours, numPieces;

int paycode;

File selectedFile = chooser.showOpenDialog(null);

if (selectedFile!=null)

{

input = new Scanner(selectedFile);

while(input.hasNextLine())

{

line = input.nextLine();

fields = line.split(":");

fname = fields[0];

lname = fields[1];

type = fields[2];

switch(type)

{

case "Manager": salary = Double.parseDouble(fields[3]);

empNum = Integer.parseInt(fields[4]);

company.addEmployee(fname, lname, "Manager", salary, 0, empNum);

break;

case "Design": payRate = Double.parseDouble(fields[3]);

hours = Integer.parseInt(fields[4]);

empNum = Integer.parseInt(fields[5]);

company.addEmployee(fname, lname, "Design", payRate, hours, empNum);

break;

case "Sales": grossSales = Double.parseDouble(fields[3]);

empNum = Integer.parseInt(fields[4]);

company.addEmployee(fname, lname, "Sales", grossSales, 0, empNum);

break;

case "Manufacturing": piecePrice = Double.parseDouble(fields[3]);

numPieces = Integer.parseInt(fields[4]);

empNum = Integer.parseInt(fields[5]);

company.addEmployee(fname, lname, "Manufacturing", piecePrice, numPieces, empNum);

break;

}

}

}

}

private class RadioButtonHandler implements EventHandler {

@Override

public void handle(ActionEvent event) {

//public void actionPerformed(ActionEvent event) {

if(event.getSource() == designButton)

{

firstLabel.setText("Payrate:");

secondLabel.setText("Hours:");

secondLabel.setVisible(true);

secondField.setVisible(true);

}

else if(event.getSource() == salesButton)

{

firstLabel.setText("Weekly Sales:");

secondLabel.setVisible(false);

secondField.setVisible(false);

}

else if(event.getSource() == managerButton)

{

firstLabel.setText("Salary:");

secondLabel.setVisible(false);

secondField.setVisible(false);

}

else if(event.getSource() == manufacturingButton)

{

firstLabel.setText("Piece rate:");

secondLabel.setText("# pieces:");

secondLabel.setVisible(true);

secondField.setVisible(true);

}

}

}

private class ButtonHandler implements EventHandler {

@Override

public void handle(ActionEvent event) {

Object selectedButton = event.getSource();

if (selectedButton==addEmployeeButton) {

String position="";

int second=0, id = 0;

double first=0;

String firstName = firstNameField.getText();

String lastName = lastNameField.getText();

id = Integer.parseInt(idField.getText());

if (salesButton.isSelected())

{

position = "Sales";

first = Double.parseDouble(firstField.getText());

second = -1;

}

else if (designButton.isSelected())

{

position = "Design";

first = Double.parseDouble(firstField.getText());

second = Integer.parseInt(secondField.getText());

}

else if (manufacturingButton.isSelected())

{

position = "Manufacturing";

first = Double.parseDouble(firstField.getText());

second = Integer.parseInt(secondField.getText());

}

else if (managerButton.isSelected())

{

position = "Manager";

first = Double.parseDouble(firstField.getText());

second = -1;

}

String result = company.addEmployee(firstName, lastName, position,first, second,id);

if (result != null)

JOptionPane.showMessageDialog(null, result,"Employee not added",JOptionPane.PLAIN_MESSAGE);

}

else if (selectedButton==printPayButton)

{

JOptionPane.showMessageDialog(null, company.generateWeeklyReport(),"Weekly Pay Report",JOptionPane.PLAIN_MESSAGE);

}

else if (selectedButton==clearButton)

{

idField.setText("");

firstNameField.setText("");

lastNameField.setText("");

}

else if (selectedButton==readFileButton)

{

try {

readFile();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

else if (selectedButton==printCompanyButton)

{

JOptionPane.showMessageDialog(null, company.printCompany(),"Employees",JOptionPane.PLAIN_MESSAGE);

}

else if (selectedButton==Exit)

{

System.exit(0);

}

}

}

}

FXPaycheckDriver.Java

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.image.Image;

import javafx.stage.Stage;

public class FXPaycheckDriver extends Application

{

public FXPaycheckDriver() {

}

public static void main (String[] args)

{

launch(args);

}

@Override

public void start(Stage stage) throws Exception {

FXMainPane root = new FXMainPane();

stage.setScene(new Scene(root, 400, 450));

// Set stage title and show the stage.

stage.setTitle("Employee Management");

stage.show();

}

}

Employee.Java

public abstract class Employee

{

private String fName;

private String lName;

private int empNum;

private Position p;

public Employee() {

this.fName = "";

this.lName = "";

this.empNum = -1;

this.p = null;

}

public Employee(String fName, String lName, int empNum, Position p)

{

this.fName = fName;

this.lName = lName;

this.empNum = empNum;

this.p = p;

}

public void setPos(Position pos) {

this.p = pos;

}

public Position getPos() {

return p;

}

public String getfName() {

return fName;

}

public void setfName(String fName) {

this.fName = fName;

}

public void setEmpNum(int empNum) {

this.empNum = empNum;

}

public String getlName() {

return lName;

}

public void setlName(String lName) {

this.lName = lName;

}

public int getEmpNum() {

return empNum;

}

public abstract double calculateWeeklyPay();

public String toString() {

if(String.valueOf(calculateWeeklyPay()) != null){

return String.valueOf(empNum) + " $" + calculateWeeklyPay()+"0";

}

return null;

}

}

Manager.Java

public class Manager extends Employee { private final static Position p = Position.MANAGER; private double salary; public Manager() { super(); salary = 0; } public Manager(String fName, String lName, int empNum, double salary) { super(fName, lName, empNum, p); this.salary = salary; } public double calculateWeeklyPay() {

return salary; } public double getSalary() { return salary; } public void setSalary(double salary) { this.salary = salary; }

public boolean inputValidation() { if(salary

Manufacturing.Java

public class Manufacturing extends Employee { // Fields private final static Position p = Position.MANUFACTURING; private double pieceAmount; private double pricePerPiece; public Manufacturing() { super(); setPieceAmount(0); setPricePerPiece(0); } public Manufacturing(String fName, String lName, double pieceAmount, double pricePerPiece, int empNum) { // call super super(fName, lName, empNum, p); setPieceAmount(pieceAmount); setPricePerPiece(pricePerPiece);

} public double calculateWeeklyPay() { return getPieceAmount() * getPricePerPiece(); } public double getPieceAmount() { return pieceAmount; } public void setPieceAmount(double pieceAmount) { this.pieceAmount = pieceAmount; } public double getPricePerPiece() { return pricePerPiece; } public void setPricePerPiece(double pricePerPiece) { this.pricePerPiece = pricePerPiece; } public boolean inputValidation() { if(pieceAmount

Position.Java

public enum Position {

MANAGER ("Manager"),

SALES ("Sales"),

DESIGN ("Design"),

MANUFACTURING ("Manufacturing");

private String name;

/**

* Creates a new Position

*

* @param name The name of the office

*/

Position(String name) {

this.name = name;

}

public String toString() {

return name;

}

}

Sales.Java

public class Sales extends Employee{

// Fields

private final static int bonus = 250;

private final static Position p = Position.SALES;

private double weeklySales;

public Sales()

{

super();

weeklySales = 0;

}

public Sales(String fName, String lName, int empNum, double weeklySales)

{

super(fName, lName, empNum, p);

this.weeklySales = weeklySales;

}

public double calculateWeeklyPay() {

return (weeklySales * .057) + bonus;

}

public void setWeeklySales(double weeklySales)

{

this.weeklySales = weeklySales;

}

public double getWeeklySales()

{

return weeklySales;

}

public boolean inputValidation()

{

if(weeklySales

return false;

else

return true;

}

}

Design.Java

public class Design extends Employee{ // Fields private final static Position p = Position.DESIGN; private double payRate; private double hours; public Design() { super(); payRate = 0; hours = 0; } public Design(String fName, String lName, int empNum, double payRate, double hours) { super(fName, lName, empNum, p); setPayRate(payRate); setHours(hours); } public double calculateWeeklyPay() { if(hours

}

Employee Management Wacky Widgets Manager Design Manufacturing Sales Weekly Pay Report WEEKLY PAY REPORT FOR Wacky Widgets COMPANY EMPLOYEE WEEKLY PAY $810.00 $1200.00 $820.00 $687.50 $2074.32500000000030 332 244 Total payroll: $5,591.83 Total number of managers paid: 1 Total number of Design employees paid: 2 Total number of Sales employees paid: 1 Total number of Manufacturing employees paid: 1 OK

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!