Question
Assignment 6 CMSC203 Spring 2018 Concepts tested by this program: Reading from a file ArrayList New concepts tested by this program Inheritance Interface Polymorphism Abstract
Assignment 6
CMSC203
Spring 2018
Concepts tested by this program:
Reading from a file
ArrayList<>
New concepts tested by this program
Inheritance
Interface
Polymorphism
Abstract classes
Overriding methods
super()
WEEKLY PAY REPORT FOR THE Wacky Widgets COMPANY
The Wacky Widgets Company has four types of employees: Managers (who receive a fixed weekly salary), Design workers (who receive a fixed hourly wage for up to the first 40 hours they work and "time-and-a-half," i.e., 1.5 times their hourly wage, for overtime hours worked), Sales workers (who receive a $250 plus 5.7% of their gross weekly sales), and Manufacturing (who receive a fixed amount of money per item for each of the items they produce -- each manufacturer in this company works on only one type of item).
Write a Java program to compute the weekly pay for each employee and the total payroll. You do not know the number of employees in advance. The first item in the report will be the first name, the second item in the line will be the last name, the third item will always be the employee type (Manager, Design, Manufacturing, Sales). For a Manager, the salary will be the fourth item. If the type is Design, hourly salary is the fourth item and hours worked is the fifth item. If the type is Sales, the fourth item will be the gross weekly sales. If the type is Manufacturing, the fourth item will be the price per piece and the fifth item will be the number of pieces. The last item on the line will be the worker's ID number.
An employee can also be added through the GUI.
A Summary Pay Report is displayed on the screen in a JOptionPane window. Each employee number and weekly wage is printed before the summary items. The summary should consist of the total payroll and the number of employees in each category. Use the FileChooser dialog box to select the input file name at run time. Print all dollar amounts with currency formatting. You can assume all information in the input file is correct.
Allow the user the read in an employee text file (provided), add an employee in the GUI, or remove an employee.
Specifications
Data Element - Employee
{C} Create an abstract class called Employee with one abstract method called calculateWeeklyPay which returns a double. This class will have an instance variables (one of them is an object of type Position, from Assignment 5), a toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor.
Data Element subclasses of Employee
{C} Create the following classes for the 4 types of employees: Manager, Design, Sales, and Manufacturing. They will contain instance variables appropriate for the type of employee. They will extend from Employee and define the calculateWeeklyPay method. There should be getters and setters, and any other methods that are needed for your design. The toString method and constructors for these classes will use the super reference to take advantage of the Employee constructor and toString methods. Use finals to represent constants.
Enumerated Type Position
{C} Create an enumerated type called Position. The valid values will be MANAGER, SALES, DESIGN, MANUFACTURING. Add any additional methods or instance variables as required by your design.
Data Structure
{C} You will be using an Arraylist within your Data Manager to hold the employee objects.
Data Manager - Company
{C} Create a Company class that implements the CompanyInterface. It will contain an arraylist which holds references to Employee objects (Manager, Design, Sales, Manufacturing all inherit from Employee). It will have methods to addEmployee, removeEmployee, printEmployees, calculateTotalWeeklyPay, retrieve number of Design employees, Sales employees, etc., and any other methods needed for your design. Your toString method will print out the employee number and weekly pay for all employees. There is a generateWeeklyPayReport method that returns a string with the entire report.
GUI Driver
{C} Create a GUI Driver class/classes. The preferred submission will be using JavaFX, although Swing submissions are also acceptable. The GUI will be able to read from a file, add or remove an employee, print a summary of employees, or print a pay report by employee. Use the FileChooser dialog box to select the input file name at run time. The number of fields in the file for one employee will change depending on the type of employee that is selected. The fields in the file are separated by colons (:). You can assume all information in the file is correct. The GUI will use an instance of the Company class.
{C} The user will have the ability to add additional employees through the keyboard. The labels and textfields will change depending on the type of employee that is selected to be added.
{C} The user will have the ability to remove an employee. If there are not employees yet added, use a JOptionPane to tell the user to add employees first. If the user does not type the first and last name of the employee to be removed, use a JOptionPane to display the current employees and tell the user to type in a name.
{C} Display a report of all employees, and a weekly pay report for all the employees
{C} Note: your GUI need not display an icon.
External Documentation
{C} Provide a UML diagram with all classes and their relationships.
{C} Create Javadoc for all classes that you have created. Upload your entire doc folder.
Testing
{C} Ensure that the JUnit tests in CompanyTest.java succeed.
{C} Implement the STUDENT test methods in CompanyTest.java.
{C} Include CompanyTest.java with the rest of your submission.
Labels and TextFields change depending on type of employee:
Input file for test case: Print Company Employees:
Display summary pay report: Add a Design Employee:
Resulting Pay Report: Remove Employee if no name has been entered:
Remove an employee (correctly): Result:
Deliverables / Submissions:
Week 1: Design a UML class diagram.
Week 2: Submit two compressed files containing the follow (see below):
Deliverable format: The deliverables will be packaged as follows. Two compressed files in the following formats:
LastNameFirstName_Assignment6.zip (a compressed file containing the following)
{C}o Javadoc (a directory) a compressed file of the Javadoc doc directory
{C}o Source Code (a directory) contains your .java files from the src directory
{C} File1.java (example)
{C} File2.java (example)
{C} File_Test.java (example)
LastNameFirstName_Assignment6_Moss.zip (a compressed file containing only .java files)
NO FOLDERS!!
File1.java (example)
File2.java (example)
Given
/////////////////////////////
employees.txt
John:Smith:Manufacturing:6.75:120:444
Betty:White:Manager:1200.00:111
Stan:Slimy:Sales:10000.00:332
Betty:Boop:Design:12.50:50:244
/////////////////////////////////////////////////////////
FXMainPane
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;
/**
* GUI for the Weekly Pay application. Based on a Swing version created
* by Prof Jeannette Kartchner
* @author ralexander
*
*/
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
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
/**
* Driver for the Weekly Pay GUI in FX
* @author ralexander
*
*/
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();
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Interface for the Company class for CMSC203, Assignment 6, Fall 2016
* Contains an ArrayList of objects that inherit from the Abstract class Employee
* Keeps track of the number of Mangers, Designers, Sales
* and Manufacturing employees
* Manages company employees
* Create a static variable to keep track of the number
* of company instances created
* @author Professor Myers changed by Prof. Justh
*
*/
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();
}
///////////////////////////////////////////////////////////////////////////////////////////////
CompanyTest
import static org.junit.Assert.*;
import java.util.Scanner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class CompanyTest {
Company company;
@Before
public void setUp() throws Exception {
company = new Company("Wacky Widgets");
company.addEmployee("John","Smith", "Manufacturing", 6.75, 120, 444); //Manufacturing
company.addEmployee("Betty","White","Manager",1200.00, 0, 111); //Manager
company.addEmployee("Stan","Slimey","Sales",10000.00, 0, 332); //Sales
company.addEmployee("Betty","Boop","Design",12.50, 50, 244); //Hourly worker
//STUDENT: Create another company object. Add several employees. Use this object in the
// Student test methods.
}
@After
public void tearDown() throws Exception {
company = null;
}
@Test
public void testAddEmployee() {
String result = company.generateWeeklyReport();
Scanner report = new Scanner(result);
report.nextLine(); //WEEKLY PAY REPORT FOR WIDGET COMPANY
report.nextLine(); //empty line
report.nextLine(); //EMPLOYEE WEEKLY PAY
report.nextLine(); //employee 444
report.nextLine(); //employee 111
report.nextLine(); //employee 332
assertEquals("244",report.next()); //employee 244
company.addEmployee("Charles","Emory","Design", 7.50, 35, 343); //Design employee
result = company.generateWeeklyReport();
report = new Scanner(result);
report.nextLine(); //WEEKLY PAY REPORT FOR Wacky Widget COMPANY
report.nextLine(); //empty line
report.nextLine(); //EMPLOYEE WEEKLY PAY
report.nextLine(); //employee 444
report.nextLine(); //employee 111
report.nextLine(); //employee 332
report.nextLine(); //employee 244
assertEquals("343",report.next()); //employee 343
assertEquals(2,company.getNumDesign());
}
@Test
public void testAddEmployeeSTUDENT() {
fail("Not yet implemted");
}
@Test
public void testCalculateTotalWeeklyPay() {
assertEquals(3517.50, company.calculateTotalWeeklyPay(), .001);
company.addEmployee("Charles","Emory","Design", 7.50, 35, 343); //Design employee
assertEquals(3780.00, company.calculateTotalWeeklyPay(), .001);
}
@Test
public void testCalculateTotalWeeklyPaySTUDENT()
{
fail("Not yet implemented");
}
@Test
public void testGetNumManager() {
assertEquals(1, company.getNumManager());
}
@Test
public void testGetNumDesign() {
assertEquals(1, company.getNumDesign());
}
@Test
public void testGetNumManufacturing() {
assertEquals(1, company.getNumManufacturing());
}
@Test
public void testGetNumSales() {
assertEquals(1, company.getNumSales());
}
@Test
public void testGenerateWeeklyReport() {
String result = company.generateWeeklyReport();
Scanner report = new Scanner(result);
report.nextLine(); //WEEKLY PAY REPORT FOR Wacky Widget COMPANY
report.nextLine(); //empty line
report.nextLine(); //EMPLOYEE WEEKLY PAY
assertEquals("444",report.next()); //444
assertEquals("$810.00",report.next()); //$1,200.00
report.nextLine();//extracts newline at end of line
assertEquals("111",report.next()); //22222
}
@Test
public void testGenerateWeeklyReportSTUDENT() {
fail("Not yet implemented");
}
@Test
/**
* Test to
* 1. add 3 new Employees as a manufacturing person
* check if recognizes there are already 4 manufacturing persons
* 2. add a new employee as a sales person
* check if recognizes there is already a a sales person
* 3. add 2 new employee as a design person
* check if recognizes there is already 2 design persons
*/
public void testAddEmployeeForErrors() {
String result;
//add another designer - No problem, should return null
result = company.addEmployee("Bobby", "Match", "Design",200,35,333);
assertEquals(null, result);
//add another designer - already 2 designers - return error message
result = company.addEmployee("Albert","Pine", "Design",200,35,777);
assertEquals("There are already two design persons Employee not added", result);
//add another sales person - already 1 sales person - return error message
result = company.addEmployee("Susie", "Smith", "Sales",4000,0,888);
assertEquals("There is already a sales person Employee not added", result);
//add another manufacturer - No problem, should return null
result = company.addEmployee("Benedict", "Cumberbatch", "Manufacturing",.35,2500,999);
assertEquals(null, result);
//add another manufacturer - No problem, should return null
result = company.addEmployee("Martin", "Freeman", "Manufacturing",.37,1500,543);
assertEquals(null, result);
//add another manufacturer - No problem, should return null
result = company.addEmployee("Fred", "Flintstone", "Manufacturing",.37,1500,389);
assertEquals(null, result);
//add another manufacturer - already 4 manufacturers - return error message
result = company.addEmployee("Andrew", "Scott", "Manufacturing",.52,1000,765);
assertEquals("There are already four manufacturing persons Employee not added", result);
}
@Test
/**
* Test to:
* 1. Check if the company name is on the first line
* 2. Check if John is on the second line
* 3. Check if Betty is on the third line
* 4. Check if Stan is on the fourth line
* 5. Check if Betty is on the fifth line
*/
public void testPrintCompany() {
String result = company.printCompany();
Scanner company = new Scanner(result);
assertEquals("Wacky Widgets",company.nextLine());
//extract three Employees
assertEquals("John", company.next());
company.nextLine(); //Smith Position manufacturing (rest of line)
assertEquals("Betty", company.next());
company.nextLine(); //White Position manager (rest of line)
assertEquals("Stan",company.next());
company.nextLine(); //Slimey Position Sales (rest of line);
assertEquals("Betty",company.next());
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started